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