OLD | NEW |
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 library test.type_error_decode_test; | 5 library test.type_error_decode_test; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'native_testing.dart'; |
8 | 8 import 'dart:_js_helper' show NullError, JsNoSuchMethodError; |
9 import 'dart:_js_helper'; | |
10 | 9 |
11 class Foo { | 10 class Foo { |
12 var field; | 11 var field; |
13 } | 12 } |
14 | 13 |
15 isNullError(e, trace) { | 14 isNullError(e, trace) { |
16 print('$e\nTrace: $trace'); | 15 print('$e\nTrace: $trace'); |
17 return e is NullError; | 16 return e is NullError; |
18 } | 17 } |
19 | 18 |
(...skipping 14 matching lines...) Expand all Loading... |
34 throw 'No exception thrown'; | 33 throw 'No exception thrown'; |
35 } | 34 } |
36 | 35 |
37 main() { | 36 main() { |
38 var x = null; | 37 var x = null; |
39 var z = new Object(); | 38 var z = new Object(); |
40 var v = new List(1)[0]; | 39 var v = new List(1)[0]; |
41 var s = "Cannot call method 'foo' of null"; | 40 var s = "Cannot call method 'foo' of null"; |
42 var nul = null; | 41 var nul = null; |
43 var f = new Foo(); | 42 var f = new Foo(); |
44 // This should foil code analysis so the variables aren't inlined below. | 43 |
45 [].forEach((y) => f.field = nul = s = x = z = v = y); | |
46 expectThrows(() => x.fisk(), isNullError); | 44 expectThrows(() => x.fisk(), isNullError); |
47 expectThrows(() => v.fisk(), isNullError); | 45 expectThrows(() => v.fisk(), isNullError); |
48 expectThrows(() => z.fisk(), isJsNoSuchMethodError); | 46 expectThrows(() => z.fisk(), isJsNoSuchMethodError); |
49 expectThrows(() => s.fisk(), isJsNoSuchMethodError); | 47 expectThrows(() => s.fisk(), isJsNoSuchMethodError); |
50 expectThrows(() => null(), isNullError); | 48 expectThrows(() => null(), isNullError); |
51 expectThrows(() => f.field(), isNullError); | 49 expectThrows(() => f.field(), isNullError); |
| 50 |
| 51 expectThrows(() => confuse(x).fisk(), isNullError); |
| 52 expectThrows(() => confuse(v).fisk(), isNullError); |
| 53 expectThrows(() => confuse(z).fisk(), isJsNoSuchMethodError); |
| 54 expectThrows(() => confuse(s).fisk(), isJsNoSuchMethodError); |
| 55 expectThrows(() => confuse(null)(), isNullError); |
| 56 expectThrows(() => confuse(f).field(), isNullError); |
| 57 expectThrows(() => confuse(f.field)(), isNullError); |
52 } | 58 } |
OLD | NEW |