Find a file
Nate Bosch 113ff6c993 Enforce that allowInterop is used in DDC
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>
2020-01-02 20:24:26 +00:00
.github Update new issue template. 2019-04-30 18:14:21 +00:00
benchmarks Added SoundSplayTreeSieve benchmark for variantly sound interfaces. 2019-12-20 23:54:15 +00:00
build [vm] Enable Dart VM to run in QEMU user-mode emulation for ARM. 2019-11-18 16:58:53 +00:00
client
docs Remove dartLangSpec.tex; current version is in language repo 2019-12-19 08:57:10 +00:00
pkg Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
runtime [vm/compiler] Remove PushArguments from ThrowInstr, ReThrowInstr 2020-01-02 19:41:46 +00:00
samples [samples/ffi] Native resource lifetime management 2019-12-12 10:27:22 +00:00
samples-dev Mass format python with yapf 2019-08-05 20:34:31 +00:00
sdk Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
sdk_nnbd Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
tests Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
third_party [vm] Remove deprecated (and untested) ARMv5 support from the VM 2019-10-23 14:44:33 +00:00
tools [infra] Add unapproved failures test to builder status script 2019-12-30 14:02:23 +00:00
utils [SDK/BUILD] Pass --enable-experiment=non-nullable to the gen_kernel when it is used to compile the sdk tools. 2019-12-14 01:04:45 +00:00
.clang-format
.gitattributes Move files under language_2 into subdirectories. 2019-12-11 19:18:00 +00:00
.gitconfig
.gitignore Reland "[llvm] Add initial scaffolding" 2019-07-30 20:34:31 +00:00
.gn
.mailmap fix my name in .mailmap 2018-09-11 01:45:52 +00:00
.packages Create a package to hold code shared between front_end and analyzer. 2019-10-31 13:05:53 +00:00
.style.yapf Mass format python with yapf 2019-08-05 20:34:31 +00:00
.vpython [infra] Add .vpython spec to fix gsutil on the bots (#31065) 2018-10-11 15:11:35 +00:00
AUTHORS [runtime/vm] ARM64: Support unaligned memory accesses for regex. 2019-10-15 20:11:40 +00:00
BUILD.gn Add a script and target to run dartfix 2019-10-14 15:50:21 +00:00
CHANGELOG.md Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
codereview.settings
CONTRIBUTING.md Change wiki link to follow contents moved. 2019-01-12 18:46:22 +00:00
DEPS [co19] Roll co19 to 9e3512c90f9110353909a0da71a871e33324034e 2019-12-18 10:15:09 +00:00
LICENSE Remove third_party licenses from LICENSE 2019-08-21 07:43:34 +00:00
PATENT_GRANT Rename patent file 2019-08-16 12:03:17 +00:00
PRESUBMIT.py [VM/runtime] Remove support for loading URLs through service isolate 2019-12-27 17:30:05 +00:00
README.dart-sdk
README.md Update README.md 2019-08-16 12:24:02 +00:00
sdk_args.gni Support building under git-worktree 2019-12-19 23:12:53 +00:00
WATCHLISTS Auto-CC dart2js on changes to the js_runtime sdk. 2019-09-12 18:17:38 +00:00

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).

Dart platforms illustration

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.