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

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

Issue 2984403002: dart2js_native tests: Migrate 'native STRING' to JS-calls (Closed)
Patch Set: the rest of the files Created 3 years, 4 months 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "native_testing.dart"; 5 import "native_testing.dart";
6 6
7 // Test that native classes can use ordinary Dart classes as mixins. 7 // Test that native classes can use ordinary Dart classes as mixins.
8 8
9 @Native("A") 9 @Native("A")
10 class A { 10 class A {
11 foo() => "A-foo"; 11 foo() => "A-foo";
12 baz() => "A-baz"; 12 baz() => "A-baz";
13 } 13 }
14 14
15 @Native("B") 15 @Native("B")
16 class B extends A with M { 16 class B extends A with M {
17 bar() => baz(); 17 bar() => baz();
18 } 18 }
19 19
20 class M { 20 class M {
21 foo() => "M-foo"; 21 foo() => "M-foo";
22 bar() => "M-bar"; 22 bar() => "M-bar";
23 } 23 }
24 24
25 A makeA() native; 25 A makeA() native;
26 B makeB() native; 26 B makeB() native;
27 27
28 void setup() native """ 28 void setup() {
29 function A() {} 29 JS('', r"""
30 function B() {} 30 (function(){
31 makeA = function(){return new A;}; 31 function A() {}
32 makeB = function(){return new B;}; 32 function B() {}
33 makeA = function(){return new A()};
34 makeB = function(){return new B()};
33 35
34 self.nativeConstructor(A); 36 self.nativeConstructor(A);
35 self.nativeConstructor(B); 37 self.nativeConstructor(B);
36 """; 38 })()""");
39 }
37 40
38 main() { 41 main() {
39 nativeTesting(); 42 nativeTesting();
40 setup(); 43 setup();
41 A a = makeA(); 44 A a = makeA();
42 Expect.equals("A-foo", a.foo()); 45 Expect.equals("A-foo", a.foo());
43 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError); 46 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError);
44 Expect.equals("A-baz", a.baz()); 47 Expect.equals("A-baz", a.baz());
45 Expect.isTrue(a is A); 48 Expect.isTrue(a is A);
46 Expect.isFalse(a is B); 49 Expect.isFalse(a is B);
47 Expect.isFalse(a is M); 50 Expect.isFalse(a is M);
48 51
49 B b = makeB(); 52 B b = makeB();
50 Expect.equals("M-foo", b.foo()); 53 Expect.equals("M-foo", b.foo());
51 Expect.equals("A-baz", b.bar()); 54 Expect.equals("A-baz", b.bar());
52 Expect.equals("A-baz", b.baz()); 55 Expect.equals("A-baz", b.baz());
53 Expect.isTrue(b is A); 56 Expect.isTrue(b is A);
54 Expect.isTrue(b is B); 57 Expect.isTrue(b is B);
55 Expect.isTrue(b is M); 58 Expect.isTrue(b is M);
56 59
57 M m = new M(); 60 M m = new M();
58 Expect.equals("M-foo", m.foo()); 61 Expect.equals("M-foo", m.foo());
59 Expect.equals("M-bar", m.bar()); 62 Expect.equals("M-bar", m.bar());
60 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError); 63 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError);
61 Expect.isFalse(m is A); 64 Expect.isFalse(m is A);
62 Expect.isFalse(m is B); 65 Expect.isFalse(m is B);
63 Expect.isTrue(m is M); 66 Expect.isTrue(m is M);
64 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698