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 that type checks occur on assignment to fields of native methods. | 5 // Test that type checks occur on assignment to fields of native methods. |
6 | 6 |
7 class A native "*A" { | 7 class A native "*A" { |
8 int foo; | 8 int foo; |
9 } | 9 } |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 function B() {} | 21 function B() {} |
22 | 22 |
23 makeA = function(){return new A;}; | 23 makeA = function(){return new A;}; |
24 makeB = function(){return new B;}; | 24 makeB = function(){return new B;}; |
25 """; | 25 """; |
26 | 26 |
27 expectThrows(action()) { | 27 expectThrows(action()) { |
28 bool threw = false; | 28 bool threw = false; |
29 try { | 29 try { |
30 action(); | 30 action(); |
31 } catch (var e) { | 31 } catch (e) { |
32 threw = true; | 32 threw = true; |
33 } | 33 } |
34 Expect.isTrue(threw); | 34 Expect.isTrue(threw); |
35 } | 35 } |
36 | 36 |
37 checkedModeTest() { | 37 checkedModeTest() { |
38 var things = [makeA(), makeB()]; | 38 var things = [makeA(), makeB()]; |
39 var a = things[0]; | 39 var a = things[0]; |
40 var b = things[1]; | 40 var b = things[1]; |
41 | 41 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Expect.equals(b.foo, 124); | 90 Expect.equals(b.foo, 124); |
91 } | 91 } |
92 | 92 |
93 bool isCheckedMode() { | 93 bool isCheckedMode() { |
94 var stuff = [1, 'string']; | 94 var stuff = [1, 'string']; |
95 var a = stuff[0]; | 95 var a = stuff[0]; |
96 // Checked-mode detection. | 96 // Checked-mode detection. |
97 try { | 97 try { |
98 String s = a; | 98 String s = a; |
99 return false; | 99 return false; |
100 } catch (var e) { } | 100 } catch (e) { |
| 101 // Ignore. |
| 102 } |
101 return true; | 103 return true; |
102 } | 104 } |
103 | 105 |
104 main() { | 106 main() { |
105 setup(); | 107 setup(); |
106 | 108 |
107 if (isCheckedMode()) { | 109 if (isCheckedMode()) { |
108 checkedModeTest(); | 110 checkedModeTest(); |
109 } else { | 111 } else { |
110 uncheckedModeTest(); | 112 uncheckedModeTest(); |
111 } | 113 } |
112 } | 114 } |
OLD | NEW |