Make dart2js_extra and dart2js_native run in dart2js-strong

Change-Id: I48cf6f40eea4509e415930c05addb2d48d413be9
Reviewed-on: https://dart-review.googlesource.com/63264
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Sigmund Cherem
2018-06-29 19:33:20 +00:00
committed by commit-bot@chromium.org
parent 6f965a94e2
commit a2cca0ad2b
105 changed files with 177 additions and 1994 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ class I8 extends TD with M implements JSIB {}
use(x) {
if (x is JSIB) {
// Should be able to find M.foo since I8 is a subtype of both JSIB and M.
Expect.equals(123, x.foo());
Expect.equals(123, (x as dynamic).foo());
}
}
+5 -13
View File
@@ -21,20 +21,12 @@ class A {
invocation.positionalArguments, invocation.namedArguments);
}
}
init() {
closure_fails = (String str) {
return str.toUpperCase();
};
}
run() {
print(closure_fails("Hello World"));
}
}
void main() {
var a = new A();
a.init();
a.run();
dynamic a = new A();
a.closure_fails = (String str) {
return str.toUpperCase();
};
print(a.closure_fails("Hello World"));
}
@@ -1,24 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for http://dartbug.com/21166/
// Fails when compiling with --checked.
var a = [];
void doStuff() {
if (a.length) {
// This triggers a TypeConversion to bool in checked mode.
var element = a[0]; // This triggers a bounds check but a.length will have
a.remove(element); // type [empty].
}
}
main() {
a.add(1);
a.add(2);
try {
doStuff(); // This is expected to fail but not crash the compiler.
} catch (_) {}
}
@@ -1,90 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for issue 21666 - problems with method that has super calls.
//
// Use a method and getter with super calls in various ways.
import 'package:expect/expect.dart';
@MirrorsUsed(targets: const [A, B, Object])
import 'dart:mirrors';
class X {
const X();
}
class Y {
const Y();
}
typedef fInt(int x);
typedef fString(String x);
class A {
@X()
foo(int x) => x + 1;
int get bar => A.g;
static int g = 0;
}
class B extends A {
@Y()
foo(int x) => 100 * super.foo(x);
int get bar => 1000 * super.bar;
}
String dump(ClassMirror cm) {
var sb = new StringBuffer();
sb.write('$cm\n');
for (var mm in cm.declarations.values) {
sb.write(' $mm\n');
// Walking declaration metadata triggers issue 21666.
for (var a in mm.metadata) {
sb.write(' $a\n');
}
}
print(sb);
return '$sb';
}
main() {
var cmB = reflectClass(B);
var cmBdump = dump(cmB);
var cmAdump = dump(cmB.superclass);
Expect.equals(dump(reflectClass(A)), cmAdump);
Expect.isTrue(cmAdump.contains("'foo'"));
Expect.isTrue(cmAdump.contains("'bar'"));
Expect.isTrue(cmBdump.contains("'foo'"));
Expect.isTrue(cmBdump.contains("'bar'"));
A.g = 123;
var a = new A();
var am = reflect(a);
var agfoo = am.getField(#foo);
var agbar = am.getField(#bar);
Expect.equals(3, agfoo.reflectee(2));
Expect.equals(4, am.invoke(#foo, [3]).reflectee);
Expect.equals(123, agbar.reflectee);
Expect.isTrue(a.foo is fInt);
Expect.isTrue(a.foo is! fString);
Expect.isTrue(agfoo.reflectee is fInt);
Expect.isTrue(agfoo.reflectee is! fString);
var b = new B();
var bm = reflect(b);
var bgfoo = bm.getField(#foo);
var bgbar = bm.getField(#bar);
Expect.equals(300, bgfoo.reflectee(2));
Expect.equals(400, bm.invoke(#foo, [3]).reflectee);
Expect.equals(123000, bgbar.reflectee);
Expect.isTrue(b.foo is fInt);
Expect.isTrue(b.foo is! fString);
Expect.isTrue(bgfoo.reflectee is fInt);
Expect.isTrue(bgfoo.reflectee is! fString);
}
@@ -1,12 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for issue 21724 - invalid call to local closure
main() {
foo(x) {}
try {
foo();
} catch (_) {}
}
@@ -1,30 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for http://dartbug.com/23056/
// Ensure that Mixin prototypes are initialized before first use.
// Mirrors is the only way to have a getter be equipped with metadata.
@MirrorsUsed(targets: 'M', override: '*')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class M {
@NoInline()
bool get foo => true;
}
class A extends Object with M {
@NoInline()
bool get foo => super.foo;
}
@AssumeDynamic()
@NoInline()
bool hide(bool x) => x;
main() {
Expect.isTrue((hide(true) ? new A() : new M()).foo);
}
+1 -1
View File
@@ -20,7 +20,7 @@ class N {
get NEVER => false;
main() {
var c = 12345;
dynamic c = 12345;
if (NEVER) c = new N();
var e;
try {
+1 -1
View File
@@ -9,7 +9,7 @@
import 'package:expect/expect.dart';
test(n) => n == 1;
run(f) => f(1);
bool run(f(dynamic)) => f(1);
main() {
Expect.equals([test].any(run), true);
}
+2 -2
View File
@@ -21,8 +21,8 @@ class C<T> {
confuse(x) => x;
main() {
var c = new C();
var a = 12;
dynamic c = new C();
dynamic a = 12;
if (confuse(true)) a = {};
c.f = a;
}
+4 -2
View File
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// dart2jsOptions=--strong
// Regression test for http://dartbug.com/28749.
//
// This would crash at compile time because inner typedefs remain after calling
@@ -47,11 +49,11 @@ void main() {
);
Expect.equals(
'Wrap<(int) => ((dynamic) => void) => (dynamic) => void>',
'Wrap<(int) => ((int) => void) => (int) => void>',
'${foo<int>(0)}',
);
Expect.equals(
'Wrap<(int) => ((dynamic) => void) => (dynamic) => void>',
'Wrap<(int) => ((String) => void) => (String) => void>',
'${foo<String>(1)}',
);
}
@@ -26,23 +26,11 @@ test1() {
}
test2() {
testFalse('constant function', () {
assert(() => false, 'Mumble');
});
}
test3() {
testFalse('variable false', () {
assert(confuse(false), 'Mumble');
});
}
test4() {
testFalse('variable function', () {
assert(confuse(() => false), 'Mumble');
});
}
testTypeErrors() {
check(name, fault) {
try {
@@ -101,19 +89,17 @@ testMessageEffect3() {
Expect.fail('Expected assert to throw');
}
bool get checkedMode {
bool get assertionsEnabled {
bool b = false;
assert((b = true));
return b;
}
main() {
if (!checkedMode) return;
if (!assertionsEnabled) return;
test1();
test2();
test3();
test4();
testTypeErrors();
testMessageEffect1();
testMessageEffect2();
@@ -26,7 +26,7 @@ class Tracer {
}
}
test1(Tracer tracer) {
Future test1(Tracer tracer) {
foo() async*
/// asyncStar: ok
@@ -56,7 +56,7 @@ test1(Tracer tracer) {
;
}
test2(Tracer tracer) {
Future test2(Tracer tracer) {
var savedStackTrace;
foo() async*
@@ -83,7 +83,7 @@ test2(Tracer tracer) {
});
}
test3(Tracer tracer) {
Future test3(Tracer tracer) {
var savedStackTrace;
foo() async*
@@ -1,24 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class A {}
class SubA extends A {}
class B {}
void main() {
A a;
SubA subA;
B b;
a = a;
a = subA;
a = b; //# 01: static type warning
subA = a;
subA = subA;
subA = b; //# 02: static type warning
b = a; //# 03: static type warning
b = subA; //# 04: static type warning
b = b;
}
@@ -1,25 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
class E {
missingType field;
}
class WithGetter {
String field;
}
void main() {
f(x) {
x.field = true;
}
Expect.throws(() {
[new E(), new WithGetter()].forEach(f);
new missingType();
new E().field = 'a string';
});
}
@@ -1,22 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that classes referenced from a signature of a tear-off closure
// are emitted.
@MirrorsUsed(targets: 'C')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A {}
class C {
A foo() {}
}
main() {
Expect.isFalse(
reflect(new C().foo).function.returnType.toString().contains('dynamic'));
}
@@ -1,22 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that classes referenced from a signature of a tear-off closure
// are emitted.
@MirrorsUsed(targets: 'C', symbols: 'A')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A {}
class C {
A foo() {}
}
main() {
Expect.equals("ClassMirror on 'A'",
reflect(new C().foo).function.returnType.toString());
}
@@ -126,21 +126,8 @@ class IntPlusString {
return (confuse(1) as int) + confuse('a');
}
static f5() {
return (confuse(1) as int) + 'a';
}
static f6() {
var a = confuse(true) ? 1 : 2; // Small int with unknown value.
return a + 'a';
}
static f7() {
return 1 + 'a';
}
static test() {
check('IntPlusString', f1, f2, f3, f4, f5, f6, f7);
check('IntPlusString', f1, f2, f3, f4);
}
}
@@ -158,25 +145,12 @@ class StringPlusInt {
}
static f4() {
return (confuse('a') as String) + 1;
}
static f5() {
var a = confuse(true) ? 'a' : 'bc';
return a + confuse(1);
}
static f6() {
var a = confuse(true) ? 'a' : 'bc';
return a + 1;
}
static f7() {
return 'a' + 1;
}
static test() {
check('StringPlusInt', f1, f2, f3, f4, f5, f6, f7);
check('StringPlusInt', f1, f2, f3, f4);
}
}
@@ -116,7 +116,7 @@ class BadType {
static f3() {
var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
return a.codeUnitAt('a');
return a.codeUnitAt(('a' as dynamic));
}
static test() {
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// dart2jsOptions=--omit-implicit-checks
import "package:expect/expect.dart";
// Test that optimized '-' and slow path '-' produce the same error.
@@ -90,21 +92,8 @@ class IntMinusString {
return (confuse(1) as int) - confuse('a');
}
static f5() {
return (confuse(1) as int) - 'a';
}
static f6() {
var a = confuse(true) ? 1 : 2; // Small int with unknown value.
return a - 'a';
}
static f7() {
return 1 - 'a';
}
static test() {
check('IntMinusString', f1, f2, f3, f4, f5, f6, f7);
check('IntMinusString', f1, f2, f3, f4);
}
}
@@ -8,8 +8,6 @@ bounds_check4b_test: RuntimeError # Issue 32741
class_test: Fail
constant_javascript_semantics4_test: Fail, OK
generic_class_is_test: Fail # Issue 32004
mirror_printer_test: Pass, Slow # Issue 25940, 16473
mirrors_used_closure_test: Fail # Issue 17939
no_such_method_test: Fail # Wrong Invocation.memberName.
statements_test: Fail
typed_locals_test: Pass, Fail
@@ -40,9 +38,6 @@ deferred_split_test: Pass, Slow # Issue 25940
[ $compiler == dart2js && $runtime == chrome && $csp ]
deferred/load_in_correct_order_test: SkipByDesign # Purposely uses `eval`
[ $compiler == dart2js && $runtime == chromeOnAndroid ]
no_such_method_mirrors_test: Pass, Slow # TODO(kasperl): Please triage.
[ $compiler == dart2js && $runtime == d8 && $fasta ]
deferred_fail_and_retry_test: RuntimeError # Uses XHR in dart:html
deferred_with_csp_nonce_test: RuntimeError # Uses dart:html
@@ -54,21 +49,10 @@ consistent_index_error_string_test: Pass, Slow # Issue 25940
[ $compiler == dart2js && $runtime == none ]
*: Fail, Pass # TODO(ahe): Triage these tests.
[ $compiler == dart2js && $checked ]
variable_type_test/01: Fail, OK
variable_type_test/03: Fail, OK
[ $compiler == dart2js && $checked && $fasta ]
deferred/deferred_mirrors1_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/deferred_mirrors2_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/reflect_multiple_annotations_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/reflect_multiple_default_arg_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
dummy_compiler_test: Crash
local_signature_test: Crash
minus_zero_test/01: MissingCompileTimeError
mirrors_used_warning2_test: Crash
mirrors_used_warning_test/minif: Crash
mirrors_used_warning_test/none: Crash
[ $compiler == dart2js && $csp ]
deferred_custom_loader_test: SkipByDesign # Issue 25683
@@ -76,94 +60,18 @@ deferred_fail_and_retry_test: SkipByDesign # Uses eval to simulate failed loadin
js_interop_optional_arg_test: RuntimeError # Issue 31082
js_interop_test: RuntimeError # Issue 31082
[ $compiler == dart2js && $fast_startup ]
21666_test: Fail # mirrors not supported
23056_test: Fail # mirrors not supported
closure_type_reflection2_test: Fail # mirrors not supported
closure_type_reflection_test: Fail # mirrors not supported
deferred/deferred_mirrors1_lib: Fail # mirrors not supported
deferred/deferred_mirrors1_test: Fail # mirrors not supported
deferred/deferred_mirrors2_lazy: Fail # mirrors not supported
deferred/deferred_mirrors2_lib3: Fail # mirrors not supported
deferred/deferred_mirrors2_test: Fail # mirrors not supported
deferred/reflect_multiple_annotations_test: CompileTimeError # mirrors not supported
deferred/reflect_multiple_default_arg_test: CompileTimeError # mirrors not supported
inference_nsm_mirrors_test: Fail # mirrors not supported
invalid_annotation2_test/01: Pass # mirrors not supported, passes for the wrong reason
invalid_annotation2_test/none: Fail # mirrors not supported
mirror_enqueuer_regression_test: Fail # mirrors not supported
mirror_invalid_field_access2_test: Fail # mirrors not supported
mirror_invalid_field_access3_test: Fail # mirrors not supported
mirror_invalid_field_access4_test: Fail # mirrors not supported
mirror_invalid_field_access_test: Fail # mirrors not supported
mirror_invalid_invoke2_test: Fail # mirrors not supported
mirror_invalid_invoke3_test: Fail # mirrors not supported
mirror_invalid_invoke_test: Fail # mirrors not supported
mirror_printer_test: Fail # mirrors not supported
mirror_test: Fail # mirrors not supported
mirror_type_inference_field2_test: Fail # mirrors not supported
mirror_type_inference_field_test: Fail # mirrors not supported
mirror_type_inference_function_test: Fail # mirrors not supported
mirrors_declarations_filtering_test: Fail # mirrors not supported
mirrors_used_closure_test: SkipByDesign
mirrors_used_metatargets_test: Fail # mirrors not supported
mirrors_used_native_test: Fail # mirrors not supported
mirrors_used_warning2_test: Fail # mirrors not supported
mirrors_used_warning_test: Fail # mirrors not supported
no_such_method_mirrors_test: Fail # mirrors not supported
reflect_native_types_test: Fail # mirrors not supported
[ $compiler == dart2js && $fast_startup && $fasta ]
23056_test: Pass
deferred/deferred_mirrors1_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/deferred_mirrors2_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/reflect_multiple_annotations_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
deferred/reflect_multiple_default_arg_test: Crash # Unsupported operation: KernelDeferredLoadTask.addMirrorElementsForLibrary
mirror_enqueuer_regression_test: Pass
[ $compiler == dart2js && $fasta ]
21666_test: RuntimeError
23264_test: RuntimeError
closure_capture2_test: RuntimeError
closure_type_reflection2_test: RuntimeError
closure_type_reflection_test: RuntimeError
constant_javascript_semantics_test/03: CompileTimeError
constant_javascript_semantics_test/04: CompileTimeError
constant_javascript_semantics_test/none: CompileTimeError
deferred/deferred_mirrors1_test: SkipByDesign
deferred/deferred_mirrors2_test: RuntimeError
deferred/reflect_multiple_annotations_test: RuntimeError
deferred/reflect_multiple_default_arg_test: RuntimeError
inference_nsm_mirrors_test: SkipByDesign
invalid_annotation2_test/none: RuntimeError
mirror_invalid_field_access2_test: RuntimeError
mirror_invalid_field_access3_test: RuntimeError
mirror_invalid_field_access4_test: RuntimeError
mirror_invalid_field_access_test: RuntimeError
mirror_invalid_invoke2_test: RuntimeError
mirror_invalid_invoke3_test: RuntimeError
mirror_invalid_invoke_test: RuntimeError
mirror_printer_test/01: RuntimeError
mirror_printer_test/none: RuntimeError
mirror_test: RuntimeError
mirror_type_inference_field2_test: RuntimeError
mirror_type_inference_field_test: RuntimeError
mirror_type_inference_function_test: RuntimeError
mirrors_declarations_filtering_test: RuntimeError
mirrors_used_closure_test: SkipByDesign
mirrors_used_metatargets_test: RuntimeError
mirrors_used_native_test: RuntimeError
mirrors_used_warning2_test: RuntimeError
mirrors_used_warning_test/minif: RuntimeError
mirrors_used_warning_test/none: RuntimeError
no_such_method_mirrors_test: SkipByDesign
private_symbol_literal_test/01: MissingCompileTimeError
private_symbol_literal_test/02: MissingCompileTimeError
private_symbol_literal_test/03: MissingCompileTimeError
private_symbol_literal_test/04: MissingCompileTimeError
private_symbol_literal_test/05: MissingCompileTimeError
private_symbol_literal_test/06: MissingCompileTimeError
reflect_native_types_test: RuntimeError
regress/4562_test/none: CompileTimeError
round_constant_folding_test: CompileTimeError
type_constant_switch_test/01: MissingCompileTimeError
@@ -198,7 +106,10 @@ extract_type_arguments_3_test: RuntimeError # Uses function type variables
generic_method_dynamic_is_test: RuntimeError # Test against function type variables is only supported in strong mode.
generic_method_dynamic_type_test: SkipByDesign # Requires strong mode support for function type variables.
generic_method_static_is_test: RuntimeError # Test against function type variables is only supported in strong mode.
int_index_test/01: MissingCompileTimeError
int_index_test/02: MissingCompileTimeError
local_signature_test: RuntimeError # Test against function type variables is only supported in strong mode.
switch_test/00: MissingCompileTimeError
[ $compiler == dart2js && ($runtime == chrome || $runtime == chromeOnAndroid || $runtime == drt || $runtime == ff || $runtime == safari) ]
isolate2_test/01: Fail # Issue 14458.
@@ -9,7 +9,7 @@ import 'dart:async';
import 'deferred_class_library.dart' deferred as lib;
isError(e) => e is Error;
bool isError(e) => e is Error;
main() {
var x;
@@ -10,7 +10,7 @@ import 'package:expect/expect.dart';
import 'deferred_function_library.dart' deferred as lib;
isError(e) => e is Error;
bool isError(e) => e is Error;
readFoo() {
return lib.foo;
@@ -1,11 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
import 'dart:mirrors';
foo() {
var m = reflect(499);
return m.reflectee;
}
@@ -1,28 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
@MirrorsUsed(override: '*')
import 'dart:mirrors';
import 'deferred_mirrors1_lib.dart' deferred as lazy;
main() {
asyncStart();
// The deferred library uses mirrors and has an unused import of typed_data.
// Dart2js must not crash on this test.
//
// Dart2js used to crash because:
// - the NativeInt8List was dragged in.
// - but not its constructors and the constructors' dependencies.
// - one of the dependencies (a local function "_ensureNativeList") was
// not handled by the deferred-loader.
lazy.loadLibrary().then((_) {
Expect.equals(499, lazy.foo());
asyncEnd();
});
}
@@ -1,14 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library lazy;
import 'deferred_mirrors2_lib3.dart';
@MirrorsUsed(metaTargets: const [Reflectable], override: 'lazy')
import 'dart:mirrors';
class Reflectable {
const Reflectable();
}
@@ -1,19 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library lib3;
import 'deferred_mirrors2_lib4.dart';
@MirrorsUsed(targets: const ['lib3'])
import 'dart:mirrors';
class R {
void bind(Type type) {
ClassMirror classMirror = _reflectClass(type);
MethodMirror ctor = classMirror.declarations[classMirror.simpleName];
int length = ctor.parameters.length;
Function create = classMirror.newInstance;
}
}
@@ -1,21 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
@MirrorsUsed(override: '*')
import 'dart:mirrors';
import 'deferred_mirrors2_lib2.dart';
foo() {
ClassMirror classMirror = reflectType(int);
Expect.isTrue(classMirror.isTopLevel);
}
// This is a minimal test extracted from a bug-report we got.
main() {
foo();
}
@@ -7,12 +7,8 @@
/// fragments is kept separate, but that when they are loaded (and the metadata
/// array is merged) all accesses to the metadata array is done correctly.
///
/// This kind of metadata is generated either when using Function.apply (to
/// store default values and parameter names) or when using dart:mirrors
/// (annotations and unmangled names also need to be stored).
///
/// This test covers uses of default values and parameter names via
/// Function.apply.
/// This kind of metadata is generated when using Function.apply to
/// store default values and parameter names.
import 'multiple_default_arg_lib1.dart' deferred as lib1;
import 'multiple_default_arg_lib2.dart' deferred as lib2;
import 'multiple_default_arg_lib3.dart' deferred as lib3;
@@ -35,8 +31,8 @@ main() {
await lib3.loadLibrary();
Expect.equals(
Function
.apply(lib3.myFunction3, ["x", "y"], {#argumentName4: () => "C"}),
Function.apply(
lib3.myFunction3, ["x", "y"], {#argumentName4: () => "C"}),
"x y 3b - C");
Expect.equals(
@@ -48,8 +44,8 @@ main() {
lib3.myFunction4, ["x", "y"], {#argumentName5: new lib3.X(4)}),
4);
Expect.equals(
Function
.apply(lib3.myFunction4, ["x", "y"], {#argumentName5: lib3.value3}),
Function.apply(
lib3.myFunction4, ["x", "y"], {#argumentName5: lib3.value3}),
3);
});
}
@@ -1,81 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// This test is indirectly testing invariants of the generated code of dart2js.
/// It ensures that indices to metadata information from **multiple** deferred
/// fragments is kept separate, but that when they are loaded (and the metadata
/// array is merged) all accesses to the metadata array is done correctly.
///
/// This kind of metadata is generated either when using Function.apply (to
/// store default values and parameter names) or when using dart:mirrors
/// (annotations and unmangled names also need to be stored).
///
/// This test file covers uses of annotations through dart:mirrors.
@MirrorsUsed(override: '*')
import 'dart:mirrors';
import 'reflect_multiple_annotations_lib1.dart' deferred as lib1;
import 'reflect_multiple_annotations_lib2.dart' deferred as lib2;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
main() {
asyncTest(() async {
await lib1.loadLibrary();
await lib2.loadLibrary();
MethodMirror m1 =
findTopLevel('multiple_annotations_lib1.dart', #myFunction1);
Expect.equals(m1.metadata.length, 2);
Expect.equals(m1.parameters.length, 1);
Expect.equals(m1.parameters[0].simpleName, #f1);
Expect.isFalse(m1.parameters[0].hasDefaultValue);
Expect.equals(m1.parameters[0].metadata.length, 1);
// Note: currently m1.metadata[*].reflectee is null, even though this works
// when not using deferred libraries.
// TODO(sigmund): fix if we do not move forward with Issue #30538.
//Expect.isTrue(lib1.MetaA.isCheck(m1.metadata[0].reflectee));
//Expect.isTrue(lib1.MetaA.isCheck(m1.metadata[1].reflectee));
//Expect.equals(m1.metadata[0].reflectee.value, "one");
//Expect.equals(m1.metadata[1].reflectee.value, lib1.topLevelF);
//Expect.isTrue(lib1.MetaA.isCheck(m1.parameters[0].metadata[0].reflectee));
//Expect.equals(m1.parameters[0].metadata[0].reflectee.value, "param");
LibraryMirror l2 = findLibrary('multiple_annotations_lib2.dart');
Expect.equals(l2.metadata.length, 1);
print(l2.metadata[0].reflectee);
Expect.equals(l2.metadata[0].reflectee.value, "lib");
ClassMirror c2 = findClass('multiple_annotations_lib2.dart', #A);
Expect.equals(c2.simpleName, #A);
Expect.equals(c2.metadata.length, 1);
print(c2.metadata[0].reflectee);
Expect.equals(c2.metadata[0].reflectee.value, "class");
});
}
MethodMirror findTopLevel(String uriSuffix, Symbol name) {
MethodMirror method;
currentMirrorSystem().libraries.forEach((uri, lib) {
if (uri.path.endsWith(uriSuffix)) method = lib.declarations[name];
});
return method;
}
ClassMirror findClass(String uriSuffix, Symbol name) {
ClassMirror cls;
currentMirrorSystem().libraries.forEach((uri, lib) {
if (uri.path.endsWith(uriSuffix)) cls = lib.declarations[name];
});
return cls;
}
LibraryMirror findLibrary(String uriSuffix) {
LibraryMirror lib;
currentMirrorSystem().libraries.forEach((uri, l) {
if (uri.path.endsWith(uriSuffix)) lib = l;
});
return lib;
}
@@ -1,54 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// This test is indirectly testing invariants of the generated code of dart2js.
/// It ensures that indices to metadata information from **multiple** deferred
/// fragments is kept separate, but that when they are loaded (and the metadata
/// array is merged) all accesses to the metadata array is done correctly.
///
/// This kind of metadata is generated either when using Function.apply (to
/// store default values and parameter names) or when using dart:mirrors
/// (annotations and unmangled names also need to be stored).
///
/// This test file covers uses of parameter names and default values through
/// dart:mirrors.
@MirrorsUsed(override: '*')
import 'dart:mirrors';
import 'reflect_multiple_default_arg_lib1.dart' deferred as lib1;
import 'reflect_multiple_default_arg_lib2.dart' deferred as lib2;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
main() {
asyncTest(() async {
await lib1.loadLibrary();
await lib2.loadLibrary();
Expect.equals(Function.apply(lib1.myFunction1, []), 1);
Expect.equals(Function.apply(lib2.myFunction2, []), 2);
MethodMirror m1 =
findTopLevel('multiple_default_arg_lib1.dart', #myFunction1);
Expect.equals(m1.parameters.length, 1);
Expect.equals(m1.parameters[0].simpleName, #argumentName1);
Expect.isTrue(m1.parameters[0].hasDefaultValue);
Expect.equals((m1.parameters[0].defaultValue.reflectee)(), 1);
MethodMirror m2 =
findTopLevel('multiple_default_arg_lib2.dart', #myFunction2);
Expect.equals(m2.parameters.length, 1);
Expect.equals(m2.parameters[0].simpleName, #argumentName2);
Expect.isTrue(m2.parameters[0].hasDefaultValue);
Expect.equals((m2.parameters[0].defaultValue.reflectee)(), 2);
});
}
MethodMirror findTopLevel(String uriSuffix, Symbol name) {
MethodMirror method;
currentMirrorSystem().libraries.forEach((uri, lib) {
if (uri.path.endsWith(uriSuffix)) method = lib.declarations[name];
});
print(method);
return method;
}
@@ -9,7 +9,7 @@ void main() {
} else {
throw "x != x with x == 3";
}
var y = x;
dynamic y = x;
if (true) {
y = 10;
}
@@ -1,20 +0,0 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Regression test for [ClosureCallSiteTypeInformation] in loops.
class Class<T> {
method() {
for (var a in []) {
(T)(); //# 01: ok
(Object)(); //# 02: ok
(this)(); //# 03: ok
(1)(); //# 04: ok
}
}
}
main() {
new Class().method();
}
@@ -29,8 +29,8 @@ testIterator(List expect, Iterable input) {
class MyIterable<T> extends IterableBase<T> {
final List<T> values;
MyIterable(List<T> values) : this.values = values;
Iterator get iterator {
return new MyListIterator(values);
Iterator<T> get iterator {
return new MyListIterator<T>(values);
}
}
@@ -9,12 +9,12 @@ import "package:expect/expect.dart";
confuse(x) => x;
main(args) {
var x = new A();
dynamic x = new A();
var y;
// Checks that inference doesn't incorrectly treat this as a normal
// assignment (where only B is a possible value after the assignment).
var c = x ??= new B();
dynamic c = x ??= new B();
var z = x;
Expect.equals('a', x.m());
Expect.equals('a', z.m());
@@ -1,29 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for dart2js that did type inferencing on parameters
// whose type may change at runtime due to an invocation through
// [InstanceMirror.delegate].
@MirrorsUsed(targets: 'A')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A {
noSuchMethod(im) {
reflect(new B()).delegate(im);
}
}
class B {
foo(a) => a + 42;
}
main() {
Expect.equals(42, new B().foo(0));
// In checked mode we should get a type error. In unchecked mode it should be
// an argument error.
Expect.throws(
() => new A().foo('foo'), (e) => e is ArgumentError || e is TypeError);
}
@@ -17,7 +17,7 @@ abstract class A {
class S extends A {
var _x; // was bad: inferred as null, than [null | int]
var _y = ''; // was bad: inferred as String, rather than [String | int]
dynamic _y = ''; // was bad: inferred as String, rather than [String | int]
var _z; // was ok : inferred as [null | int]
set x(v) {
@@ -4,9 +4,9 @@
main() {
var a = [0, 1];
a[1.2]; // //# 01: runtime error
a[1.2] = 4; // //# 02: runtime error
checkIndex(a, 1.4); //# 03: runtime error
a[1.2]; // //# 01: compile-time error
a[1.2] = 4; // //# 02: compile-time error
checkIndex(a, 1.4); //# 03: runtime error
checkIndexedAssignment(a, 1.4); //# 04: runtime error
checkIndex(a, 0);
checkIndexedAssignment(a, 0);
@@ -1,23 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for http://dartbug.com/23893/
//
// Because annotations are parsed lazily, dart2js used to crash when an
// annotation had a syntax error.
// This checks the same behavior as invalid_annotation_test.dart, except that we
// use mirrors to trigger the error in the vm. This also triggers the error in
// dart2js differently.
@MirrorsUsed(targets: const [A])
import 'dart:mirrors';
@Deprecated("m"
,, // //# 01: compile-time error
)
class A {}
main() {
reflectClass(A).metadata;
}
@@ -3,9 +3,9 @@
// BSD-style license that can be found in the LICENSE file.
void main() {
var hello = 'Hello';
var world = 'world';
var s = 0;
dynamic hello = 'Hello';
dynamic world = 'world';
dynamic s = 0;
s = world;
hello = 'Greetings';
print("$hello, $world!");
@@ -1,39 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test for locateSingleElement bug.
import 'package:expect/expect.dart';
class T {
foo() => 'T.foo'; // This is the single element.
}
class C implements T {
// There is a warning that C does not implement 'foo'.
}
@NoInline()
@AssumeDynamic()
assumeT(x) {
// returns inferred subtype(T).
if (x is T) return x;
throw "Not T";
}
var log = [];
demo() {
log.add(new T()); // T is created.
var a = assumeT(new C()); // C is created.
// The call "a.foo()" should be a NoSuchMethodError, but a bug in
// locateSingleElement used to lead to T.foo being inlined. There is a single
// method. T.foo, that matches subtype(T), but it should be rejected because
// not all instantiated classes that are subtype(T) have that method.
log.add(a.foo());
}
main() {
Expect.throws(demo);
}
@@ -29,14 +29,14 @@ const ll2 = const [1, 8, 3, 4, 5, 6, 7];
const ll3 = const [1, 2, 8, 4, 5, 6, 7];
const ll4 = const [1, 2, 3, 4, 8, 6, 7];
const m1 = const {1: 1, 2: 2};
const m2 = const {1: 2, 2: 1};
const m3 = const {1: 1, 2: 1};
const m4 = const {1: 2, 2: 2};
const m5 = const {2: 1, 1: 2};
const m6 = const {2: 2, 1: 1};
const m7 = const {2: 1, 1: 1};
const m8 = const {2: 2, 1: 2};
const m1 = const <dynamic, dynamic>{1: 1, 2: 2};
const m2 = const <dynamic, dynamic>{1: 2, 2: 1};
const m3 = const <dynamic, dynamic>{1: 1, 2: 1};
const m4 = const <dynamic, dynamic>{1: 2, 2: 2};
const m5 = const <dynamic, dynamic>{2: 1, 1: 2};
const m6 = const <dynamic, dynamic>{2: 2, 1: 1};
const m7 = const <dynamic, dynamic>{2: 1, 1: 1};
const m8 = const <dynamic, dynamic>{2: 2, 1: 2};
const m9 = const <int, int>{1: 1, 2: 2};
const mA = const <int, int>{1: 2, 2: 1};
const mB = const <int, int>{1: 1, 2: 1};
@@ -12,7 +12,7 @@ void main() {
var list = [1, 2, 3];
if (new DateTime.now().millisecondsSinceEpoch == 42) list[1] = 4;
int sum = 0;
for (int i = -0.0; i < list.length; i++) {
for (num i = -0.0; i < list.length; i++) {
sum += list[i];
}
Expect.equals(6, sum);
@@ -6,13 +6,14 @@
import "package:expect/expect.dart";
const double MINUS_ZERO = -0; //# 01: static type warning, checked mode compile-time error
@NoInline()
num minusZero() => -0;
void main() {
// Dart2js must not infer that the type-intersection of int and -0.0 is empty.
// It must get an interceptor for the addition (`i += 3`), or use the native
// JS + operation.
int i = MINUS_ZERO; // //# 01: continued
i += 3; // //# 01: continued
Expect.equals(3, i); // //# 01: continued
int i = minusZero();
i += 3;
Expect.equals(3, i);
}
@@ -1,14 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for 'staged' reflection. MirrorsUsed pulls in static
// functions, that pulls in more reflection. This used to trigger a bug in
// Enqueuer where the second set of pulled in definitions were unresolved.
@MirrorsUsed(targets: const ["foo"])
import 'dart:mirrors';
final foo = reflect(reflect(9)).getField(#getField);
void main() {}
@@ -1,33 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'C.foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class C {
var foo;
var bar;
}
main() {
var c = new C();
c.bar = 1;
var local = c.bar;
var mirror = reflect(c);
Expect.equals(1, mirror.setField(const Symbol('foo'), 1).reflectee);
Expect.equals(1, mirror.getField(const Symbol('foo')).reflectee);
Expect.throws(() => mirror.setField(const Symbol('bar'), 2),
(e) => e is NoSuchMethodError);
Expect.throws(() => mirror.getField(const Symbol('bar')),
(e) => e is NoSuchMethodError);
}
@@ -1,30 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'C.foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class C {
static var foo;
static var bar;
}
main() {
C.bar = 1;
var local = C.bar;
var mirror = reflect(new C()).type; // Workaround bug 12799.
Expect.equals(1, mirror.setField(const Symbol('foo'), 1).reflectee);
Expect.equals(1, mirror.getField(const Symbol('foo')).reflectee);
Expect.throws(() => mirror.setField(const Symbol('bar'), 2),
(e) => e is NoSuchMethodError);
Expect.throws(() => mirror.getField(const Symbol('bar')),
(e) => e is NoSuchMethodError);
}
@@ -1,40 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'C.foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
class C {
var foo;
var bar;
}
class D {
get bar {}
set bar(x) {}
}
int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
main() {
var c = inscrutable(1) == 1 ? new C() : new D();
c.bar = 1;
var local = c.bar;
var mirror = reflect(c);
Expect.equals(1, mirror.setField(const Symbol('foo'), 1).reflectee);
Expect.equals(1, mirror.getField(const Symbol('foo')).reflectee);
Expect.throws(() => mirror.setField(const Symbol('bar'), 2),
(e) => e is NoSuchMethodError);
Expect.throws(() => mirror.getField(const Symbol('bar')),
(e) => e is NoSuchMethodError);
}
@@ -1,29 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
var foo;
var bar;
main() {
bar = 1;
var local = bar;
var mirror = currentMirrorSystem().findLibrary(const Symbol('test'));
Expect.equals(1, mirror.setField(const Symbol('foo'), 1).reflectee);
Expect.equals(1, mirror.getField(const Symbol('foo')).reflectee);
Expect.throws(() => mirror.setField(const Symbol('bar'), 2),
(e) => e is NoSuchMethodError);
Expect.throws(() => mirror.getField(const Symbol('bar')),
(e) => e is NoSuchMethodError);
}
@@ -1,33 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'C.foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
import '../../language/compiler_annotations.dart';
class C {
foo() => 1;
@NoInline()
// Use a closure to prevent inlining until the annotation is implemented.
bar() => () => 2;
}
main() {
var c = new C();
c.bar(); // Call bar, so it is included in the program.
var mirror = reflect(c);
Expect.equals(1, mirror.invoke(const Symbol('foo'), []).reflectee);
Expect.throws(() => mirror.invoke(const Symbol('bar'), []),
(e) => e is NoSuchMethodError);
}
@@ -1,32 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'C.foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
import '../../language/compiler_annotations.dart';
class C {
static foo() => 1;
@NoInline()
// Use a closure to prevent inlining until the annotation is implemented.
static bar() => () => 2;
}
main() {
C.bar(); // Call bar, so it is included in the program.
var mirror = reflect(new C()).type; // Workaround bug 12799.
Expect.equals(1, mirror.invoke(const Symbol('foo'), []).reflectee);
Expect.throws(() => mirror.invoke(const Symbol('bar'), []),
(e) => e is NoSuchMethodError);
}
@@ -1,29 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
// annotation.
library test;
@MirrorsUsed(targets: 'foo')
import 'dart:mirrors';
import 'package:expect/expect.dart';
import '../../language/compiler_annotations.dart';
foo() => 1;
@NoInline()
// Use a closure to prevent inlining until the annotation is implemented.
bar() => () => 2;
main() {
bar(); // Call bar, so it is included in the program.
var lm = currentMirrorSystem().findLibrary(const Symbol('test'));
Expect.equals(1, lm.invoke(const Symbol('foo'), []).reflectee);
Expect.throws(() => lm.invoke(const Symbol('bar'), []));
}
@@ -1,189 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Prints all information about all mirrors. This tests that it is possible to
/// enumerate all reflective information without crashing.
// Note: Adding imports below is fine for regression tests. For example,
// 'crash_library_metadata.dart' is imported to ensure the compiler doesn't
// crash.
// TODO(ahe): This test should be extended until we are sure all data is
// printed.
library test.mirror_printer_test;
@MirrorsUsed(targets: '*')
import 'dart:mirrors';
import 'crash_library_metadata.dart'; // This would crash dart2js.
// Importing dart:html to make things interesting.
import 'dart:html'; //# 01: ok
class MirrorPrinter {
final StringBuffer buffer;
final TypeMirror dynamicType = currentMirrorSystem().dynamicType;
int indentationLevel = 0;
MirrorPrinter(this.buffer);
void w(object) {
buffer.write(object);
}
n(Symbol symbol) => MirrorSystem.getName(symbol);
void indented(action) {
indentationLevel++;
action();
indentationLevel--;
}
get indent {
for (int i = 0; i < indentationLevel; i++) {
w(' ');
}
}
String stringifyInstance(InstanceMirror mirror) {
var reflectee = mirror.reflectee;
if (reflectee is String) return '"${reflectee}"';
if (reflectee is Null ||
reflectee is bool ||
reflectee is num ||
reflectee is List ||
reflectee is Map) {
return '$reflectee';
}
StringBuffer buffer = new StringBuffer();
Map<Symbol, DeclarationMirror> declarations = mirror.type.declarations;
buffer..write(n(mirror.type.simpleName))..write('(');
bool first = true;
declarations.forEach((Symbol name, DeclarationMirror declaration) {
if (declaration is! VariableMirror) return;
VariableMirror variable = declaration;
if (variable.isStatic) return;
// TODO(ahe): Include superclasses.
if (first) {
first = false;
} else {
buffer.write(', ');
}
buffer
..write(n(name))
..write(': ')
..write(stringifyInstance(mirror.getField(name)));
});
buffer.write(')');
return buffer.toString();
}
String stringifyMetadata(InstanceMirror mirror) {
return '@${stringifyInstance(mirror)}';
}
bool writeType(TypeMirror mirror) {
if (mirror == null || mirror == dynamicType) return false;
w('${n(mirror.simpleName)} ');
return true;
}
writeVariable(VariableMirror mirror) {
bool needsVar = true;
if (mirror.isStatic) w('static ');
// TODO(ahe): What about const?
if (mirror.isFinal) {
w('final ');
needsVar = false;
}
if (writeType(mirror.type)) needsVar = false;
if (needsVar) {
w('var ');
}
w('${n(mirror.simpleName)};');
}
writeMethod(MethodMirror mirror) {
writeType(mirror.returnType);
if (mirror.isOperator) {
w('operator ');
}
if (mirror.isGetter) {
w('get ');
}
if (mirror.isSetter) {
w('set ');
}
w('${n(mirror.simpleName)}');
if (!mirror.isGetter) {
w('()');
}
w(';');
}
writeClass(ClassMirror mirror) {
// TODO(ahe): Write 'abstract' if [mirror] is abstract.
w('class ${n(mirror.simpleName)}');
// TODO(ahe): Write superclass and interfaces.
w(' {');
bool first = true;
indented(() {
for (DeclarationMirror declaration in mirror.declarations.values) {
if (first) {
first = false;
} else {
w('\n');
}
writeDeclaration(declaration);
}
});
w('\n}\n');
}
writeDeclaration(DeclarationMirror declaration) {
w('\n');
var metadata = declaration.metadata;
if (!metadata.isEmpty) {
indent;
buffer.writeAll(metadata.map(stringifyMetadata), ' ');
w('\n');
}
indent;
if (declaration is ClassMirror) {
writeClass(declaration);
} else if (declaration is VariableMirror) {
writeVariable(declaration);
} else if (declaration is MethodMirror) {
writeMethod(declaration);
} else {
// TODO(ahe): Test other subclasses of DeclarationMirror.
w('$declaration');
}
}
writeLibrary(LibraryMirror library) {
w('library ${n(library.simpleName)};\n\n');
library.declarations.values
.where((d) => d is! TypeMirror)
.forEach(writeDeclaration);
w('\n');
}
static StringBuffer stringify(Map<Uri, LibraryMirror> libraries) {
StringBuffer buffer = new StringBuffer();
libraries.values.forEach(new MirrorPrinter(buffer).writeLibrary);
return buffer;
}
}
main() {
print(MirrorPrinter.stringify(currentMirrorSystem().libraries));
// Clear the nodes to avoid confusing the fine test framework (by "fine" I
// mean something else) -- ahe.
document.body.nodes.clear(); //# 01: continued
}
@@ -1,19 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import 'dart:mirrors';
void main() {
var now = new DateTime.now();
InstanceMirror mirror = reflect(now);
print('now: ${now}');
print('mirror.type: ${mirror.type}');
print('now.toUtc(): ${now.toUtc()}');
var value = mirror.invoke(const Symbol("toUtc"), []);
print('mirror.invoke("toUtc", []): $value');
Expect.isTrue(value.hasReflectee);
Expect.equals(now.toUtc(), value.reflectee);
}
@@ -1,23 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that type inference sees the possible modification of `fisk` from
// the mirror system and not infers the value to be an integer, or any
// other elements that use `fisk` like `otherFisk` to be of type integer.
library test;
@MirrorsUsed(targets: 'fisk', override: '*')
import 'dart:mirrors';
import 'package:expect/expect.dart';
var fisk = 1;
var otherFisk = 42;
main() {
var lm = currentMirrorSystem().findLibrary(const Symbol('test'));
lm.setField(const Symbol('fisk'), 'hest');
otherFisk = fisk;
Expect.isTrue(otherFisk is String);
}
@@ -1,20 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that type inference sees the possible modification of `fisk` from
// the mirror system and not infers the value to be an integer.
library test;
@MirrorsUsed(targets: 'fisk', override: '*')
import 'dart:mirrors';
import 'package:expect/expect.dart';
var fisk = 1;
main() {
var lm = currentMirrorSystem().findLibrary(const Symbol('test'));
lm.setField(const Symbol('fisk'), 'hest');
Expect.isTrue(fisk is String);
}
@@ -1,20 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that type inference sees the call to `fisk` from the mirror system
// and not infers the argument to be an integer.
library test;
@MirrorsUsed(targets: 'fisk', override: '*')
import 'dart:mirrors';
import 'package:expect/expect.dart';
bool fisk(a) => a is int;
main() {
Expect.isTrue(fisk(1));
var lm = currentMirrorSystem().findLibrary(const Symbol('test'));
Expect.isFalse(lm.invoke(const Symbol('fisk'), ['hest']).reflectee);
}
@@ -1,52 +0,0 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for the dart2js mirrors implementation that triggers the
// generation of the declarations of a class in the presence of call stubs
// and non-reflectable methods. For neither of the latter an instance mirror
// should be constructed and they should not be contained in declarations.
@MirrorsUsed(metaTargets: "Meta")
import "dart:mirrors";
import "package:expect/expect.dart";
class Meta {
const Meta();
}
class A {
@Meta()
reflectableThing(int a, [int b = 9, int c = 42]) => a + b + c;
nonReflectableThing(int a, [int b = 4, int c = 21]) => a + b + c;
}
tryCall(object, symbol, values, expected) {
var mirror = reflect(object);
var result = mirror.invoke(symbol, values).reflectee;
Expect.equals(result, expected);
}
@NoInline()
@AssumeDynamic()
hide(x) => x;
main() {
var a = hide(new A());
// Make sure we statically have some calls to reflectableThing with 1, 2 and
// 3 arguments so that stubs are generated.
Expect.equals(1 + 9 + 42, a.reflectableThing(1));
Expect.equals(1 + 5 + 42, a.reflectableThing(1, 5));
Expect.equals(1 + 22 + 3, a.reflectableThing(1, 22, 3));
// Try calling methods through reflection.
tryCall(a, #reflectableThing, [1], 1 + 9 + 42);
tryCall(a, #reflectableThing, [1, 5], 1 + 5 + 42);
tryCall(a, #reflectableThing, [1, 22, 3], 1 + 22 + 3);
Expect.throws(() => tryCall(a, #nonReflectableThing, [1], 1 + 4 + 21));
Expect.throws(() => tryCall(a, #nonReflectableThing, [1, 5], 1 + 5 + 21));
Expect.throws(() => tryCall(a, #nonReflectableThing, [1, 13, 7], 1 + 13 + 7));
// Trigger generation of all declarations and check they only contain a
// a single entry.
var declarations = reflect(a).type.declarations;
Expect.equals(1, declarations.keys.length);
Expect.equals(#reflectableThing, declarations.keys.first);
}
@@ -1,29 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library MirrorsTest;
import 'package:expect/expect.dart';
@MirrorsUsed(targets: const ['A.foo', 'B.bar'])
import 'dart:mirrors';
class A {
foo() => 42;
bar() => 499;
}
class B {
bar() => 33;
}
@NoInline()
@AssumeDynamic()
confuse(x) => x;
main() {
var f = [new A(), new B()][confuse(0)].bar;
Expect.throws(
() => reflect(f).invoke(#call, [], {}), (e) => e is UnsupportedError);
}
@@ -1,40 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@MirrorsUsed(metaTargets: 'X')
import 'dart:mirrors';
const x = const X();
class X {
const X();
}
@x
class Y {
foo() => 42;
}
class Z {
foo() => 99;
@X()
bar() => 87;
}
main() {
var y = new Y();
var z = new Z();
if (reflect(y).invoke(#foo, []).reflectee != 42) throw 'Wrong Y.foo';
if (reflect(z).invoke(#bar, []).reflectee != 87) throw 'Wrong Z.bar';
bool caught = false;
try {
reflect(z).invoke(#foo, []);
} on UnsupportedError catch (e) {
caught = true;
}
if (!caught) throw 'Wrong Z.foo';
}
@@ -1,14 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@MirrorsUsed(targets: 'List')
import 'dart:mirrors';
import 'package:expect/expect.dart';
main() {
Expect.equals(3, reflect([1, 2, 3]).getField(#length).reflectee);
Expect.throws(() => reflect({"hest": 42}).getField(#length),
(e) => e is UnsupportedError);
}
@@ -1,34 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:mirrors';
import 'dart:async';
import 'package:expect/expect.dart';
class A {
noSuchMethod(Invocation invocation) {
return MirrorSystem.getName(invocation.memberName);
}
}
var lines = [];
capturePrint(Zone self, ZoneDelegate parent, Zone origin, line) {
lines.add(line);
}
runTests() {
// No MirrorsUsed annotation anywhere.
// Dart2js should retain all symbols.
Expect.equals("foo", new A().foo);
Expect.isTrue(lines.isEmpty);
var barResult = new A().bar;
Expect.equals("bar", barResult);
Expect.isTrue(lines.isEmpty);
}
main() {
runZoned(runTests,
zoneSpecification: new ZoneSpecification(print: capturePrint));
}
@@ -1,39 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@MirrorsUsed(symbols: 'foo')
import 'dart:mirrors';
import 'dart:async';
import 'package:expect/expect.dart';
class A {
noSuchMethod(Invocation invocation) {
return MirrorSystem.getName(invocation.memberName);
}
}
var lines = [];
capturePrint(Zone self, ZoneDelegate parent, Zone origin, line) {
lines.add(line);
}
runTests() {
// "foo" is in MirrorsUsed and should therefore always work.
Expect.equals("foo", new A().foo);
Expect.isTrue(lines.isEmpty);
var barResult = new A().bar;
Expect.equals("bar", barResult); // //# minif: ok
Expect.isTrue(lines.length == 1);
var line = lines.first;
Expect.isTrue(line.contains("Warning") &&
line.contains("bar") && // //# minif: continued
line.contains("minif"));
}
main() {
runZoned(runTests,
zoneSpecification: new ZoneSpecification(print: capturePrint));
}
@@ -1,21 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A {
noSuchMethod(im) {
reflect(new B()).delegate(im);
}
}
class B {}
main() {
// Test with an intercepted selector.
Expect.throws(() => new A().startsWith(42), (e) => e is NoSuchMethodError);
// Test with a non-intercepted selector.
Expect.throws(() => new A().foobar(), (e) => e is NoSuchMethodError);
}
@@ -93,7 +93,7 @@ void mulTest() {
void divTest() {
var m1 = 0.0 - 1.0;
var m2 = 0 - 2;
var x = two();
num x = two();
x /= 2;
Expect.equals(1.0, x);
x /= 2;
@@ -13,7 +13,7 @@ class AlwaysFalse {
}
main() {
var a = new AlwaysTrue();
dynamic a = new AlwaysTrue();
Expect.isTrue(a == 2);
Expect.isFalse(a == null);
Expect.isFalse(a != 2);
@@ -24,7 +24,7 @@ main() {
Expect.equals(null, a.foo());
Expect.equals(null, a.bar(42));
Expect.equals(42, a.bar(null, 42));
Expect.equals(0, a.foo(1, 2));
Expect.equals(0, a.bar());
Expect.equals(0, a.bar(1, 2, 3));
Expect.equals(0, (a as dynamic).foo(1, 2));
Expect.equals(0, (a as dynamic).bar());
Expect.equals(0, (a as dynamic).bar(1, 2, 3));
}
@@ -1,22 +0,0 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that reflection works on intercepted types.
import 'dart:mirrors';
import 'package:expect/expect.dart';
main() {
// Make sure that reflecting on values of intercepted/native classes does
// not crash.
var intMembers = reflect(123).type.instanceMembers;
Expect.isTrue(intMembers.containsKey(#compareTo));
Expect.isTrue(intMembers.length > 15);
var listMembers = reflect([]).type.instanceMembers;
Expect.isTrue(listMembers.containsKey(#join));
Expect.isTrue(listMembers.length > 15);
var stringMembers = reflect('hest').type.instanceMembers;
Expect.isTrue(stringMembers.containsKey(#contains));
Expect.isTrue(stringMembers.length > 15);
}
@@ -1,9 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library _4740_library;
class Foo {
Foo._internal();
}
@@ -1,11 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import '4740_library.dart';
main() {
Expect.throws(() => new Foo._internal(), (e) => e is NoSuchMethodError);
}
@@ -6,8 +6,8 @@ import 'package:expect/expect.dart';
main() {
var m1 = {
'hello': ['hi', 'howdy'],
'bye': []
'hello': <String>['hi', 'howdy'],
'bye': <String>[]
};
var m = new Map<String, List<String>>.unmodifiable(m1);
print(m);
@@ -75,8 +75,10 @@ switcher4(val) {
switch (val) {
case 1:
return 100;
case 2:
case 2: _throw(); //# 00: compile-time error
case 3:
_throw();
break;
default:
return 300;
}
@@ -9,9 +9,9 @@ import 'package:expect/expect.dart';
class C<T, S> {}
bool inCheckedMode() {
bool inComplianceMode() {
try {
int i = 'hest';
int i = ('hest' as dynamic);
} catch (e) {
return true;
}
@@ -19,10 +19,10 @@ bool inCheckedMode() {
}
main() {
if (inCheckedMode()) {
if (inComplianceMode()) {
bool caught = false;
try {
C<String, String> x = new C<C<int, String>, String>();
C<String, String> x = (new C<C<int, String>, String>()) as dynamic;
} catch (e) {
String nameOfC = (C).toString();
String nameOfInt = (int).toString();
@@ -1,13 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
int foo(int i) {
i = 'fisk'; // //# 01: static type warning
return 'kat'; // //# 02: static type warning, dynamic type error
}
main() {
foo(42);
foo('hest'); // //# 03: static type warning
}
@@ -11,6 +11,6 @@ main() {
// of our test runner, but I can think of no other way to test this.
// -- ahe
if (!thisScript.endsWith('/out.js')) {
throw 'Unexpected script: "$thiscript"';
throw 'Unexpected script: "$thisScript"';
}
}
@@ -8,13 +8,19 @@ import "native_testing.dart";
class A {}
@Native("B")
class B implements Comparable {}
class B implements Comparable {
noSuchMethod(m) => super.noSuchMethod(m);
}
@Native("C")
class C implements Pattern {}
class C implements Pattern {
noSuchMethod(m) => super.noSuchMethod(m);
}
@Native("D")
class D implements Pattern, Comparable {}
class D implements Pattern, Comparable {
noSuchMethod(m) => super.noSuchMethod(m);
}
makeA() native;
makeB() native;
@@ -5,17 +5,13 @@
[ $compiler == dart2js ]
bound_closure_super_test: RuntimeError
fake_thing_test: RuntimeError # Issue 13010
mirror_intercepted_field_test: SkipByDesign # mirrors not supported
native_mirror_test: SkipByDesign # mirrors not supported
native_no_such_method_exception3_frog_test: SkipByDesign # mirrors not supported
native_no_such_method_exception4_frog_test: SkipByDesign # mirrors not supported
native_no_such_method_exception5_frog_test: SkipByDesign # mirrors not supported
[ $browser ]
*: Skip
[ $compiler == dart2js && $checked ]
[ $compiler == dart2js && $checked && !$strong ]
error_safeToString_test: RuntimeError # Fix for Issue 33627 disabled native class sharing
native_method_inlining_test: RuntimeError
[ $compiler == dart2js && $fasta ]
native_library_same_name_used_frog_test: CompileTimeError
@@ -26,3 +22,7 @@ subclassing_super_field_2_test: RuntimeError
[ $compiler == dart2js && $minified ]
optimization_hints_test: RuntimeError, OK # Test relies on unminified names.
[ $compiler == dart2js && $strong ]
error_safeToString_test: RuntimeError # Fix for Issue 33627 disabled native class sharing
native_checked_fields_frog_test: RuntimeError
@@ -10,7 +10,7 @@ abstract class J {}
abstract class I extends J {
I read();
write(I x);
write(covariant I x);
}
// Native implementation.
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import "dart:_foreign_helper" show JS;
// Test that native objects cannot accidentally or maliciously be mistaken for
// Dart objects.
@@ -20,7 +21,7 @@ void setup() {
(function(){
function A() {}
A.prototype.$isThing = true;
make1 = function(){return new A;};
make1 = function(){return new A();};
make2 = function(){return {$isThing: true}};
})()""");
}
@@ -5,9 +5,9 @@
import 'native_testing.dart';
import 'dart:_js_helper' show intTypeCheck;
bool get inCheckedMode {
bool get inComplianceMode {
try {
String a = 42;
String a = (42 as dynamic);
} on TypeError catch (e) {
return true;
}
@@ -25,7 +25,7 @@ main() {
// implementing checked mode semantics (like in the check below),
// the check won't fail at runtime.
intTypeCheck(42);
if (inCheckedMode) {
if (inComplianceMode) {
int value;
Expect.throws(() => value = a[1], (e) => e is TypeError);
}
@@ -1,31 +0,0 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:mirrors';
import 'native_testing.dart';
@Native("B")
class B {
// Having this field in a native class will generate accessors with
// the interceptor calling convention.
var f;
}
class A {
int f;
}
const symF = const Symbol('f');
main() {
JS('B', '(null)'); // B appears to be created.
var a = new A();
InstanceMirror mirror = reflect(a);
mirror.setField(symF, 42);
Expect.equals(42, a.f);
mirror = mirror.getField(symF);
Expect.equals(42, mirror.reflectee);
}
@@ -66,17 +66,17 @@ testStaticContext() {
A a = makeA();
B b = makeB();
Expect.throws(() => a.foo());
Expect.throws(() => (a as dynamic).foo());
Expect.equals(1, a.foo(10));
Expect.throws(() => a.foo(10, 20));
Expect.throws(() => a.foo(10, 20, 30));
Expect.throws(() => (a as dynamic).foo(10, 20));
Expect.throws(() => (a as dynamic).foo(10, 20, 30));
Expect.equals(0, b.foo());
Expect.equals(1, b.foo(10));
Expect.equals(2, b.foo(10, 20));
Expect.equals(3, b.foo(10, 20, 30));
Expect.throws(() => b.foo(10, 20, 30, 40));
Expect.throws(() => (b as dynamic).foo(10, 20, 30, 40));
}
main() {
@@ -78,20 +78,16 @@ testStaticContext() {
Expect.equals(0, a.foo());
Expect.equals(1, a.foo(10));
Expect.equals(2, a.foo(10, 20));
Expect.throws(() => a.foo(10, 20, 30));
Expect.equals(1, a.foo(10));
Expect.equals(2, a.foo(null, 20));
Expect.throws(() => a.foo(10, 20, 30));
Expect.equals(0, b.foo());
Expect.equals(1, b.foo(10));
Expect.equals(2, b.foo(10, 20));
Expect.throws(() => b.foo(10, 20, 30));
Expect.equals(1, b.foo(10));
Expect.equals(2, b.foo(null, 20));
Expect.throws(() => b.foo(10, 20, 30));
}
main() {
@@ -65,10 +65,7 @@ testStaticContext() {
A a = makeA();
B b = makeB();
Expect.throws(() => a.foo());
Expect.equals(1, a.foo(10));
Expect.throws(() => a.foo(10, 20));
Expect.throws(() => a.foo(10, 20, 30));
Expect.equals(0, b.foo());
Expect.equals(1, b.foo(10));
@@ -78,7 +75,6 @@ testStaticContext() {
Expect.equals(1, b.foo(10));
Expect.equals(2, b.foo(null, 20));
Expect.equals(3, b.foo(null, null, 30));
Expect.throws(() => b.foo(10, 20, 30, 40));
}
main() {
@@ -50,8 +50,8 @@ expectThrows(action()) {
Expect.isTrue(threw);
}
checkedModeTest() {
var things = [makeA(), makeB()];
complianceModeTest() {
var things = <dynamic>[makeA(), makeB()];
var a = things[0];
var b = things[1];
@@ -68,28 +68,10 @@ checkedModeTest() {
Expect.equals(1, b.cmp(b));
expectThrows(() => b.cmp(a));
expectThrows(() => b.cmp(5));
// Check that we throw the same errors when the locals are typed.
A aa = things[0];
B bb = things[1];
Expect.equals(124, aa.foo(123));
expectThrows(() => aa.foo('xxx'));
Expect.equals('helloha!', bb.foo('hello'));
expectThrows(() => bb.foo(123));
Expect.equals(0, aa.cmp(aa));
expectThrows(() => aa.cmp(bb));
expectThrows(() => aa.cmp(5));
Expect.equals(1, bb.cmp(bb));
expectThrows(() => bb.cmp(aa));
expectThrows(() => bb.cmp(5));
}
uncheckedModeTest() {
var things = [makeA(), makeB()];
omitImplicitChecksModeTest() {
var things = <dynamic>[makeA(), makeB()];
var a = things[0];
var b = things[1];
@@ -106,30 +88,12 @@ uncheckedModeTest() {
Expect.equals(1, b.cmp(b));
Expect.equals(1, b.cmp(a));
Expect.equals(1, b.cmp(5));
// Check that we do not throw errors when the locals are typed.
A aa = things[0];
B bb = things[1];
Expect.equals(124, aa.foo(123));
Expect.equals('xxx1', aa.foo('xxx'));
Expect.equals('helloha!', bb.foo('hello'));
Expect.equals('123ha!', bb.foo(123));
Expect.equals(0, aa.cmp(aa));
Expect.equals(0, aa.cmp(bb));
Expect.equals(0, aa.cmp(5));
Expect.equals(1, bb.cmp(bb));
Expect.equals(1, bb.cmp(aa));
Expect.equals(1, bb.cmp(5));
}
bool isCheckedMode() {
var stuff = [1, 'string'];
var a = stuff[0];
// Checked-mode detection.
bool isComplianceMode() {
var stuff = <dynamic>[1, 'string'];
dynamic a = stuff[0];
// compliance-mode detection.
try {
String s = a;
return false;
@@ -143,9 +107,9 @@ main() {
nativeTesting();
setup();
if (isCheckedMode()) {
checkedModeTest();
if (isComplianceMode()) {
complianceModeTest();
} else {
uncheckedModeTest();
omitImplicitChecksModeTest();
}
}
@@ -44,8 +44,8 @@ expectThrows(action()) {
Expect.isTrue(threw);
}
checkedModeTest() {
var things = [makeA(), makeB()];
complianceModeTest() {
var things = <dynamic>[makeA(), makeB()];
var a = things[0];
var b = things[1];
@@ -56,22 +56,10 @@ checkedModeTest() {
b.foo = 'hello';
expectThrows(() => b.foo = 123);
Expect.equals('hello', b.foo);
// Check that we throw the same errors when the locals are typed.
A aa = things[0];
B bb = things[1];
aa.foo = 124;
expectThrows(() => aa.foo = 'xxx');
Expect.equals(124, aa.foo);
bb.foo = 'hello';
expectThrows(() => bb.foo = 124);
Expect.equals('hello', bb.foo);
}
uncheckedModeTest() {
var things = [makeA(), makeB()];
omitImplicitChecksTest() {
var things = <dynamic>[makeA(), makeB()];
var a = things[0];
var b = things[1];
@@ -84,26 +72,12 @@ uncheckedModeTest() {
Expect.equals('hello', b.foo);
b.foo = 123;
Expect.equals(b.foo, 123);
// Check that we do not throw errors when the locals are typed.
A aa = things[0];
B bb = things[1];
aa.foo = 124;
Expect.equals(124, aa.foo);
a.foo = 'yyy';
Expect.equals('yyy', a.foo);
b.foo = 'hello';
Expect.equals('hello', b.foo);
b.foo = 124;
Expect.equals(b.foo, 124);
}
bool isCheckedMode() {
bool isComplianceMode() {
var stuff = [1, 'string'];
var a = stuff[0];
// Checked-mode detection.
// Detect whether we are using --omit-implicit-checks.
try {
String s = a;
return false;
@@ -117,9 +91,9 @@ main() {
nativeTesting();
setup();
if (isCheckedMode()) {
checkedModeTest();
if (isComplianceMode()) {
complianceModeTest();
} else {
uncheckedModeTest();
omitImplicitChecksTest();
}
}
@@ -104,7 +104,7 @@ main() {
caught = false;
try {
var x = 123;
dynamic x = 123;
x.foo(20);
} catch (ex) {
caught = true;
@@ -111,7 +111,7 @@ testBasicB_typed() {
testAB_dynamic() {
setup(); // Fresh constructors.
var things = [makeA(), makeB()];
var things = <dynamic>[makeA(), makeB()];
var a = things[0];
var b = things[1];
@@ -8,7 +8,7 @@ import "native_testing.dart";
abstract class I {
I read();
write(I x);
write(covariant I x);
}
// Native implementation.
@@ -10,7 +10,7 @@ abstract class J {}
abstract class I extends J {
I read();
write(I x);
write(covariant I x);
}
// Native implementation.
@@ -32,7 +32,7 @@ main() {
nativeTesting();
setup();
var a = new A();
dynamic a = new A();
var z = makeZ();
Expect.equals(100, z.foo());
@@ -77,16 +77,6 @@ void setup() {
})()""");
}
bool get isCheckedMode {
int i = 0;
try {
i = 'a';
} catch (e) {
return true;
}
return false;
}
void match(String s, String pattern1) {
var pattern2 = pattern1.replaceAll(' ', '');
Expect.isTrue(s.contains(pattern1) || s.contains(pattern2),
@@ -103,19 +93,11 @@ test1() {
String method1 = findMethodTextContaining(new B(), '(Method1Tag)');
Expect.isNotNull(method1, 'No method found containing "(Method1Tag)"');
if (isCheckedMode) {
match(method1, r'foo()');
// TODO: inlining in checked mode.
nomatch(method1, r'foo(1)');
// t1.foo$3(x, 3, 10, 30) or y.EL(z,3,10,30)
match(method1, r', 3, 10, 30)');
} else {
// Direct (inlined) calls don't have $3 or minified names.
match(method1, r'.foo()');
match(method1, r'.foo(1)');
match(method1, r'.foo(2, 10)');
match(method1, r'.foo(3, 10, 30)');
}
// Direct (inlined) calls don't have $3 or minified names.
match(method1, r'.foo()');
match(method1, r'.foo(1)');
match(method1, r'.foo(2, 10)');
match(method1, r'.foo(3, 10, 30)');
// Ensure the methods are compiled by calling them.
var a = makeA();
@@ -1,29 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Intercepted members need to be accessed in a different way than normal
// members. In this test the native class A (thus being intercepted) has a
// member "foo", that is final. Therefore only the getter needs to be
// intercepted. Dart2js had a bug where it used the intercepted
// calling-convention for parts of the compiler, and the non-intercepted
// convention for others, making this fail.
import 'native_testing.dart';
import 'dart:_js_helper';
import 'dart:mirrors';
@Native("A")
class A {
final foo;
}
class B {
String foo;
}
main() {
var b = new B();
reflect(b).setField(new Symbol("foo"), "bar");
Expect.equals("bar", b.foo);
}
@@ -33,7 +33,7 @@ class B {
typedContext() {
confuse(new B()).foo();
A a = makeA();
dynamic a = makeA();
Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError);
Expect.throws(() => a.foo, (e) => e is NoSuchMethodError);
Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError);
@@ -33,8 +33,8 @@ class C {
}
}
typedContext() {
A a = makeA();
inferredContext() {
dynamic a = makeA();
Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError);
Expect.throws(() => a.foo, (e) => e is NoSuchMethodError);
Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError);
@@ -52,6 +52,6 @@ main() {
setup();
confuse(new B()).foo();
confuse(new C()).foo(1);
typedContext();
inferredContext();
untypedContext();
}
@@ -47,9 +47,9 @@ main() {
setup();
A a = makeA();
Expect.equals("A-foo", a.foo);
Expect.throws(() => a.bar, (e) => e is NoSuchMethodError);
Expect.throws(() => a.baz, (e) => e is NoSuchMethodError);
Expect.throws(() => a.buz, (e) => e is NoSuchMethodError);
Expect.throws(() => (a as dynamic).bar, (e) => e is NoSuchMethodError);
Expect.throws(() => (a as dynamic).baz, (e) => e is NoSuchMethodError);
Expect.throws(() => (a as dynamic).buz, (e) => e is NoSuchMethodError);
B b = makeB();
Expect.equals("A-foo", b.foo);
@@ -59,14 +59,14 @@ main() {
Expect.isNull(b.buz);
M1 m1 = new M1();
Expect.throws(() => m1.foo, (e) => e is NoSuchMethodError);
Expect.throws(() => m1.bar, (e) => e is NoSuchMethodError);
Expect.throws(() => (m1 as dynamic).foo, (e) => e is NoSuchMethodError);
Expect.throws(() => (m1 as dynamic).bar, (e) => e is NoSuchMethodError);
Expect.isNull(m1.baz);
Expect.throws(() => m1.buz, (e) => e is NoSuchMethodError);
Expect.throws(() => (m1 as dynamic).buz, (e) => e is NoSuchMethodError);
M2 m2 = new M2();
Expect.throws(() => m2.foo, (e) => e is NoSuchMethodError);
Expect.throws(() => (m2 as dynamic).foo, (e) => e is NoSuchMethodError);
Expect.isNull(m2.bar);
Expect.throws(() => m2.baz, (e) => e is NoSuchMethodError);
Expect.throws(() => (m2 as dynamic).baz, (e) => e is NoSuchMethodError);
Expect.isNull(m2.buz);
}
@@ -47,7 +47,8 @@ main() {
setup();
A a = makeA();
Expect.equals("A-foo", a.foo());
Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (a as dynamic).bar(), (error) => error is NoSuchMethodError);
Expect.equals("A-baz", a.baz());
Expect.isTrue(a is A);
Expect.isFalse(a is B);
@@ -65,7 +66,8 @@ main() {
M1 m1 = new M1();
Expect.equals("M1-foo", m1.foo());
Expect.throws(() => m1.bar(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (m1 as dynamic).bar(), (error) => error is NoSuchMethodError);
Expect.equals("M1-baz", m1.baz());
Expect.isFalse(m1 is A);
Expect.isFalse(m1 is B);
@@ -74,8 +76,10 @@ main() {
M2 m2 = new M2();
Expect.equals("M2-foo", m2.foo());
Expect.throws(() => m2.bar(), (error) => error is NoSuchMethodError);
Expect.throws(() => m2.baz(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (m2 as dynamic).bar(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (m2 as dynamic).baz(), (error) => error is NoSuchMethodError);
Expect.isFalse(m2 is A);
Expect.isFalse(m2 is B);
Expect.isFalse(m2 is M1);
@@ -43,7 +43,8 @@ main() {
setup();
A a = makeA();
Expect.equals("A-foo", a.foo());
Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (a as dynamic).bar(), (error) => error is NoSuchMethodError);
Expect.equals("A-baz", a.baz());
Expect.isTrue(a is A);
Expect.isFalse(a is B);
@@ -60,7 +61,8 @@ main() {
M m = new M();
Expect.equals("M-foo", m.foo());
Expect.equals("M-bar", m.bar());
Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError);
Expect.throws(
() => (m as dynamic).baz(), (error) => error is NoSuchMethodError);
Expect.isFalse(m is A);
Expect.isFalse(m is B);
Expect.isTrue(m is M);
@@ -1,56 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:mirrors" show reflect;
import "native_testing.dart";
class GetName {
foo(x, y, [z]) => "foo";
}
String getName(im) => reflect(new GetName()).delegate(im);
@Native("A")
class A {
bar() => 42;
}
@Native("B")
class B {
foo() => 42;
}
class C {
static create() => new C();
noSuchMethod(x) => "${getName(x)}:${x.positionalArguments}";
}
makeA() native;
setup() {
JS('', r"""
(function(){
function A() {}
makeA = function() { return new A(); };
self.nativeConstructor(A);
})()""");
}
main() {
nativeTesting();
setup();
var a = makeA();
a.bar();
var exception;
try {
a.foo();
} on NoSuchMethodError catch (e) {
exception = e;
}
Expect.isNotNull(exception);
var c = C.create();
Expect.equals("foo:[1, 2]", c.foo(1, 2));
Expect.equals("foo:[3, 4, 5]", c.foo(3, 4, 5));
}
@@ -1,44 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:mirrors" show reflect;
import "native_testing.dart";
class GetName {
foo(x, y) => "foo";
baz(x, y, z) => "baz";
}
String getName(im) => reflect(new GetName()).delegate(im);
@Native("A")
class A {
bar() => 42;
noSuchMethod(x) => "native(${getName(x)}:${x.positionalArguments})";
}
@Native("B")
class B {
baz() => 42;
}
makeA() native;
setup() {
JS('', r"""
(function(){
function A() {}
makeA = function() { return new A(); };
self.nativeConstructor(A);
})()""");
}
main() {
nativeTesting();
setup();
var a = makeA();
a.bar();
Expect.equals("native(foo:[1, 2])", a.foo(1, 2));
Expect.equals("native(baz:[3, 4, 5])", a.baz(3, 4, 5));
}
@@ -1,51 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:mirrors" show reflect;
import "native_testing.dart";
class GetName {
foo(x, [y]) => "foo";
baz(x, y, z) => "baz";
}
String getName(im) => reflect(new GetName()).delegate(im);
@Native("A")
class A {
bar() => 42;
noSuchMethod(x) => "native(${getName(x)}:${x.positionalArguments})";
}
@Native("B")
class B {
baz() => 42;
}
class C {
static create() => new C();
noSuchMethod(x) => "${getName(x)}:${x.positionalArguments}";
}
makeA() native;
setup() {
JS('', r"""
(function(){
function A() {}
makeA = function() { return new A(); };
self.nativeConstructor(A);
})()""");
}
main() {
nativeTesting();
setup();
var a = makeA();
a.bar();
Expect.equals("native(foo:[1, 2])", a.foo(1, 2));
Expect.equals("native(baz:[3, 4, 5])", a.baz(3, 4, 5));
var c = C.create();
Expect.equals("foo:[6]", c.foo(6));
}

Some files were not shown because too many files have changed in this diff Show More