dart-sdk/tests
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
..
angular
co19 [co19] Handle builders using co19 with test selectors 2019-12-17 17:24:09 +00:00
co19_2 [co19] Roll co19_2 and add co19 (nnbd) to DEPS. 2019-11-26 17:10:18 +00:00
compiler Enforce that allowInterop is used in DDC 2020-01-02 20:24:26 +00:00
corelib Migrate corelib_2/regexp files to NNBD. 2019-12-18 16:16:51 +00:00
corelib_2 Track files that do not need to be migrated in the NNBD progress script. 2019-12-20 21:25:35 +00:00
dart
ffi [vm] Fix IntConverter canonicalization 2020-01-02 12:43:36 +00:00
kernel Remove the old "preview Dart 2" flags from the test runner. 2019-09-05 16:59:43 +00:00
language [testing] Fill out equality_test 2019-12-20 20:18:54 +00:00
language_2 Extract error reporting from TypeNameResolver. 2020-01-01 22:29:05 +00:00
lib Migrate lib_2/js to NNBD. 2019-12-17 20:28:14 +00:00
lib_2 [ VM / dart:typed_data ] Fixed more cases where null was a valid parameter for typed data functions in AOT 2019-12-27 20:04:35 +00:00
modular [dartdevc] Cleanup all temporary nnbd modular tests 2019-12-18 00:43:44 +00:00
search
standalone Delete standalone_2/io/process_exit_negative_test.dart. 2019-11-19 18:23:30 +00:00
standalone_2 [vm/io] add endian.host to RawSocketOption.fromInt 2019-12-30 09:34:18 +00:00
legacy_status_dart2js.csv [infra] Remove non-essential test expectations with comments from general status files 2019-10-01 06:18:59 +00:00
light_unittest.dart
README.md Update tests/README to point to new doc. 2019-08-06 22:19:42 +00:00

This directory contains tests of the language and core library implementations. For more information, see https://github.com/dart-lang/sdk/wiki/Testing.