Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: tests/compiler/dart2js_native/native_missing_method2_frog_test.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "dart:_js_helper"; 5 import 'native_testing.dart';
6 import "package:expect/expect.dart";
7
8 @Native("A") 6 @Native("A")
9 class A {} 7 class A {}
10 8
11 makeA() native ; 9 A makeA() native ;
12 10
13 void setup() native """ 11 void setup() native """
14 function A() {}; 12 function A() {};
15 A.prototype.foo = function() { return 42; } 13 A.prototype.foo = function() { return 42; }
16 makeA = function() { return new A; } 14 makeA = function() { return new A; }
15 self.nativeConstructor(A);
17 """; 16 """;
18 17
19 class B { 18 class B {
20 foo() { 19 foo() {
21 return 42; 20 return 42;
22 } 21 }
23 } 22 }
24 23
25 class C { 24 class C {
26 // By having two 'foo' defined in the application, Frog will mangle 25 // By having two 'foo' defined in the application, Frog will mangle
27 // all calls to 'foo', which makes this test pass. 26 // all calls to 'foo', which makes this test pass.
28 foo(x) { 27 foo(x) {
29 return 43; 28 return 43;
30 } 29 }
31 } 30 }
32 31
33 typedContext() { 32 typedContext() {
34 var things = [makeA(), new B()]; 33 A a = makeA();
35 A a = things[0];
36 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); 34 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError);
37 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); 35 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError);
38 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); 36 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError);
39 } 37 }
40 38
41 untypedContext() { 39 untypedContext() {
42 var things = [makeA(), new B()]; 40 var a = confuse(makeA());
43 var a = things[0];
44 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError); 41 Expect.throws(() => a.foo(), (e) => e is NoSuchMethodError);
45 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError); 42 Expect.throws(() => a.foo, (e) => e is NoSuchMethodError);
46 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError); 43 Expect.throws(() => a.foo = 4, (e) => e is NoSuchMethodError);
47 } 44 }
48 45
49 main() { 46 main() {
47 nativeTesting();
50 setup(); 48 setup();
49 confuse(new B()).foo();
50 confuse(new C()).foo(1);
51 typedContext(); 51 typedContext();
52 untypedContext(); 52 untypedContext();
53 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698