mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Fix typed JS interop in DDK
Change-Id: Ic36d5dca3b74cd174b62f917f2f49e0920341c1b Reviewed-on: https://dart-review.googlesource.com/34511 Commit-Queue: Jenny Messerly <jmesserly@google.com> Reviewed-by: Vijay Menon <vsm@google.com>
This commit is contained in:
parent
8d48151e16
commit
6f59d5be74
|
@ -121,7 +121,12 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
allowMultiple: true)
|
||||
..addFlag('source-map', help: 'emit source mapping', defaultsTo: true)
|
||||
..addOption('summary-input-dir', allowMultiple: true)
|
||||
..addOption('custom-app-scheme', defaultsTo: 'org-dartlang-app');
|
||||
..addOption('custom-app-scheme', defaultsTo: 'org-dartlang-app')
|
||||
// Ignore dart2js options that we don't support in DDC.
|
||||
..addFlag('enable-enum', hide: true)
|
||||
..addFlag('experimental-trust-js-interop-type-annotations', hide: true)
|
||||
..addFlag('trust-type-annotations', hide: true)
|
||||
..addFlag('supermixin', hide: true);
|
||||
|
||||
addModuleFormatOptions(argParser, singleOutFile: false);
|
||||
|
||||
|
|
|
@ -4317,9 +4317,6 @@ class ProgramCompiler
|
|||
visitConstructorInvocation(ConstructorInvocation node) {
|
||||
var ctor = node.target;
|
||||
var args = node.arguments;
|
||||
var ctorClass = ctor.enclosingClass;
|
||||
if (_isObjectLiteral(ctorClass)) return _emitObjectLiteral(args);
|
||||
|
||||
JS.Expression emitNew() {
|
||||
return new JS.New(_emitConstructorName(node.constructedType, ctor),
|
||||
_emitArgumentList(args, types: false));
|
||||
|
@ -4332,6 +4329,10 @@ class ProgramCompiler
|
|||
var args = node.arguments;
|
||||
var ctor = node.target;
|
||||
var ctorClass = ctor.enclosingClass;
|
||||
if (ctor.isExternal && _isJSNative(ctorClass)) {
|
||||
return _emitJSInteropNew(ctor, args);
|
||||
}
|
||||
|
||||
var type = ctorClass.typeParameters.isEmpty
|
||||
? ctorClass.rawType
|
||||
: new InterfaceType(ctorClass, args.types);
|
||||
|
@ -4396,7 +4397,6 @@ class ProgramCompiler
|
|||
}
|
||||
|
||||
JS.Expression emitNew() {
|
||||
// Native factory constructors are JS constructors - use new here.
|
||||
return new JS.Call(_emitConstructorName(type, ctor),
|
||||
_emitArgumentList(args, types: false));
|
||||
}
|
||||
|
@ -4404,6 +4404,13 @@ class ProgramCompiler
|
|||
return node.isConst ? _emitConst(emitNew) : emitNew();
|
||||
}
|
||||
|
||||
JS.Expression _emitJSInteropNew(Member ctor, Arguments args) {
|
||||
var ctorClass = ctor.enclosingClass;
|
||||
if (_isObjectLiteral(ctorClass)) return _emitObjectLiteral(args);
|
||||
return new JS.New(_emitConstructorName(ctorClass.rawType, ctor),
|
||||
_emitArgumentList(args, types: false));
|
||||
}
|
||||
|
||||
JS.Expression _emitMapImplType(InterfaceType type, {bool identity}) {
|
||||
var typeArgs = type.typeArguments;
|
||||
if (typeArgs.isEmpty) return _emitType(type);
|
||||
|
@ -4421,11 +4428,10 @@ class ProgramCompiler
|
|||
}
|
||||
|
||||
bool _isObjectLiteral(Class c) {
|
||||
return _isJSNative(c) && findAnnotation(c, isJSAnonymousAnnotation) != null;
|
||||
return _isJSNative(c) && c.annotations.any(isJSAnonymousAnnotation);
|
||||
}
|
||||
|
||||
bool _isJSNative(NamedNode c) =>
|
||||
findAnnotation(c, isPublicJSAnnotation) != null;
|
||||
bool _isJSNative(Class c) => c.annotations.any(isPublicJSAnnotation);
|
||||
|
||||
JS.Expression _emitObjectLiteral(Arguments node) {
|
||||
var args = _emitArgumentList(node);
|
||||
|
|
|
@ -10,19 +10,23 @@ import 'kernel_helpers.dart';
|
|||
bool _isJSLibrary(Library library) {
|
||||
if (library == null) return false;
|
||||
var uri = library.importUri;
|
||||
if (uri.scheme == 'package' && uri.path.startsWith('js/')) return true;
|
||||
if (uri.scheme == 'dart') {
|
||||
return uri.path == '_js_helper' || uri.path == '_foreign_helper';
|
||||
}
|
||||
return false;
|
||||
var scheme = uri.scheme;
|
||||
return scheme == 'package' && uri.pathSegments[0] == 'js' ||
|
||||
scheme == 'dart' &&
|
||||
(uri.path == '_js_helper' || uri.path == '_foreign_helper');
|
||||
}
|
||||
|
||||
bool _annotationIsFromJSLibrary(String expectedName, Expression value) {
|
||||
Class c;
|
||||
if (value is ConstructorInvocation) {
|
||||
var c = value.target.enclosingClass;
|
||||
return c.name == expectedName && _isJSLibrary(getLibrary(c));
|
||||
c = value.target.enclosingClass;
|
||||
} else if (value is StaticGet) {
|
||||
var type = value.target.getterType;
|
||||
if (type is InterfaceType) c = type.classNode;
|
||||
}
|
||||
return false;
|
||||
return c != null &&
|
||||
c.name == expectedName &&
|
||||
_isJSLibrary(c.enclosingLibrary);
|
||||
}
|
||||
|
||||
/// Whether [value] is a `@rest` annotation (to be used on function parameters
|
||||
|
|
|
@ -109,7 +109,7 @@ bool isBuiltinAnnotation(
|
|||
String getAnnotationName(NamedNode node, bool test(Expression value)) {
|
||||
var match = findAnnotation(node, test);
|
||||
if (match is ConstructorInvocation && match.arguments.positional.isNotEmpty) {
|
||||
var first = match.arguments.positional[0];
|
||||
var first = _followConstFields(match.arguments.positional[0]);
|
||||
if (first is StringLiteral) {
|
||||
return first.value;
|
||||
}
|
||||
|
@ -117,6 +117,16 @@ String getAnnotationName(NamedNode node, bool test(Expression value)) {
|
|||
return null;
|
||||
}
|
||||
|
||||
Expression _followConstFields(Expression expr) {
|
||||
if (expr is StaticGet) {
|
||||
var target = expr.target;
|
||||
if (target is Field) {
|
||||
return _followConstFields(target.initializer);
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
/// Finds constant expressions as defined in Dart language spec 4th ed,
|
||||
/// 16.1 Constants
|
||||
class ConstantVisitor extends ExpressionVisitor<bool> {
|
||||
|
|
|
@ -125,16 +125,6 @@ abstract_syntax_test/00: MissingCompileTimeError
|
|||
additional_interface_adds_optional_args_concrete_subclass_test: MissingCompileTimeError
|
||||
additional_interface_adds_optional_args_concrete_test: MissingCompileTimeError
|
||||
additional_interface_adds_optional_args_supercall_test: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc01: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc02: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc03: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc05: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc06: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc07: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc08: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc09: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc10: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/cc11: MissingCompileTimeError
|
||||
assertion_initializer_test: CompileTimeError
|
||||
async_await_syntax_test/c10a: MissingCompileTimeError
|
||||
async_await_syntax_test/d08b: MissingCompileTimeError
|
||||
|
@ -479,49 +469,22 @@ mixin_invalid_bound_test/09: MissingCompileTimeError
|
|||
mixin_invalid_bound_test/10: MissingCompileTimeError
|
||||
mixin_lib_extends_field_test: Crash
|
||||
mixin_lib_extends_method_test: Crash
|
||||
mixin_of_mixin_test/01: Crash
|
||||
mixin_of_mixin_test/02: Crash
|
||||
mixin_of_mixin_test/03: Crash
|
||||
mixin_of_mixin_test/04: Crash
|
||||
mixin_of_mixin_test/05: Crash
|
||||
mixin_of_mixin_test/06: Crash
|
||||
mixin_of_mixin_test/none: Crash
|
||||
mixin_super_2_test/01: Crash
|
||||
mixin_super_2_test/02: Crash
|
||||
mixin_super_2_test/03: Crash
|
||||
mixin_super_2_test/04: Crash
|
||||
mixin_super_2_test/none: Crash
|
||||
mixin_of_mixin_test/01: MissingCompileTimeError
|
||||
mixin_of_mixin_test/02: MissingCompileTimeError
|
||||
mixin_of_mixin_test/03: MissingCompileTimeError
|
||||
mixin_of_mixin_test/04: MissingCompileTimeError
|
||||
mixin_of_mixin_test/05: MissingCompileTimeError
|
||||
mixin_of_mixin_test/06: MissingCompileTimeError
|
||||
mixin_super_2_test/01: MissingCompileTimeError
|
||||
mixin_super_2_test/03: MissingCompileTimeError
|
||||
mixin_super_bound_test/01: MissingCompileTimeError
|
||||
mixin_super_bound_test/02: MissingCompileTimeError
|
||||
mixin_super_constructor_named_test/01: MissingCompileTimeError
|
||||
mixin_super_constructor_positionals_test/01: MissingCompileTimeError
|
||||
mixin_super_test: Crash
|
||||
mixin_super_use_test: Crash
|
||||
mixin_superclass_test: Crash
|
||||
mixin_supertype_subclass2_test/01: Crash
|
||||
mixin_supertype_subclass2_test/02: Crash
|
||||
mixin_supertype_subclass2_test/03: Crash
|
||||
mixin_supertype_subclass2_test/04: Crash
|
||||
mixin_supertype_subclass2_test/05: Crash
|
||||
mixin_supertype_subclass2_test/none: Crash
|
||||
mixin_supertype_subclass3_test/01: Crash
|
||||
mixin_supertype_subclass3_test/02: Crash
|
||||
mixin_supertype_subclass3_test/03: Crash
|
||||
mixin_supertype_subclass3_test/04: Crash
|
||||
mixin_supertype_subclass3_test/05: Crash
|
||||
mixin_supertype_subclass3_test/none: Crash
|
||||
mixin_supertype_subclass4_test/01: Crash
|
||||
mixin_supertype_subclass4_test/02: Crash
|
||||
mixin_supertype_subclass4_test/03: Crash
|
||||
mixin_supertype_subclass4_test/04: Crash
|
||||
mixin_supertype_subclass4_test/05: Crash
|
||||
mixin_supertype_subclass4_test/none: Crash
|
||||
mixin_supertype_subclass_test/01: Crash
|
||||
mixin_supertype_subclass_test/02: Crash
|
||||
mixin_supertype_subclass_test/03: Crash
|
||||
mixin_supertype_subclass_test/04: Crash
|
||||
mixin_supertype_subclass_test/05: Crash
|
||||
mixin_supertype_subclass_test/none: Crash
|
||||
mixin_super_test: RuntimeError
|
||||
mixin_super_use_test: RuntimeError
|
||||
mixin_supertype_subclass_test/02: MissingCompileTimeError
|
||||
mixin_supertype_subclass_test/05: MissingCompileTimeError
|
||||
mixin_type_parameters_errors_test/01: MissingCompileTimeError
|
||||
mixin_type_parameters_errors_test/02: MissingCompileTimeError
|
||||
mixin_type_parameters_errors_test/03: MissingCompileTimeError
|
||||
|
@ -785,6 +748,13 @@ syncstar_yield_test/copyParameters: RuntimeError # Expect.equals(expected: <2>,
|
|||
type_literal_test: RuntimeError # Expect.equals(expected: <Func>, actual: <(bool) => int>) fails.
|
||||
instantiate_tearoff_test: RuntimeError
|
||||
|
||||
[ $compiler == dartdevk && $checked ]
|
||||
assertion_initializer_const_error2_test/*: MissingCompileTimeError
|
||||
assertion_initializer_const_error2_test/none: Pass
|
||||
|
||||
[ $compiler == dartdevk && !$checked ]
|
||||
assertion_initializer_const_error2_test/*: SkipByDesign # DDC does not support non-checked mode.
|
||||
|
||||
# Compiler tests for dartdevc and dartdevk. These contain common expectations
|
||||
# for all runtimes including $runtime == none. They are organized by: shared
|
||||
# expectations for dartdevc and dartdevk, then expectations for dartdevc, and
|
||||
|
@ -998,3 +968,4 @@ void_type_usage_test/setter_assign: CompileTimeError # Issue 30514
|
|||
[ $compiler == dartdevk || $compiler == dartdevc && $runtime == none ]
|
||||
instantiate_type_variable_test/01: CompileTimeError
|
||||
setter_no_getter_call_test/01: CompileTimeError
|
||||
|
||||
|
|
|
@ -19,20 +19,6 @@ convert/chunked_conversion_utf87_test: RuntimeError
|
|||
convert/codec1_test: RuntimeError
|
||||
convert/utf82_test: RuntimeError
|
||||
html/debugger_test: CompileTimeError
|
||||
html/js_typed_interop_anonymous2_exp_test: Crash
|
||||
html/js_typed_interop_anonymous2_test: RuntimeError
|
||||
html/js_typed_interop_anonymous_exp_test: Crash
|
||||
html/js_typed_interop_anonymous_test: RuntimeError
|
||||
html/js_typed_interop_anonymous_unreachable_exp_test: Crash
|
||||
html/js_typed_interop_dynamic_test: RuntimeError
|
||||
html/js_typed_interop_lazy_test/01: RuntimeError
|
||||
html/js_typed_interop_lazy_test/none: RuntimeError
|
||||
html/js_typed_interop_side_cast_exp_test/01: Crash
|
||||
html/js_typed_interop_side_cast_exp_test/none: Crash
|
||||
html/js_typed_interop_side_cast_test: RuntimeError
|
||||
html/js_typed_interop_test: RuntimeError
|
||||
html/js_typed_interop_type2_test/01: RuntimeError
|
||||
html/js_typed_interop_type2_test/none: RuntimeError
|
||||
js/prototype_access_test: RuntimeError
|
||||
|
||||
[ $runtime == chrome && ($compiler == dartdevc || $compiler == dartdevk) ]
|
||||
|
|
Loading…
Reference in a new issue