-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop
Description
Externalizing some internal discussion on this topic already:
Currently, the way to pass Dart objects to JavaScript involves JSBoxedDartObject. Its conversion method, toJSBox does:
- On the JS backends, we create a JS object and then set a Dart runtime-specific symbol whose value is the Dart object.
- On dart2wasm, we do something very similar except the Dart object is converted to an
externreffirst.
While this offers a consistent interface on the JavaScript side and avoids mixing Dart objects between runtimes, it does come with downsides:
- It's slow, especially if passing Dart objects to JS is a common operation.
- It creates a new box everytime the Dart object is converted, requiring users to be careful about identity.
- Users aren't meant to actually access the Dart value in the box.
Instead, we can provide a better type here which doesn't provide any consistency or runtime safety, but addresses the above downsides. As it's not a JS value, it shouldn't be a subtype of JSAny and our error checker should allowlist this value to flow into JS.
Related issues:
ykmnkmi and bivens-dev
Metadata
Metadata
Assignees
Labels
area-dart2wasmIssues for the dart2wasm compiler.Issues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interopIssues that impact all js interop
Type
Projects
Status
Done