-
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
[web/interop] New JS interop extensions that provide jsify()
/ dartify()
#55222
Comments
I think the ability to call
We should double-check our tests to make sure we have good coverage here. Are you seeing this discrepancy even in the allowed types or just the disallowed types (arbitrary Dart objects)?
I believe beyond the
Yes, at least for
I can see this adding overhead if it's a large map. We could make this a named parameter e.g.
We could speed-up the current
Can you specify what you mean by "wrapped user objects" and what "" here is?
Reading through the other thread, would the user ever want to lose precision here? Should we always throw? Or is checking whether we'd lose precision slow? |
I meant the discrepancy of instances of user-defined classes. We do have the number discrepancy as well, where in wasm one always gets
Even if one gets the What I meant here is: If we have building blocks, we could have the extension e.g. in
Objects of user-defined classes (like You mentioned this is unintentional in the first place (👍 ) and we should throw. If users need it for some esoteric use case, they can write their own recursive code for that (if we have the building blocks)
We'd need to benchmark to see the impact. Seems to be also somewhat inconsistent atm for the explicit operations
|
Got it, disallowing user-defined classes should get us just to just the
This is a fair point. I have seen users leaning towards these functions and unintentionally introduing overhead, whereas if they knew the type or set of types the value could be, the conversion would be faster. If we added the conversion functions for
Agreed.
I think this is just oversight. The JS compilers don't have the same issue around losing precision, and the conversion to int case is much more common than losing precision. I presume the cost isn't high as the bottleneck will be the interop, but benchmarking makes sense. |
There's also one other discrepancy I noticed here we should fix:
|
Not sure if this is the right place - but I found that |
@curt-weber I'm assuming this is the same issue as #55203? If so, then yes, it's still a bug we need to fix to get consistency. :) |
Yep - good find, same issue as the commenter even - wrapper around indexeddb. |
One more discrepancy here that came up in flutter/flutter#153742:
The idea is to return some interoperable value that users can use, but may lead to issues like flutter/flutter#153742 (comment) where casts may succeed in one compiler but fail in the other. invalid_runtime_check_with_js_interop_types detects erroneous casts, but the result of |
Currently the
dart:js_interop
provides ajsify()
method that is described as this:=> Based on this description it would seem one can only use
.jsify()
for things that can be encoded as json (i.e. maps, lists and primitives (including e.g. typed arrays))But the implementation allows using arbitrary objects:
On top of that, it behaves differently on dart2js vs dart2wasm:
So I think we have to address at least those two aspects:
IMHO it would make sense to rethink the API itself:
jsify()
/dartify()
is <X>
/instance of <X>
calls)?postMessage(<obj>.jsify())
may fail in dart2wasm and do strange things in dart2js))int64
should be converted toint64
or not (see e.g. [bug wasm/js] jsify/dartify issue converting a simple int #55203)/cc @srujzs @sigmundch
The text was updated successfully, but these errors were encountered: