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 import "dart:_js_helper"; | 5 import 'native_testing.dart'; |
6 import "package:expect/expect.dart"; | |
7 | 6 |
8 // Test that type checks occur on assignment to fields of native methods. | 7 // Test that type checks occur on assignment to fields of native methods. |
9 | 8 |
10 @Native("A") | 9 @Native("A") |
11 class A { | 10 class A { |
12 int foo; | 11 int foo; |
13 } | 12 } |
14 | 13 |
15 @Native("B") | 14 @Native("B") |
16 class B { | 15 class B { |
17 String foo; | 16 String foo; |
18 } | 17 } |
19 | 18 |
20 A makeA() native ; | 19 A makeA() native ; |
21 B makeB() native ; | 20 B makeB() native ; |
22 | 21 |
23 void setup() native """ | 22 void setup() native """ |
24 function A() {} | 23 function A() {} |
25 | 24 |
26 function B() {} | 25 function B() {} |
27 | 26 |
28 makeA = function(){return new A;}; | 27 makeA = function(){return new A;}; |
29 makeB = function(){return new B;}; | 28 makeB = function(){return new B;}; |
| 29 |
| 30 self.nativeConstructor(A); |
| 31 self.nativeConstructor(B); |
30 """; | 32 """; |
31 | 33 |
32 expectThrows(action()) { | 34 expectThrows(action()) { |
33 bool threw = false; | 35 bool threw = false; |
34 try { | 36 try { |
35 action(); | 37 action(); |
36 } catch (e) { | 38 } catch (e) { |
37 threw = true; | 39 threw = true; |
38 } | 40 } |
39 Expect.isTrue(threw); | 41 Expect.isTrue(threw); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 try { | 104 try { |
103 String s = a; | 105 String s = a; |
104 return false; | 106 return false; |
105 } catch (e) { | 107 } catch (e) { |
106 // Ignore. | 108 // Ignore. |
107 } | 109 } |
108 return true; | 110 return true; |
109 } | 111 } |
110 | 112 |
111 main() { | 113 main() { |
| 114 nativeTesting(); |
112 setup(); | 115 setup(); |
113 | 116 |
114 if (isCheckedMode()) { | 117 if (isCheckedMode()) { |
115 checkedModeTest(); | 118 checkedModeTest(); |
116 } else { | 119 } else { |
117 uncheckedModeTest(); | 120 uncheckedModeTest(); |
118 } | 121 } |
119 } | 122 } |
OLD | NEW |