OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test the feature where the native string declares the native method's name. | 5 // Test the feature where the native string declares the native method's name. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "native_testing.dart"; |
8 import 'dart:_js_helper' show Native, JSName; | |
9 | 8 |
10 @Native("A") | 9 @Native("A") |
11 class A { | 10 class A { |
12 @JSName('fooA') | 11 @JSName('fooA') |
13 int foo() native ; | 12 int foo() native ; |
14 } | 13 } |
15 | 14 |
16 @Native("B") | 15 @Native("B") |
17 class B extends A { | 16 class B extends A { |
18 @JSName('fooB') | 17 @JSName('fooB') |
(...skipping 16 matching lines...) Expand all Loading... |
35 } | 34 } |
36 } | 35 } |
37 function A(){} | 36 function A(){} |
38 A.prototype.fooA = function(){return 100;}; | 37 A.prototype.fooA = function(){return 100;}; |
39 function B(){} | 38 function B(){} |
40 inherits(B, A); | 39 inherits(B, A); |
41 B.prototype.fooB = function(){return 200;}; | 40 B.prototype.fooB = function(){return 200;}; |
42 | 41 |
43 makeA = function(){return new A}; | 42 makeA = function(){return new A}; |
44 makeB = function(){return new B}; | 43 makeB = function(){return new B}; |
| 44 |
| 45 self.nativeConstructor(A); |
| 46 self.nativeConstructor(B); |
45 """; | 47 """; |
46 | 48 |
47 testDynamic() { | 49 testDynamic() { |
48 var things = [makeA(), makeB()]; | 50 var things = [makeA(), makeB()]; |
49 var a = things[0]; | 51 var a = things[0]; |
50 var b = things[1]; | 52 var b = things[1]; |
51 | 53 |
52 Expect.equals(100, a.foo()); | 54 Expect.equals(100, a.foo()); |
53 Expect.equals(200, b.foo()); | 55 Expect.equals(200, b.foo()); |
54 | 56 |
(...skipping 14 matching lines...) Expand all Loading... |
69 | 71 |
70 testTyped() { | 72 testTyped() { |
71 A a = makeA(); | 73 A a = makeA(); |
72 B b = makeB(); | 74 B b = makeB(); |
73 | 75 |
74 Expect.equals(100, a.foo()); | 76 Expect.equals(100, a.foo()); |
75 Expect.equals(200, b.foo()); | 77 Expect.equals(200, b.foo()); |
76 } | 78 } |
77 | 79 |
78 main() { | 80 main() { |
| 81 nativeTesting(); |
79 setup(); | 82 setup(); |
80 | 83 |
81 testDynamic(); | 84 testDynamic(); |
82 testTyped(); | 85 testTyped(); |
83 } | 86 } |
84 | 87 |
85 expectNoSuchMethod(action, note) { | 88 expectNoSuchMethod(action, note) { |
86 bool caught = false; | 89 bool caught = false; |
87 try { | 90 try { |
88 action(); | 91 action(); |
89 } catch (ex) { | 92 } catch (ex) { |
90 caught = true; | 93 caught = true; |
91 Expect.isTrue(ex is NoSuchMethodError, note); | 94 Expect.isTrue(ex is NoSuchMethodError, note); |
92 } | 95 } |
93 Expect.isTrue(caught, note); | 96 Expect.isTrue(caught, note); |
94 } | 97 } |
OLD | NEW |