-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS interop makes non-breaking JS changes break Dart code #48186
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
Comments
@srujzs - in thinking about the other issue (high-order conversions with ExternalDartObjectReference in function parameters), I realized that a similar idea would be helpful to address this issue. That is: to switch from a single generic allow-interop implementation, to mutliple specialized implementations depending on the static type of the argument to allow interop. Those specialized implementations would no longer need to use |
Oh I briefly mentioned this in the other issue (#55342) before I saw this, but I agree. :) |
…n.toDart Lowers these extension methods to some helper functions instead of allowInterop to improve performance and get consistent semantics. Specifically: - Function.toJS no longer gives you the same JSFunction when calling toJS on the same function multiple times in the JS compilers. - Adds fast calling syntax for functions with 0-5 args in the JS compilers. - Allows additional args to be passed to converted functions that are omitted in the JS compilers. - The static type now determines the number of args that can be passed to the JS function in the JS compilers. - Fixes an issue in dart2wasm where if too few arguments are passed, the call may succeed due to conversion of undefined to null. - Adds throws when a user tries to wrap a JS function that returned from Function.toJS in the JS compilers. Closes #55515 Addresses #48186 CoreLibraryReviewExempt: Changes to docs only in API surface. Change-Id: I41d864dc5e02b597d9f1c16c88e3c04872f28225 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368065 Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
FYI @nex3 - this has landed with |
In JS, it's legal to pass more arguments to a function than that function declares. For example,
(() => {})(1)
is valid code. In Dart this is not legal, and(() {})(1)
will produce an error.The issue comes when passing Dart functions to JS. Despite needing to wrap the JS functions in
allowInterop()
, Dart doesn't actually allow them to take multiple arguments. This violates JS libraries' assumptions about what changes are non-breaking, and leads to real-world breakages such as sass/dart-sass#1625.The text was updated successfully, but these errors were encountered: