Closed
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
externref
first.
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:
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done