![]() 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> |
||
---|---|---|
.github | ||
benchmarks | ||
build | ||
client | ||
docs | ||
pkg | ||
runtime | ||
samples | ||
samples-dev | ||
sdk | ||
sdk_nnbd | ||
tests | ||
third_party | ||
tools | ||
utils | ||
.clang-format | ||
.gitattributes | ||
.gitconfig | ||
.gitignore | ||
.gn | ||
.mailmap | ||
.packages | ||
.style.yapf | ||
.vpython | ||
AUTHORS | ||
BUILD.gn | ||
CHANGELOG.md | ||
codereview.settings | ||
CONTRIBUTING.md | ||
DEPS | ||
LICENSE | ||
PATENT_GRANT | ||
PRESUBMIT.py | ||
README.dart-sdk | ||
README.md | ||
sdk_args.gni | ||
WATCHLISTS |
Dart
A client-optimized language for fast apps on any platform
Dart is:
-
Optimized for UI: Develop with a programming language specialized around the needs of user interface creation
-
Productive: Make changes iteratively: use hot reload to see the result instantly in your running app
-
Fast on all platforms: Compile to ARM & x64 machine code for mobile, desktop, and backend. Or compile to JavaScript for the web
Dart has flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:
-
Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code.
-
Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).
License & patents
Dart is free and open source.
See LICENSE and PATENT_GRANT.
Using Dart
Visit the dart.dev to learn more about the language, tools, getting started, and more.
Browse pub.dev for more packages and libraries contributed by the community and the Dart team.
Building Dart
If you want to build Dart yourself, here is a guide to getting the source, preparing your machine to build the SDK, and building.
There are more documents on our wiki.
Contributing to Dart
The easiest way to contribute to Dart is to file issues.
You can also contribute patches, as described in Contributing.