mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
113ff6c993
Fixes #39074 DDC emits Dart code that can usually be called with the same semantics as JS there is no guarantee that a function passed to JS and then invoked successfully was wrapped with `allowInterop`. The wrapping is always required in Dart2JS. To make DDC more strict, add interceptors that check for the usage of `allowInterop`. Whenever a JS interop function or setter is passed an argument which is statically typed as a Function, but not wrapped with `allowInterop` at the call site, wrap it with `assertInterop` which will check the argument at call time and fail with a clear error if it was not wrapped. Whenever a JS interop function is torn off, either at the top level or from an instance, wrap it with a function that will also inject these checks at runtime. There are still holes where we can't catch the mistake: - An argument which is statically dynamic and a Function at runtime won't be caught. - A Function which is stored in a collection won't be caught. - A JS interop definition where a getter returns a Function which takes a Function as an argument is not checked. - A dynamic call through to javascript is not checked. Changes: - Refactor `_isJsLibrary` and add `isJsMember`, and `isAllowInterop` utilities to determine what needs wrapping. - Update `assertInterop` to give a more clear error when it fails, and to ignore non function arguments. - Add `tearoffInterop` to wrap a function an ensure that any function typed arguments are wrapped. - Inject `assertInterop` around Function arguments passed to JS methods. - Inject `assertInterop` around Function arguments passed to static or instance JS setters. - Inject a runtime wrapper around static or instance Function tearoffs. - Add a test covering all flavors of checks that are supported. - Change the interop expando to an `Expando<dynamic>` in the NNBD SDK to work around a stricter type check. https://github.com/dart-lang/sdk/issues/39971 Potential improvements: If the `tearoffInterop` turns out to be too heavy, we could loosen it so that we only wrap methods if any of their argument types are statically declared to be a Function. Change-Id: Ibc92df5b54e1a041b4102a07b8398b774b6bd1d2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128462 Commit-Queue: Nate Bosch <nbosch@google.com> Reviewed-by: Vijay Menon <vsm@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> |
||
---|---|---|
.. | ||
bin | ||
lib | ||
api_readme.md | ||
BUILD.gn |