[dart2wasm] Move wasm-js interop to dart:_js_interop_wasm

Some features in `dart:_wasm` are relevant for all WebAssembly targets
(like interop types or memory intrinsics). Others, in particular the
helper methods to convert between `WasmExternRef` and `JSAny`, don't
make sense for the standalone target.

To be able to remove the `js_interop` library from the standalone
target, we need to stop importing it from `dart:_wasm`. To prepare that
step, this moves the helpers to a new library (`dart:_js_interop_wasm`)
and re-exports them from `dart:_wasm`.

Once Flutter has migrated to the new import, the export can be removed.

Bug: https://github.com/dart-lang/sdk/issues/63166
Change-Id: I13fe875e509a13d16c48d420a5927d3130b90736
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505080
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Simon Binder <oss@simonbinder.eu>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
Simon Binder
2026-05-22 04:06:27 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 1d61eecafa
commit 3196571c9b
17 changed files with 70 additions and 29 deletions
+2 -1
View File
@@ -209,7 +209,8 @@ class WasmTarget extends Target {
return true;
}
if (imported.toString() == 'dart:_wasm') {
if (imported.toString() == 'dart:_wasm' ||
imported.toString() == 'dart:_js_interop_wasm') {
return enableExperimentalWasmInterop;
}
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/fuse_with_and/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/fuse_with_and/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/fuse_with_or/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/fuse_with_or/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/just_fuse/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
@@ -6,8 +6,8 @@ Part 0
- pkg/compiler/test/custom_split/data/just_fuse/lib4.dart prefix: b4
References
- dart:_boxed_int::BoxedInt::@methods::toRadixString
- dart:_string::@methods::dart:_string::_JS_Inline_173
- dart:_string::@methods::dart:_string::_JS_Inline_181
- dart:_string::@methods::dart:_string::_JS_Inline_179
- dart:_string::@methods::dart:_string::_JS_Inline_187
- dart:_string::@methods::dart:_string::_jsIdentical
- dart:_string::@methods::dart:_string::_jsStringToUpperCase
- dart:_string::@methods::jsStringFromCharCodeArray
+1
View File
@@ -248,6 +248,7 @@ _full_sdk_libraries = [
"js",
"js_interop",
"js_interop_unsafe",
"_js_interop_wasm",
"js_util",
"math",
"mirrors",
@@ -337,6 +337,11 @@ const Map<String, LibraryInfo> libraries = const {
categories: '',
documented: false,
),
'_js_interop_wasm': const LibraryInfo(
'_js_interop_wasm/js_interop_wasm.dart',
categories: '',
documented: false,
),
};
/// Information about a "dart:" library.
@@ -0,0 +1,19 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Utilities to transform between `dart:js_interop` types and `WasmExternRef`
/// from `dart:_wasm`.
library;
import 'dart:_wasm';
import 'dart:js_interop';
extension WasmExternRefToJSAny on WasmExternRef {
external JSAny get toJS;
}
// Note: We would make this an extension method on JSAny, but external methods
// on JS interop types are assumed to be JS interop functions, not methods that
// are patched in patch files. So instead we just use a plain function here.
external WasmExternRef? externRefForJSAny(JSAny object);
@@ -0,0 +1,5 @@
# Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
js_interop_wasm_sdk_sources = [ "js_interop_wasm.dart" ]
+3 -10
View File
@@ -4,7 +4,9 @@
library dart._wasm;
import 'dart:js_interop';
// TODO(63166): Remove this export after migrating Flutter to import that
// library directly.
export 'dart:_js_interop_wasm';
part 'memory.dart';
@@ -787,15 +789,6 @@ extension DoubleWasmInstructions on double {
double sqrt() => this.toWasmF64().sqrt().toDouble();
}
extension WasmExternRefToJSAny on WasmExternRef {
external JSAny get toJS;
}
// Note: We would make this an extension method on JSAny, but external methods
// on JS interop types are assumed to be JS interop functions, not methods that
// are patched in patch files. So instead we just use a plain function here.
external WasmExternRef? externRefForJSAny(JSAny object);
// Tests whether the given object's class is a subclass of T.
//
// NOTICE: If the object's class is a subtype of T but not a subclass this will
+14 -4
View File
@@ -354,8 +354,7 @@
]
},
"_wasm": {
"uri": "_wasm/wasm_types.dart",
"patches": "_internal/wasm_standalone/lib/wasm_types_patch.dart"
"uri": "_wasm/wasm_types.dart"
},
"math": {
"uri": "math/math.dart",
@@ -367,6 +366,12 @@
"js_interop": {
"uri": "_internal/wasm_standalone/lib/js_interop.dart",
"support_conditional_import": false
},
"_js_interop_wasm": {
"uri": "_js_interop_wasm/js_interop_wasm.dart",
"patches": [
"_internal/wasm_standalone/lib/js_interop_wasm_patch.dart"
]
}
}
},
@@ -395,8 +400,7 @@
]
},
"_wasm": {
"uri": "_wasm/wasm_types.dart",
"patches": "_internal/wasm/lib/wasm_types_patch.dart"
"uri": "_wasm/wasm_types.dart"
},
"async": {
"uri": "async/async.dart",
@@ -431,6 +435,12 @@
"js_interop_unsafe": {
"uri": "js_interop_unsafe/js_interop_unsafe.dart",
"patches": "_internal/wasm/lib/js_interop_unsafe_patch.dart"
},
"_js_interop_wasm": {
"uri": "_js_interop_wasm/js_interop_wasm.dart",
"patches": [
"_internal/wasm/lib/js_interop_wasm_patch.dart"
]
}
}
},
+8 -2
View File
@@ -298,7 +298,6 @@ wasm_standalone:
- _internal/vm_shared/lib/check_valid_weak_target_patch.dart
_wasm:
uri: _wasm/wasm_types.dart
patches: _internal/wasm_standalone/lib/wasm_types_patch.dart
math:
uri: math/math.dart
patches:
@@ -309,6 +308,10 @@ wasm_standalone:
# currently added as a stub because APIs in dart:_wasm reference it.
uri: _internal/wasm_standalone/lib/js_interop.dart
support_conditional_import: false
_js_interop_wasm:
uri: _js_interop_wasm/js_interop_wasm.dart
patches:
- _internal/wasm_standalone/lib/js_interop_wasm_patch.dart
wasm_js_common:
include:
@@ -329,7 +332,6 @@ wasm_js_common:
- _internal/vm_shared/lib/check_valid_weak_target_patch.dart
_wasm:
uri: _wasm/wasm_types.dart
patches: _internal/wasm/lib/wasm_types_patch.dart
async:
uri: async/async.dart
patches:
@@ -354,6 +356,10 @@ wasm_js_common:
js_interop_unsafe:
uri: js_interop_unsafe/js_interop_unsafe.dart
patches: _internal/wasm/lib/js_interop_unsafe_patch.dart
_js_interop_wasm:
uri: _js_interop_wasm/js_interop_wasm.dart
patches:
- _internal/wasm/lib/js_interop_wasm_patch.dart
wasm_common:
libraries:
+1
View File
@@ -16,6 +16,7 @@
// dart2wasmOptions=--extra-compiler-option=--enable-experimental-wasm-interop
import 'dart:_wasm';
import 'dart:_js_interop_wasm';
import 'dart:js_interop';
import 'package:expect/expect.dart';