Commit Graph

279 Commits

Author SHA1 Message Date
Srujan Gaddam 94e1217774 Reland "[dart:js_interop] Make JSFunction and JSExportedDartFunction generic"
This is a reland of commit e7dbd6ba48

Original change's description:
> [dart:js_interop] Make JSFunction and JSExportedDartFunction generic
>
> Fixes https://github.com/dart-lang/sdk/issues/54557
>
> The generic type in JSExportedDartFunction corresponds to the
> static type of the function it wrapped, whereas for JSFunction,
> it's purely a descriptor of the JS function.
>
> When calling JSExportedDartFunction, a cast is now introduced
> to cast it to T.
>
> When calling isA, the type in JSExportedDartFunction is passed
> along to check that the value that is wrapped is that function
> type. Because the T in JSFunction is descriptive, e.g.
> isA<JSFunction<int Function()>>() does no such check.
>
> ____
>
> Also cleans up:
>
> - isA<JSTypedArray>() logic to use intrinsic functions
> - some expectation files to be consistent for both dart2js and ddc.
>
> CoreLibraryReviewExempt: Backend-specific library with needed reviews.
> Change-Id: I1a55c4386e416fa4ccabe06ac5051f41c2e2e95a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496820
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

CoreLibraryReviewExempt: Reland.
Change-Id: I29d706aa4967fd80390e8cb37f8144603ec007f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498100
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-04-27 20:32:55 -07:00
Srujan Gaddam 442bdeda4a Revert "[dart:js_interop] Make JSFunction and JSExportedDartFunction generic"
This reverts commit e7dbd6ba48.

Reason for revert: Broke flutter_analyze

Original change's description:
> [dart:js_interop] Make JSFunction and JSExportedDartFunction generic
>
> Fixes https://github.com/dart-lang/sdk/issues/54557
>
> The generic type in JSExportedDartFunction corresponds to the
> static type of the function it wrapped, whereas for JSFunction,
> it's purely a descriptor of the JS function.
>
> When calling JSExportedDartFunction, a cast is now introduced
> to cast it to T.
>
> When calling isA, the type in JSExportedDartFunction is passed
> along to check that the value that is wrapped is that function
> type. Because the T in JSFunction is descriptive, e.g.
> isA<JSFunction<int Function()>>() does no such check.
>
> ____
>
> Also cleans up:
>
> - isA<JSTypedArray>() logic to use intrinsic functions
> - some expectation files to be consistent for both dart2js and ddc.
>
> CoreLibraryReviewExempt: Backend-specific library with needed reviews.
> Change-Id: I1a55c4386e416fa4ccabe06ac5051f41c2e2e95a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496820
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I98447c8c95906feb7f8f1a57859a24fc8e4966d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498080
Commit-Queue: Alexander Aprelev <aam@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
2026-04-24 09:31:08 -07:00
Srujan Gaddam e7dbd6ba48 [dart:js_interop] Make JSFunction and JSExportedDartFunction generic
Fixes https://github.com/dart-lang/sdk/issues/54557

The generic type in JSExportedDartFunction corresponds to the
static type of the function it wrapped, whereas for JSFunction,
it's purely a descriptor of the JS function.

When calling JSExportedDartFunction, a cast is now introduced
to cast it to T.

When calling isA, the type in JSExportedDartFunction is passed
along to check that the value that is wrapped is that function
type. Because the T in JSFunction is descriptive, e.g.
isA<JSFunction<int Function()>>() does no such check.

____

Also cleans up:

- isA<JSTypedArray>() logic to use intrinsic functions
- some expectation files to be consistent for both dart2js and ddc.

CoreLibraryReviewExempt: Backend-specific library with needed reviews.
Change-Id: I1a55c4386e416fa4ccabe06ac5051f41c2e2e95a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496820
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-04-23 20:55:26 -07:00
Natalie Weizenbaum d863706259 Add JS iterable types
Closes https://github.com/dart-lang/sdk/pull/62610

GitOrigin-RevId: 63f5c6eddcd2e3f6ef88656c34d67df68c053c12
Change-Id: I74556b1bd8241e1de344d4f73ca76cfea7167de6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478704
Commit-Queue: Kevin Moore <kevmoo@google.com>
Reviewed-by: Jackson Gardner <jacksongardner@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2026-04-06 13:30:46 -07:00
Nate Biggs c3b28c2da4 [dart2wasm] Add test for stack traces originating in JS.
Ensure we don't remove any frames from these like we do for Dart stack
traces.

Change-Id: I32c3a53bc229873a05e35767f7fa27c2ec4643e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483846
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Auto-Submit: Nate Biggs <natebiggs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2026-03-03 13:52:30 -08:00
Nate Biggs 0f3c75d1eb [js_interop] Add jsIdentical function that implements === on JS values backing Dart values.
dart2js and DDC implement `identical` using JS `===`. This means for
interop values the objects will be compared using JS strict equality
semantics. For Strings in particular this means value equality rather
than reference equality.

In wasm we use equality on the struct reference wrapping the JS value.
This leads to differing semantics between JS and wasm when using
identical on these JS wrapped values.

`jsIdentical` provides a way to have consistent semantics between JS and
wasm.

Change-Id: I207fbbb294254798372924a55cdb2691094a5461
CoreLibraryReviewExempt: Just updating web-related code.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483440
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2026-02-27 16:27:06 -08:00
Srujan Gaddam 0615d3a467 [dart:js_interop] Make isA<JSExportedDartFunction>() check that it's a wrapped function
Closes https://github.com/dart-lang/sdk/issues/62573

isA<JSExportedDartFunction>() used to just check if the object
was a function, leading to a possible runtime error if `toDart`
is called. Fixes that by introducing some helpers and moving
around some functions in the JS compilers to other internal
libraries (public members can't be added to
js_allow_interop_patch.dart). Also fixes a minor issue in dart2js
where `allowInterop`ed functions could successfully invoke
`JSExportedDartFunction.toDart`.

CoreLibraryReviewExempt: Documentation change.
Change-Id: I5a9d7c31d3143eb3fb6ebd3273a4bf06ca329479
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482967
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2026-02-24 10:40:43 -08:00
Srujan Gaddam 9f367b1709 [dart:js_interop] Expand isA to Object?
Fixes https://github.com/dart-lang/sdk/issues/56905

Instead of just supporting isJSAny and isJSObject, we
can support isA for all objects. Depending on the static
type, we include an intrinsic _isJSAny function first in
the transformation. For fast paths for JSObjects, we also
now call an intrinsic function which has the added benefit
of now correctly returning true for objects with no prototype.

The intrinsic functions in dart2wasm need to be careful to
not treat ExternalDartReferences as JS values, so JSValue
is amended to include a field that determines if the value
is a Dart value (and caches it if not set already). JSValue
constructions are updated to pass false for this field if
we know for sure this value isn't an externalized Dart value.

CoreLibraryReviewExempt: Backend-specific function changes.
Change-Id: Ib2a6e74b4130632791375fcda9a5b85198ad64af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/478241
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-02-19 14:10:32 -08:00
Lasse R.H. Nielsen 6fe105671c Remove var and final from parameters in test/.
Not removing from any file with a language marker.
Also not touching anything in `tests/language/primary_constructors`
or `.../private_named_parameters`, which are both assumed to be
primary constructor feature aware.

Two files rewritten from multi-test to error-test.

Change-Id: I43d444a35a41c7734f266794e9f167655692473f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480640
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2026-02-17 08:28:57 -08:00
Natalie Weizenbaum 9947e20c36 Add additional definitions to JSSymbol
Closes https://github.com/dart-lang/sdk/pull/61917

GitOrigin-RevId: 16c03048f0108a22a36713513ea646cf43d89e87
Change-Id: Ia2f7d79d3e1048da7684da2a55eda0266c57489f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460141
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-12-22 09:50:26 -08:00
Ben Konyi 364b36691c Reland "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
This reverts commit c616db31d2.

Reason for revert: Fix landed downstream in Flutter engine: https://github.com/flutter/flutter/pull/180127

Original change's description:
> Revert "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
>
> This reverts commit b5e60be49d.
>
> Reason for revert: broke Flutter web engine tests
>
> Original change's description:
> > [ DDC / CFE ] Add support for allowing imports of unsupported libraries
> >
> > This change adds support for allowing for imports of unsupported
> > platform-specific libraries when the
> > `--include-unsupported-platform-library-stubs` flag is provided to the
> > CFE.
> >
> > This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
> > `TargetFlags`, which `Target`s can use to conditionally return different
> > `DartLibrarySupport` objects with different supported/unsupported
> > library sets.
> >
> > A `checkForUnsupportedDartColonImports` function has been added to
> > `Target` that uses the value of `dartLibrarySupport` to determine if
> > there's any unsupported library imports. This function is called after
> > the various transformation operations provided by the `Target`
> > implementation, meaning the import of an unsupported library specified
> > in `dartLibrarySupport` will now result in a compilation error (this
> > includes `dart:mirrors` imports for VM targets when mirrors are
> > disabled, which was previously handled by the VM itself).
> >
> > Related to https://github.com/dart-lang/sdk/issues/62125
> >
> > TEST=Tests added / modified
> >
> > Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
> > Reviewed-by: Nicholas Shahan <nshahan@google.com>
> > Reviewed-by: Johnni Winther <johnniwinther@google.com>
> > Commit-Queue: Ben Konyi <bkonyi@google.com>
>
> Change-Id: I0b59f00e55a2424f783351abd977eb38409ce01f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469100
> Reviewed-by: Nate Biggs <natebiggs@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Sigmund Cherem <sigmund@google.com>

Change-Id: I1ae2eac675432286aebabea3c1f58caf35a27fbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469240
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-12-19 12:53:22 -08:00
Alexander Markov c616db31d2 Revert "[ DDC / CFE ] Add support for allowing imports of unsupported libraries"
This reverts commit b5e60be49d.

Reason for revert: broke Flutter web engine tests

Original change's description:
> [ DDC / CFE ] Add support for allowing imports of unsupported libraries
>
> This change adds support for allowing for imports of unsupported
> platform-specific libraries when the
> `--include-unsupported-platform-library-stubs` flag is provided to the
> CFE.
>
> This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
> `TargetFlags`, which `Target`s can use to conditionally return different
> `DartLibrarySupport` objects with different supported/unsupported
> library sets.
>
> A `checkForUnsupportedDartColonImports` function has been added to
> `Target` that uses the value of `dartLibrarySupport` to determine if
> there's any unsupported library imports. This function is called after
> the various transformation operations provided by the `Target`
> implementation, meaning the import of an unsupported library specified
> in `dartLibrarySupport` will now result in a compilation error (this
> includes `dart:mirrors` imports for VM targets when mirrors are
> disabled, which was previously handled by the VM itself).
>
> Related to https://github.com/dart-lang/sdk/issues/62125
>
> TEST=Tests added / modified
>
> Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
> Reviewed-by: Nicholas Shahan <nshahan@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

Change-Id: I0b59f00e55a2424f783351abd977eb38409ce01f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469100
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2025-12-18 09:47:11 -08:00
Ben Konyi b5e60be49d [ DDC / CFE ] Add support for allowing imports of unsupported libraries
This change adds support for allowing for imports of unsupported
platform-specific libraries when the
`--include-unsupported-platform-library-stubs` flag is provided to the
CFE.

This flag sets the `includeUnsupportedPlatformLibraryStubs` property in
`TargetFlags`, which `Target`s can use to conditionally return different
`DartLibrarySupport` objects with different supported/unsupported
library sets.

A `checkForUnsupportedDartColonImports` function has been added to
`Target` that uses the value of `dartLibrarySupport` to determine if
there's any unsupported library imports. This function is called after
the various transformation operations provided by the `Target`
implementation, meaning the import of an unsupported library specified
in `dartLibrarySupport` will now result in a compilation error (this
includes `dart:mirrors` imports for VM targets when mirrors are
disabled, which was previously handled by the VM itself).

Related to https://github.com/dart-lang/sdk/issues/62125

TEST=Tests added / modified

Change-Id: Ife819b2e1a6d28f67d80aab6701cd23a1724aa4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465760
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2025-12-17 09:30:38 -08:00
Mayank Patke a63045d197 [dart2wasm] Remove dart:js_util from supported libraries
Since that stops `dart:_js_annotations` from building on dart2wasm,
let's stop supporting that, too.

This causes `package:js` to no longer work on dart2wasm, but none of the
allowlisted packages use it any longer, so we can simply migrate tests
off of it.

Fixes: #56502
Fixes: #61550
Change-Id: I6a6a696438255ebf25a5a17131cdbd327ba81581
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453645
Commit-Queue: Mayank Patke <fishythefish@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-10-15 15:38:35 -07:00
Mayank Patke 80281e6f6c [js] Migrate some tests to use js_interop rather than js_util
These tests need to run on dart2wasm but use `dart:js_util`, which
dart2wasm will no longer support.

`js_util` isn't core to the behavior being tested in
tests/lib/js/static_interop_test/; it's simply how the expectations were
written. This CL migrates those tests to use the new `dart:js_interop`
APIs for expectations.

Since dart2wasm no longer supports `dart:js_util`, which includes
`createStaticInteropMock`, it can simply skip
tests/lib/js/export/static_interop_mock/* in the status file.

We also split up tests/lib/js/export/functional_test into two separate
tests - one for `createDartExport` (which is also skipped on dart2wasm),
and one for `createJSInteropWrapper` (which runs on all web backends).
These tests can still share most of the code in a common library.

Bug: #61550
Change-Id: I6a6a6964b6f914fea5b42101204ab80910c49b36
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451221
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-09-25 14:22:43 -07:00
Mayank Patke 6d58b9a1e0 [js_interop] Allow createJSInteropWrapper to take a prototype
Fixes: #61567
CoreLibraryReviewExempt: got +1s from all relevant backends
Change-Id: I6a6a69640dc217b1bf019e6295c0aed253943731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451124
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-09-25 14:22:43 -07:00
fishythefish 3367e6167c [dart2wasm] Convert Promises with dartify
Fixes: #54573
Change-Id: I6a6a6964eb05637522a54d7f81e2d5dfcba5e556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450261
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2025-09-25 14:22:43 -07:00
Srujan Gaddam b01bf92f9a [dart2wasm] Typed array wrappers should unwrap instead of reinstantiate
Fixes https://github.com/dart-lang/sdk/issues/61543

toJS and jsify conversions instantiate a new typed array using
the same underlying buffer instead of returning the original
typed array. To fix this, the typed array wrappers now capture
the original array ref (if any) and return it in toJSArrayExternRef
if it exists and the caller didn't ask for a subrange.

Note that _ref in the wrappers refer to a DataView, and not
the array ref. Some methods are renamed to reduce that confusion.

Change-Id: Ia9befd114a77489aedbb3644c9604aef4b3af7c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450966
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-09-25 09:24:31 -07:00
Sergey G. Grekhov 409ecc7e93 [Test runner] Enable warnings for dart2js, dart2wasm and DDC
Enable support warnings in tests for `dart2js`, `dart2wasm` and DDC compilers

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

Change-Id: Ifcbcaca3deb0444e68bddfef7da2e4bdcb385e0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448960
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2025-09-19 03:45:23 -07:00
Ömer Ağacan 9eea7a334d [dart2wasm] Fix ByteData.elementSizeInBytes, ByteData to JS convs
Bug: https://github.com/dart-lang/sdk/issues/61515
Change-Id: I54821b61f310e084affbc4dfbe00c97573ebebfa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449901
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-09-18 03:27:02 -07:00
Srujan Gaddam 32f1db06cd [dart:js_interop] Add missing checks for toJSCaptureThis
Fixes https://github.com/dart-lang/sdk/issues/61439

These checks exist for toJS but were not added when we
introduced toJSCaptureThis. Error wording is slightly
modified to be consistent.

Change-Id: I12c861aacecc2bfed255be9f26c99bf2f1c02ebd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449661
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-09-16 10:30:21 -07:00
Srujan Gaddam 7155f169b1 [dart2wasm] Support non-identifiers in @JS renames
dart2js and ddc both have a rich enough JS AST to use
dot or bracket notation when necessary. Therefore,
both compilers have and do support @JS renames that
contain characters that aren't supported in dot
notation e.g. `my-lib`. We should have dart2wasm also
support such characters to be consistent, but prefer
dot notation and avoid adding extra `globalThis`
when possible.

Change-Id: Iabf4d6f88dd23321388841f3a6b64758f856c68f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447964
Reviewed-by: Ömer Ağacan <omersa@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-09-04 10:15:48 -07:00
Srujan Gaddam fe4c2c3e04 [dart2js/ddc] Support '.' in @JS renames in extension type and extension members
Fixes https://github.com/dart-lang/sdk/issues/61411

This was previously disallowed for static members in pkg:js
classes, but an error was never added for dart:js_interop types.
We could add an error, but this is useful for both static and
non-static members so users don't have to introduce new top-levels
or types just to access a nested member. This also makes it
consistent with dart2wasm.

Updates some front_end expectations tests as well to test
more syntax and renamed members.

Change-Id: I690d53d64fedc5869e1bdd9f7cfd86d256d7f75b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447482
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2025-09-04 09:07:20 -07:00
Simon Binder afa127b1c6 Support renaming fields for JS object literals
This respects the `@JS()` annotation on parameters of external
factories in JS extension types to customize the keys of created object
literals.

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

Change-Id: Idebeee922d2080356fd7449f639ecd2ae9ee5fc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445840
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-08-26 13:17:30 -07:00
Srujan Gaddam 3b39c2637b [ddc] Separate _emitObjectLiteral out from _emitArgumentList
Currently _emitArgumentList handles arguments for Dart
members, JS interop members, and object literal constructors.
It requires an Arguments node, which we end up synthesizing,
which messes with parent pointers erroneously. We also have
to separate out the arguments and do additional checks later
to detect whether the arguments passed correspond to an
object literal constructor.

Instead, we should create the resulting expression directly
in a helper method. A map is passed so that the names of
arguments can be easily changed when we handle @JS renaming
on object literal constructors. Lastly, we need to avoid
wrapping the values with assertInterop in the case where the
constructor is from a dart:js_interop interface. That library
only statically allows Functions to be passed if they're
externalized, in which case we shouldn't tell users to wrap
the Function with allowInterop (which doesn't exist anyways in
dart:js_interop).

Change-Id: If6fdc706e80837ab2b698cca704ffd9f08aed28a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446184
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-08-21 15:25:57 -07:00
Srujan Gaddam d672d98636 [dart:js_interop] Make isA<JSBoxedDartObject> check if it's a boxed object
Fixes https://github.com/dart-lang/sdk/issues/60644

Previously, we made no special case for JSBoxedDartObjects, so isA
would always return true for any object (as JSBoxedDartObject contains
an @JS('Object') annotation). This is not obvious however, and it's
much more useful to check that the value is a result of a previous
`toJSBox` call. Documentation is updated/cleaned up to make note of
the various exceptions in `isA`.

CoreLibraryReviewExempt: Web-only library.
Change-Id: Ibd8873d3f862f4c950101f5f049327a1aa5c7bf2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445522
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2025-08-19 12:56:51 -07:00
Srujan Gaddam 67d39caa81 [dart:js_interop] Non-empty @JSExport on class should not be a fatal error
Fixes https://github.com/dart-lang/sdk/issues/61291

Change-Id: I5a5c058cfe46880704912145b2ec98b19127282d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445101
Commit-Queue: Erik Ernst <eernst@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
2025-08-14 00:26:51 -07:00
Srujan Gaddam 16a43860a1 [dart:js_interop] Add JSArray.add
Fixes https://github.com/dart-lang/sdk/issues/59830

Migration from Lists to JSArray sometimes involve usages
of List.add. In the migration, if List.add was used, it would
become JSAnyOperationExtension.add, which is the JS + operator.
This then leads to bugs where users mistakenly assumed that
something similar to List.add was occurring.

CoreLibraryReviewExempt: Wasm and JS backends only.
Change-Id: I2bb6684316725167a8fa65fd51483f2717788dad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443182
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2025-08-05 11:35:34 -07:00
Srujan Gaddam 3e7e66767c [pkg:_js_interop_checks] Handle unnamed members in JSExport error handling
Fixes https://github.com/dart-lang/sdk/issues/61085

If a member that is not exportable is marked for export, we
mark it as an error using the member's name. In the case of
unnamed members, however, we don't have a name, and therefore
the template throws an error as it doesn't have a valid arg.

Instead, use "<unnamed>" in the absence of a name.

Change-Id: Ie0776c95f775eb3f09f582d0386a2097beedc7fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439641
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
2025-07-09 15:40:42 -07:00
Srujan Gaddam 6f85292b08 [dart2wasm] Support NullRejectionException.isUndefined
Previously, the implementation worked around boxing limitations
by always setting this field to false. However, because we
control both the callback and the JS code that calls the rejection
function, we can pass more information to the callback to let it
know whether the error was undefined.

Change-Id: Ic19f24ec20d321859eb8184d5c87744f7679cf0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439141
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
2025-07-08 09:47:12 -07:00
Srujan Gaddam 67bda7c22b [dart2js/ddc/dart2wasm/dart:js_interop] Support SharedArrayBuffers in JS typed data wrappers
https://github.com/dart-lang/sdk/issues/56455

The existing native typed data implementation in dart2js/ddc
and the JS typed data wrappers in dart2wasm do not support
SharedArrayBuffers.

In dart2js/ddc, this is because the native type for ByteBuffer
is simply ArrayBuffer, leading to type failures when using
SharedArrayBuffers. To handle this, this change makes NativeByteBuffer
an abstract parent class to NativeArrayBuffer and NativeSharedArrayBuffer.
This allows ByteBuffer to support both types. There is a preexisting
SharedArrayBuffer type in dart:html that we should avoid breaking, so
we add an interface that NativeSharedArrayBuffer implements and expose
that interface.

In dart2wasm, JSArrayBufferImpl only allows ArrayBuffers as its
extern ref. This change makes that wrapper support SharedArrayBuffers
as well.

In dart:js_interop, the existing toJS conversion on ByteBuffer
now throws if the underlying buffer was actually a SharedArrayBuffer.
This is to support the return type of JSArrayBuffer. This behavior
technically already existed due to type differences in the JS
compilers, but was never possible with dart2wasm.

CoreLibraryReviewExempt: Backend-specific libraries with no real functional changes to public APIs.
Change-Id: I4dac9fb808590bf0c274da815c152cd4637316b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437526
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2025-07-07 12:50:25 -07:00
Ryan Macnak 56636971dc [test_runner] Remove nnbd mode options.
In particular, this means the VM tests stop getting invoked with the now-invalid --sound-null-safety flag.

Change-Id: Ia8f5a59e0bf1fd7094508fdc4bb146ebf3034148
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431360
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Kallen Tu <kallentu@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-02 10:59:31 -07:00
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