Commit Graph

247 Commits

Author SHA1 Message Date
Robert Nystrom 2f2bdc3c22 Reformat tests/lib/js and /js_interop_unsafe using 3.8 style.
Change-Id: I182e28a3c4b44dd899e5ea30ac5c5c3ba60fd6cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425333
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2025-04-29 21:21:29 -07:00
Stephen Adams 2cc7d381a5 [rti/js_interop] Accelerate is JSObject
Change-Id: I36501521db9922068f8e5246e9edb0e63b561d0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422200
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-04-26 21:57:20 -07:00
Nicholas Shahan 183f8b2f51 [tests] Fix typing information in package:js tests
Makes this test consistent with the others in the "family"
which all use `String` as the return type.

Change-Id: Id50de839094f766f29170d4b42e922635e12683a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423561
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-04-21 17:25:11 -07:00
Srujan Gaddam af7f6393e6 Change void_return_test to not use eval
eval is disallowed by CSP and the dart2js-minified-csp-linux-chrome
bot is currently red. This uses Math.max, which should be available
both on d8 and with CSP enabled.

Change-Id: I5e348a72d50cf10db713934151473f0d15782ba3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421502
Commit-Queue: Ömer Ağacan <omersa@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-04-09 01:29:40 -07:00
Ömer Ağacan b372b54ecb Reland "[dart2wasm] Don't dartify JS values when returning as void"
This is a reland of commit 4bb05dc562

Initial commit didn't properly box the `void` return value, so when we
cast the return value to `ref #Top` to pass it to a Dart function (as
`Object?` or `dynamic`) it caused "illegal cast" traps.

In this commit we properly box the `externref` as `JSValue` (a proper
Dart class). A new test added passing the return value of a `void` JS
return to `print`.

Original change's description:
> [dart2wasm] Don't dartify JS values when returning as void
>
> When calling a JS function that returns `void`, avoid dartifying the
> result.
>
> Technically the return value of `void` functions can still be used, by
> casting the return type to `Object?` or `dynamic`. However this
> shouldn't be done, and `dartifyRaw` overhead just to support this case
> which should be extremely rare is too much.
>
> Any hacky code that uses return values of `void`-returning JS interop
> functions can manually dartify the retrun values with `toDart` or
> similar.
>
> Issue: https://github.com/dart-lang/sdk/issues/60357
> Change-Id: Ic370c7cf6eb6982f61f8a07c91e3bb93c5345ac6
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417240
> Reviewed-by: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Ömer Ağacan <omersa@google.com>

Change-Id: I264211cca4f6b87e63d68909647975ab96f0b5bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421080
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-04-08 09:29:33 -07:00
Martin Kustermann 20fc102287 [dart2wasm] Switch to only using JS strings
Currently we have 3 different string types (JS Strings, OneByteString
and TwoByteString)s. There's some advantages to this, mainly that
if strings are used purely inside Dart we have more control over
optimizing them. But it does come with some issues

* Operations on mixture of strings are slow
* We get JS strings from outside (in DevTools e.g. websocket messages)
* Any kind of DOM interaction requires copying strings
* Regular expression matches can result in O(N*N) instead of O(N)
* Encoding of string literals/constants is terrible, high size overhead
* ...

Now that there's a standardized way to access JS strings (via
the `js-string` builtin spec) and this standard is finalized and
enabled in Chrome & Firefox it makes sense for us to switch to it.

It reduces app size:

* Smaller size: hello world -25%, flute -5.5%
* Faster startup

The performance changes are nuanced, some workloads will improve
significantly, some workloads will regress.

Improvements will come especially in cases where
strings are concatenated (due to JS not actually allocating new
strings in this case). That impacts e.g. string interpolations,
string buffer, json-to-string encoding, ...

Regressions will come especially for cases where we have to
construct strings from bytes (e.g. in utf8 decoder, utf8+json
decoder) - mainly due to having to go through an intermediary
`WasmArray<WasmI16>` to allocate strings. Also in cases where we
access individual char codes from the strings.

There's some follow-up improvements we can do, but it's better to
not iterate on this CL even longer but get it landed.

This CL will make the benchmarking system use
`--require-js-string-builtin` as well as most of test CI
(in `pkg/dart2wasm/tool/compile_benchmark`)

Though we run some configurations via overriding with
`--no-require-js-string-builtin`
(in `tools/bots/test_matrix.json`)

Issue https://github.com/flutter/flutter/issues/159400#issuecomment-2538593980
Issue https://github.com/dart-lang/sdk/issues/59699

TEST=ci

Change-Id: I238ac65efe092de569da870f23134f889ac929f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392903
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-02-27 00:33:34 -08:00
Lasse R.H. Nielsen 0dfbab89cb Make tests/lib/js/static_interop not use minitest.
Change-Id: Id7a8a6ac0098df55b04fa089587c62b07e9cf3c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403860
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-02-04 01:44:02 -08:00
Mohamed Abdelaal 9b7bb9df90 Fix "the the" typo
Closes https://github.com/dart-lang/sdk/pull/59926

GitOrigin-RevId: cb37bca473b0c177b876a0f4e75858cd1862e699
Change-Id: I6827241b22e99db455945afcdfbaee0450999ce9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404923
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-01-21 14:08:20 -08:00
Robert Nystrom 246050a1ef Opt multitests out of formatting in corelib/ and lib/.
The new formatter supports opting a region of code out from being
formatted. I'm applying this marker to all of the multitests since
those tests are often very sensitive to formatting and easily broken.
This way, anyone touching a multitest (including me when I reformat
the tests) doesn't have to remember to not run the formatter on it.

Change-Id: I34831719cd35e669b49e02a0d00c32b44068a34e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396103
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2024-11-19 11:14:40 +00:00
Devon Carew 3488fd58e9 [package:js] remove a test related to package:mockito
Change-Id: Ic060e250d5e6e481a37b23032da79d021496fec2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392465
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2024-10-29 20:50:55 +00:00
Srujan Gaddam e661776f80 [pkg:js] Add tests for allowInterop idempotency
Closes https://github.com/dart-lang/sdk/issues/56897

Adds a few missing tests to make sure we handle already
converted functions, Dart functions that were wrapped
by a previous call, and JS functions correctly in
allowInterop and allowInteropCaptureThis.

Change-Id: Iaa6f34652717787fad8141ad941c47e944e70a5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390400
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-10-16 18:18:23 +00:00
Lasse R.H. Nielsen f8086c81ae Collect all test-related files in package:expect.
Collects files from `package:async_helper` and `tests/language`
that are generally useful, so that all test-related helpers are
in `package:expect`.

Moves the two libraries from `package:async_helper` into `package:expect`,
and the `tests/language/static_type_helper.dart` file too.

Deprecates `async_minitest.dart`, to follow `minitest.dart`,
expecting the Flutter use of it to have been fixed to not break
on deprecation (I believe Flutter no longer breaks builds on deprecations at all).

Patch 1 is the actual change.
Patch 2+4+8 is changing all existing references to the files.
Patch 6 ignores deprecation in files still using `async_minitest.dart`.

3+5+7+9 are updating this text to make the numbers match.
Then it's just test-expectations and small tweaks from there.

Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-11 16:53:52 +00:00
Parker Lougheed c73677e606 [tests] Minor spelling and grammar fixes
Change-Id: I18c309b9037cf94a883443ac9067f911f829516c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388945
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-09 08:38:48 +00:00
Srujan Gaddam dc3b6af33d Add location rename to locationString in test
The SecurityError was being hidden because of
https://github.com/dart-lang/sdk/issues/56772.
With this, single-stepping through the test succeeds.

Change-Id: I47a768e803598d5f918a4d2bed9aa4391377464f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386401
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-23 22:38:57 +00:00
Srujan Gaddam 591b774213 Add tests for cross-origin window and location
Tests that we can use JSAny? as the type without
violating cross-origin policy. This will then be
used in package:web to implement a wrapper.

Change-Id: Ic30557138b61e27e421747ead81ea2fb7f6db240
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381886
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-12 21:30:00 +00:00
Lasse R.H. Nielsen 7e75d881a0 Tweak test_runner.
Clean up and optimize some RegExps, and fix uses of `.group`.
Switch to a newer language version, to be able to use newer features.
Add a little documentation about why some RegExps are as they are.

Add (tentative) warning for multitests.

Change-Id: I59f73b87ce30caaeca1c0e0aa7954af1b97abd1b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382620
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-09-10 15:29:28 +00:00
Rutvik Tak 1fb6869585 Adds a static from method on JSArray which helps a create a JSArray from a given JS iterable or array-like object. (Resolves #56069)
R=brianwilkerson@google.com, nshahan@google.com

Change-Id: I4b913107f5789f48af521b90052052d87453951d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382080
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Auto-Submit: Rutvik Tak <takrutvik@gmail.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-04 23:27:18 +00:00
Srujan Gaddam e9a72b80c1 [dart:js_interop] Clear up wording about isA requiring non-generic type argument
Closes https://github.com/dart-lang/sdk/issues/56564

CoreLibraryReviewExempt: Doc-only change.
Change-Id: I0086a0778d53d850c8d746e0474d22382d5e451c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381942
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-09-03 16:03:57 +00:00
Sigmund Cherem e8a049fd8e [dart2wasm] Make dart.library.js false in conditional imports (attempt 2)
This change removes the implementation of `dart:js` for dart2wasm. The
code is no longer in use and the compiler already provides a static
error if you import `dart:js` internally.

By removing the implementation from the libraries.json spec, we also
show this as unaccessible on conditional imports. This will allow
developers to distinguish JS and Wasm backends

This adapts the original implementation in
https://dart-review.googlesource.com/c/sdk/+/368642 with a few small
changes, but keeps around the existing allowances on `package:js`. Those
can be addressed separately to reduce the disruption from this change.

Closes #55266.

Change-Id: I0d01a424f2fdb4f48879bd1a41c847a92439e74a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380583
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
2024-08-16 16:22:50 +00:00
Nate Biggs 2f97501551 [js_interop] Fix JsInteropChecks not recursing into constructor's AST children.
The JS interop transformer assumes the entire AST has been checked and ends up trying to cast to FunctionType. If there is malformed, unvisited interop code this results opaque failure (failed type cast) rather than the useful error message from the check.

Bug: https://github.com/dart-lang/sdk/issues/56443
Change-Id: I5b911d0da7a839e3045dce61121496d464b79af9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380381
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2024-08-15 01:47:34 +00:00
Srujan Gaddam ac6588ba60 [dart2wasm] Optimize dartify type-checks
dartifyRaw type-checks are currently a bunch of if
cases where the check is done in JS. Instead of going
back and forth between runtimes, we can do the checks
in JS and return an enum value.

- Replaces the if cases with a externRefType method that
returns an integer that maps to some static const values.
Dart enums are slower so consts are preferred. Speeds up
type-checks by 4-5x and dartifyRaw by 1.1-1.8x for common
types using some quick local benchmarks. Also moves the
array check up as it's more common and groups the typed
array checks together.
- Reuses the externRefType helper in dartify so we don't
type-check the same value twice.
- Moves some tests from basic_test.dart to jsify_dartify_test.dart
and adds more type-checks, casts to assert types, cleans
up property getters, and adds a few missing cases.

Change-Id: Ia5fb9bfef6f9e212ea8da27362b0b4efb4cbf2fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/379144
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-08 16:12:17 +00:00
Srujan Gaddam be9dcae47e Add soundNullSafety checks in js_function_arity_test.dart for cases where we expect a failure when casting the this value to String
The this value can either be a JSObject or null. In JavaScript,
it's only ever null when strict mode is enabled. In DDC,
since strict mode is enabled, these parameter checks
then succeeded when we test unsound mode as null can be
successfully casted to String, and therefore the failure
expectation fails. Instead, we should only enable these tests
when sound null safety is enabled.

Change-Id: I70ab3de98fb81af5c71450d81590c0bf87a029e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378567
Reviewed-by: Nate Biggs <natebiggs@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-08-02 20:26:58 +00:00
Srujan Gaddam ae3dbcdfb1 [dart:js_interop] Add toJSCaptureThis
Closes https://github.com/dart-lang/sdk/issues/54381

- Adds an API to capture the this value so that users
can use it in the callback.
- Adds specialized stubs to dart2js similar to what was
done for toJS.
- Adds generic stub to DDC as these stubs don't get
tree-shaken away and toJSCaptureThis is less likely to be
used.
- Modifies dart2wasm lowerings to add this to the JS
function wrapper if calling toJSCaptureThis.

Change-Id: Ic0a7fd768de1dd6b491998e029ff5eb406ee7992
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377160
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-08-01 01:02:47 +00:00
Nicholas Shahan 77be340ce8 [ddc] Fix the internal type of prototype objects
Ensure that if a prototype object of a native peer class flows
into the program through JavaScript interop, it will be interpreted
as an interop object, instead of the Dart peer class.

Add some regression tests.

Fixes: https://github.com/dart-lang/sdk/issues/56322
Change-Id: Ic84bbdc4784e667a8730a9f1d578527b4bbdd198
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377763
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-07-30 15:33:28 +00:00
Nicholas Shahan 21dee0734f [js_interop] Add tests for Object literal factory
Ensures factories using named arguments to create Object literals
work as expected when the names shadow properties on the native
JavaScript Object prototype.

Issue: https://github.com/dart-lang/sdk/issues/56315
Change-Id: Iaae8390f853a6f32ac6ba891a56643296a394930
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377723
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-07-29 18:19:54 +00:00
Srujan Gaddam 4806f5cb0a [dart:js_interop] Add JSArray.length and accessors
Also cleans up some TODOs due to previous JSArray
limitations.

Change-Id: Id17e5d069538defc0f89b8f5e1a0e52d3c07ce2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373884
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-07-24 17:40:05 +00:00
Srujan Gaddam abdba89805 [dart2wasm] Fix type casts in interop lowerings
Closes https://github.com/dart-lang/sdk/issues/54314
Closes https://github.com/dart-lang/sdk/issues/56004

- Fixes calling interop members with generic return
type so that there's a cast based on the expected static
type.
- Fixes converted callbacks that take generic parameters
by passing a "cast closure" that captures the generic types
and then casts the arguments to the JS wrapper to those
generic types.
- Adds and cleans up some tests.
- Adds and cleans up documentation around callbacks.

Change-Id: I3749e9326cfa31ee759a89203d513be39019d86d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/374847
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-07-24 16:57:46 +00:00
Srujan Gaddam 9e0acbc52b Reland "[dart:js_interop] Add typed array/data buffer constructors"
This reverts commit 3f77881352.

Reason for revert: Relanding with test fixes. The setting of
maxByteLength via constructor is not available on the Firefox
and Safari versions in the bots but is available in newer
versions. See
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/ArrayBuffer#browser_compatibility
for more details. For now, since we're just testing whether
the constructor exists, it suffices to remove the test for the
property.

Original change's description:
> Revert "[dart:js_interop] Add typed array/data buffer constructors"
>
> This reverts commit aa48f77d44.
>
> Reason for revert: Broke Safari/Firefox bots due to maxByteLength not returning an int.
>
> Original change's description:
> > [dart:js_interop] Add typed array/data buffer constructors
> >
> > - Adds constructors for JSArrayBuffer, JSDataView, and
> >   concrete typed array types e.g. JSInt8Array.
> >
> > While JSDataView and the typed array types can also take in
> > a SharedArrayBuffer, we currently don't have a type that
> > represents that type. Therefore we keep it as JSArrayBuffer
> > and not JSObject as that would be too general.
> >
> > Change-Id: Iea1e08a9a8225accc7fc3550f0f8fe88039a1eb5
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343940
> > Reviewed-by: Leaf Petersen <leafp@google.com>
> > Commit-Queue: Srujan Gaddam <srujzs@google.com>
> > Reviewed-by: Sigmund Cherem <sigmund@google.com>
> > Reviewed-by: Ömer Ağacan <omersa@google.com>
> > Reviewed-by: Martin Kustermann <kustermann@google.com>
>
> Change-Id: I74ab5ceb4be6d51f3429703bdf4a467bf31e7f1c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377122
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

CoreLibraryReviewExempt: Reland with just test fixes.
Change-Id: I8bc6a86aba83138ad627e299486f688e531b55a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377123
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-07-23 16:14:09 +00:00
Srujan Gaddam 3f77881352 Revert "[dart:js_interop] Add typed array/data buffer constructors"
This reverts commit aa48f77d44.

Reason for revert: Broke Safari/Firefox bots due to maxByteLength not returning an int.

Original change's description:
> [dart:js_interop] Add typed array/data buffer constructors
>
> - Adds constructors for JSArrayBuffer, JSDataView, and
>   concrete typed array types e.g. JSInt8Array.
>
> While JSDataView and the typed array types can also take in
> a SharedArrayBuffer, we currently don't have a type that
> represents that type. Therefore we keep it as JSArrayBuffer
> and not JSObject as that would be too general.
>
> Change-Id: Iea1e08a9a8225accc7fc3550f0f8fe88039a1eb5
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343940
> Reviewed-by: Leaf Petersen <leafp@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: I74ab5ceb4be6d51f3429703bdf4a467bf31e7f1c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377122
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-07-22 23:48:57 +00:00
Srujan Gaddam aa48f77d44 [dart:js_interop] Add typed array/data buffer constructors
- Adds constructors for JSArrayBuffer, JSDataView, and
  concrete typed array types e.g. JSInt8Array.

While JSDataView and the typed array types can also take in
a SharedArrayBuffer, we currently don't have a type that
represents that type. Therefore we keep it as JSArrayBuffer
and not JSObject as that would be too general.

Change-Id: Iea1e08a9a8225accc7fc3550f0f8fe88039a1eb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343940
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-07-22 23:18:48 +00:00
Srujan Gaddam f9cd24327f Put expected value first in importModule tests
Change-Id: I1e1cb720c6bcc6991ab10def235dc3b97977c6c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373402
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
2024-06-27 13:58:53 +00:00
Srujan Gaddam 1c534e5fd5 [dart2wasm/ddc/dart2js] Lower Function.toJS and JSExportedDartFunction.toDart
Lowers these extension methods to some helper functions instead of
allowInterop to improve performance and get consistent semantics.

Specifically:
- Function.toJS no longer gives you the same JSFunction when calling
toJS on the same function multiple times in the JS compilers.
- Adds fast calling syntax for functions with 0-5 args in the JS
compilers.
- Allows additional args to be passed to converted functions that
are omitted in the JS compilers.
- The static type now determines the number of args that can be
passed to the JS function in the JS compilers.
- Fixes an issue in dart2wasm where if too few arguments are
passed, the call may succeed due to conversion of undefined to
null.
- Adds throws when a user tries to wrap a JS function that
returned from Function.toJS in the JS compilers.

Closes https://github.com/dart-lang/sdk/issues/55515
Addresses https://github.com/dart-lang/sdk/issues/48186

CoreLibraryReviewExempt: Changes to docs only in API surface.
Change-Id: I41d864dc5e02b597d9f1c16c88e3c04872f28225
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368065
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-26 23:06:36 +00:00
Srujan Gaddam b8402f5c27 [dart:js_interop] Make ExternalDartReference generic
Closes https://github.com/dart-lang/sdk/issues/55342
Closes https://github.com/dart-lang/sdk/issues/55536
Closes https://github.com/dart-lang/sdk/issues/56015

- Adds a type parameter T that extends Object? to
ExternalDartReference to capture the type of the value
that was externalized.
-- In the JS compilers, the representation type of
ExternalDartReference is now T.
-- In dart2wasm, the representation type is now JSValue?.
- ExternalDartReference no longer implements Object.
- Return type of toDartObject is now T.
- ObjectToExternalDartReference and
ExternalDartReferenceToObject both now are on a T that is
bound to Object?.
- Internal patches for WeakReference and Finalizer are
updated.

Change-Id: Ic2dc834b17ec6a4eb2122cba3c495a6e0a1eae6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370663
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2024-06-26 21:53:53 +00:00
Srujan Gaddam 1550539558 [dart:js_interop] Make not and isTruthy return JSBoolean
Since these operators can't be written by users, prefer
to keep them as JS types.

Closes https://github.com/dart-lang/sdk/issues/55267

Change-Id: Ifb9b581fb82e057ba14c669a5a3934f9c502d06f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359181
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-06-25 17:50:33 +00:00
Srujan Gaddam 0b761229cc [dart:js_interop] Change importModule to accept JSAny
Closes https://github.com/dart-lang/sdk/issues/55429
Closes https://github.com/dart-lang/sdk/issues/55508

Objects like TrustedScriptURLs can be passed to the dynamic import
function, and therefore importModule should accept any JS value.

Change-Id: I43ce9aeb1e8fbd628bc768a16b246ba19470b1dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363504
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-06-25 17:50:33 +00:00
Srujan Gaddam 06ec78851b [dart:js_interop] Add static error for converted functions that contain named params
Like type parameters, these parameters can't be passed from JS and
such functions already do not work as intended as there is no way
to pass named args to a JS function. These named parameters were
being silently ignored in dart2wasm when creating the function
trampoline.

Change-Id: Iebb890de05f8b242e0542c1ec8f2c0582c5232df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368062
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2024-06-14 19:42:10 +00:00
Ömer Sinan Ağacan dbcf23a5ed [dart2wasm] Disallow dart:ffi in user code
Change-Id: I1d99637e4538a183d8fa567399bfb7c55675e60e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368568
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-05-31 07:12:21 +00:00
Srujan Gaddam 307d739158 [dart:js_interop] Fix lowerings of ExternalDartReferences
Closes https://github.com/dart-lang/sdk/issues/55549
Closes https://github.com/dart-lang/sdk/issues/55340

Fixes several issues around using ExternalDartReferences:
- Better inlining of interop methods is enabled when this
type is used. This also indirectly improves inlining when
using JSAny.
- Adding some missed inlining for setting properties in
general.
- Allows opaque references of Dart functions to be passed
to JS
- Allows type parameters that extend ExternalDartReference
to be used in interop methods.
- Fixes up parent pointers of nodes in transforms.

Change-Id: I8cbd163ee3c1b98e733c35a61e6e83a0787d334c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364580
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-04-26 19:08:13 +00:00
Lasse R.H. Nielsen b464fc9037 Reland "Tweak expect.dart library."
This reverts commit cd2c566bcf.

Reason for revert: Updating to not remove field used by Flutter engine.

Original change's description:
> Revert "Tweak `expect.dart` library."
>
> This reverts commit ff5f391c0a.
>
> Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one.
>
> Original change's description:
> > Tweak `expect.dart` library.
> >
> > Make API more consistent for a few methods.
> > Reduce the number of language features used in tests:
> > * Never iterating an iterable, always converting it
> >   using `.toList()` first and iterating using indices
> >   (fx `setEquals`).
> >   Also require a `List` in places where an `Iterable`
> >   wasn't necessary.
> > * Avoid doing complicated computations that are also
> >   used for the error message. Do simple check first,
> >   then recompute to get better error messages
> >   (fx `allDistinct`).
> >
> > Renamed some rarely used members for consistency
> > (`stringContainsInOrder`->`containsInOrder`,
> > where other string-contains functions just start
> > with `contains`, and `containsOneOf` -> `containsAny`
> > to match `Iterable.any` phrasing, and also it accepts
> > if containing at least one, not precisely one.)
> >
> > Removed a function that wasn't used anywhere.
> >
> > Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
> > Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.
> >
> > Deprecates `package:expect/minitest.dart`. It was never intended
> > to be used for new tests, only as a help to convert existing tests
> > written against `package:unit_test`.
> > All existing imports marked as `// ignore: deprecated_member_use`.
> >
> > Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
> > Reviewed-by: Slava Egorov <vegorov@google.com>
> > Reviewed-by: Ömer Ağacan <omersa@google.com>
> > Reviewed-by: Nate Bosch <nbosch@google.com>
> > Reviewed-by: Stephen Adams <sra@google.com>
> > Commit-Queue: Lasse Nielsen <lrn@google.com>
>
> Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>
> Reviewed-by: Leaf Petersen <leafp@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: William Hesse <whesse@google.com>

CoreLibraryReviewExempt: Reland
Change-Id: I53db40edc0733842a008839c3913d51c885e39ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362502
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-26 15:28:26 +00:00
William Hesse cd2c566bcf Revert "Tweak expect.dart library."
This reverts commit ff5f391c0a.

Reason for revert: The expect library is used by Flutter engine, and some of its tests use assertStatementsEnabled. There should be a migration path that doesn't require an atomic change, like adding the replacement api before removing the old one.

Original change's description:
> Tweak `expect.dart` library.
>
> Make API more consistent for a few methods.
> Reduce the number of language features used in tests:
> * Never iterating an iterable, always converting it
>   using `.toList()` first and iterating using indices
>   (fx `setEquals`).
>   Also require a `List` in places where an `Iterable`
>   wasn't necessary.
> * Avoid doing complicated computations that are also
>   used for the error message. Do simple check first,
>   then recompute to get better error messages
>   (fx `allDistinct`).
>
> Renamed some rarely used members for consistency
> (`stringContainsInOrder`->`containsInOrder`,
> where other string-contains functions just start
> with `contains`, and `containsOneOf` -> `containsAny`
> to match `Iterable.any` phrasing, and also it accepts
> if containing at least one, not precisely one.)
>
> Removed a function that wasn't used anywhere.
>
> Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
> Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.
>
> Deprecates `package:expect/minitest.dart`. It was never intended
> to be used for new tests, only as a help to convert existing tests
> written against `package:unit_test`.
> All existing imports marked as `// ignore: deprecated_member_use`.
>
> Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Nate Bosch <nbosch@google.com>
> Reviewed-by: Stephen Adams <sra@google.com>
> Commit-Queue: Lasse Nielsen <lrn@google.com>

Change-Id: I360b4347470a0bb2b63c3108e2b83ee2a771bf3f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362020
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: William Hesse <whesse@google.com>
2024-04-09 18:10:57 +00:00
Lasse R.H. Nielsen ff5f391c0a Tweak expect.dart library.
Make API more consistent for a few methods.
Reduce the number of language features used in tests:
* Never iterating an iterable, always converting it
  using `.toList()` first and iterating using indices
  (fx `setEquals`).
  Also require a `List` in places where an `Iterable`
  wasn't necessary.
* Avoid doing complicated computations that are also
  used for the error message. Do simple check first,
  then recompute to get better error messages
  (fx `allDistinct`).

Renamed some rarely used members for consistency
(`stringContainsInOrder`->`containsInOrder`,
where other string-contains functions just start
with `contains`, and `containsOneOf` -> `containsAny`
to match `Iterable.any` phrasing, and also it accepts
if containing at least one, not precisely one.)

Removed a function that wasn't used anywhere.

Moved `assertStatementsEnabled` to `variations.dart` as `asserts`.
Removed `typeAssertionsEnabled` and `checkedModeEnabled`. The former used in one place, where it was replaced with `checkedImplicitDowncasts` from `variations.dart`, the latter wasn't used anywhere.

Deprecates `package:expect/minitest.dart`. It was never intended
to be used for new tests, only as a help to convert existing tests
written against `package:unit_test`.
All existing imports marked as `// ignore: deprecated_member_use`.

Change-Id: I07e21d4c0f3ccf11b82ee34af2668fdbb22264d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352360
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-04-09 14:49:17 +00:00
Srujan Gaddam 2631319edf [dart2wasm] Use node's enclosing library annotation for lowerings
Closes https://github.com/dart-lang/sdk/issues/55359

The current library's annotation is used for the interop lowerings
in dart2wasm. For most members, this is okay because we emit the
equivalent JS code for the member when we visit the procedure and
not when we visit the invocation. However, for methods, the invocation
determines the resulting JS call due to the existence of optional
parameters. In that case, if the invocation was not in the same
library as the interop member declaration, it results in using the
wrong library's annotation value.

Adds tests for this case and does some cleanup of existing tests.

Specifically:
- Adds a consistent naming scheme for test libraries that are
namespaced.
- Adds code to delete the non-namespaced declarations so that the
namespaced interop methods don't accidentally call those declarations.
- Removes differentArgsMethod which was already tested in
js_default_test.
- Removes use of js_util in favor of js_interop_unsafe.

Change-Id: Iac2abe7f11b17b149fb6726c007e1ffa434c3c5c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361241
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-04-05 17:43:48 +00:00
Nicholas Shahan eda91b407d [tests] Add implicit downcast requirements
Some expectations in these tests rely on implicit downcasts throwing
errors at runtime.

Fixes: https://github.com/dart-lang/sdk/issues/55353
Change-Id: Ie1923e26552b95ddb3d4199e0f8f5a2a05e2c124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361004
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
2024-04-04 00:42:24 +00:00
Nicholas Shahan add2f411e6 [web] Add static js interop .call() tests
These tests should help:
 - avoid regressions in the existing behavior
 - highlight incremental improvements towards implementing the
   desired behavior (with corresponding changes to the expectations)
 - identify the differences between the JavaScript and wasm compilers

Change-Id: Ie95233868a13b7ffffc2688ab7c973dcd14ed721
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359246
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2024-04-02 17:03:12 +00:00
Nicholas Shahan 8ca97716cc [dart2js,ddc] Add package:js .call() tests
Some expectations in these tests do not match the language 
specification or are undefined.

These tests should help:
 - avoid regressions in the existing behavior
 - highlight incremental improvements towards implementing the 
   desired behavior (with corresponding changes to the expectations)
 - identify the differences between the JavaScript compilers

Change-Id: Icaa7371b3cf8c4221e4348176f712b3d03196720
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359245
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-04-02 00:41:23 +00:00
Srujan Gaddam d1a949a8e5 Add static tests for external extension members on extension types
We have tests for whether external extension members are allowed
on certain classes, but not extension types.

Also rewords the error to be more accurate.

Change-Id: I61c1fa4c101971986b6c8e7cc778aca94908816a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358380
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-26 15:43:19 +00:00
Srujan Gaddam 1232260158 [dart:js_interop] Add ExternalDartReference
Closes https://github.com/dart-lang/sdk/issues/55187

Adds a faster way for users to pass opaque Dart values to
JS without the need for boxing like in JSBoxedDartObject.
This does mean, however, that this new type can't be a JS type,
and therefore cannot have interop members declared on it.
Refactors existing code to handle that distinction.

CoreLibraryReviewExempt: Backend-specific library that's been reviewed by both dart2wasm and JS compiler teams.
Change-Id: Ia86f1fe3476512fc0e5f382e05739713b687f092
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358224
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-03-26 15:43:19 +00:00
Srujan Gaddam 47f08fb143 [dart:js_interop] Change several operators back to JSBoolean
Related issues:
https://github.com/dart-lang/sdk/issues/55024
https://github.com/dart-lang/sdk/issues/55267

These operators were initially broken in 3.3 and were exposed
as returning JSBoolean but implemented as returning bool. They
were fixed to return bool in the public API, but we should
prefer to have them return JS types as they're likely to be used
in cases where implicit conversions are not useful.

CoreLibraryReviewExempt: Fixing type mismatch in backend-specific library.
Change-Id: I3b0e60550dcac78918f8399d11238dcfa34982cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359180
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2024-03-25 17:05:36 +00:00
Srujan Gaddam 7685ec3e0e [dart:js_interop] Better error reporting for invalid external types
Closes https://github.com/dart-lang/sdk/issues/54320

Several improvements to the error reporting:

- Split errors to avoid parametrizing error strings.
- Use one error per member/toJS invocation.
- Highlight the invalid types in the signature.

Extra tests are added to get coverage for things like operators.

Change-Id: I6d8ac3cf0124730e7c2c0dab3a107da5d0263f7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347226
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-15 23:36:22 +00:00
Srujan Gaddam 55df0ca4d6 [dart:js_interop] Fix operator precedence in determining constructor type
Fixes https://github.com/dart-lang/sdk/issues/55107

The lack of parentheses around the ternary operator made the check
invalid when there are members that aren't constructors in the
extension type.

Change-Id: I87ce918c478113f682d3df28f148b7f59d4fd075
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355883
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2024-03-06 17:39:29 +00:00