-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose JSUnsafeDartObject in dart:js_interop_unsafe #55187
Comments
I think there's nothing unsafe about it - it's simply a lower-level primitive. This should be easily accessible, it should be the default way of doing things. Putting it into
Instead I'd suggest to add an extension to extension on Object {
JSExternalizedObject get externalize;
// or
JSWrapper get toJSWrapper;
// or
JSCompanion get toJSCompanion;
// or
JS... get <some-better-name>;
} /cc @sigmundch |
Thanks for the additional input @mkustermann! I'm open to moving this to be the default in I would only want to go through the exercise of recalling the reasons we initially suggested to put this in When we first proposed it, we had two safety goals in mind for the Dart/JS interop design: type soundness (which prior interop didn't have) and enforced separation of Dart and JS type hierarchies. We dropped the second goal when we discovered that it would have been too expensive to enforce such separation. In fact, it would have made type soundness even more expensive to achieve. (In case it helps, I also provided you with some additional references offline for context.) It all boiled down to what was our choice for what I believe that was the most likely reason we deemed it as unsafe, and I can't recall at the moment if there was something else. Given that since then we have made the choice of reify @srujzs - curious to hear your thoughts here too. |
I also think it's possible to put this in Beyond 1) soundness and 2) separation, I also was concerned about 3) consistency guarantees. I think soundness is trivially possible to achieve here, and this API wouldn't affect that. We were worried about separation if we wanted to make I think consistency of the externalized value is impossible across all web backends, hence I was thinking of declaring it as "unsafe". An alternative naming scheme might be something like |
Great! Thanks @srujzs! Re naming. Another idea is As for the getter, I wonder if we should repurpose |
There is no
I'm also open to not naming this type with a |
Great points! Happy to brainstorm offline. Once we land on something, we should follow up with an update on our docs as well. |
This type exists in 3.4 onwards but isn't a JS type. See dart-lang/sdk#55187 for more details on what the type is.
This type was added as part of dart-lang/sdk#55187 to dart:js_interop for a faster alternative to JSBoxedDartObject, so we should add some documentation on it.
Externalizing some internal discussion on this topic already:
Currently, the way to pass Dart objects to JavaScript involves
JSBoxedDartObject
. Its conversion method,toJSBox
does:externref
first.While this offers a consistent interface on the JavaScript side and avoids mixing Dart objects between runtimes, it does come with downsides:
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:
#55183
#55114
#54925
The text was updated successfully, but these errors were encountered: