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 hidden native exception classes can be marked as existing. | 5 // Test that hidden native exception classes can be marked as existing. |
6 // | 6 // |
7 // To infer which native hidden types exist, we need | 7 // To infer which native hidden types exist, we need |
8 // (1) return types of native methods and getters | 8 // (1) return types of native methods and getters |
9 // (2) argument types of callbacks | 9 // (2) argument types of callbacks |
10 // (3) exceptions thrown by the operation. | 10 // (3) exceptions thrown by the operation. |
11 // | 11 // |
12 // (1) and (2) can be achieved by having nicely typed native methods, but there | 12 // (1) and (2) can be achieved by having nicely typed native methods, but there |
13 // is no place in the Dart language to communicate (3). So we use the following | 13 // is no place in the Dart language to communicate (3). So we use the following |
14 // fake body technique. | 14 // fake body technique. |
15 | 15 |
16 import "package:expect/expect.dart"; | |
17 import 'native_metadata.dart'; | 16 import 'native_metadata.dart'; |
18 | 17 |
19 // The exception type. | 18 // The exception type. |
20 @Native("*E") | 19 @Native("*E") |
21 class E { | 20 class E { |
22 @native E._used(); // Bogus native constructor, called only from fake body. | 21 @native E._used(); // Bogus native constructor, called only from fake body. |
23 | 22 |
24 final int code; | 23 final int code; |
25 } | 24 } |
26 | 25 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 threw = false; | 95 threw = false; |
97 try { | 96 try { |
98 var x = aa.op(51); | 97 var x = aa.op(51); |
99 } on E catch (e) { | 98 } on E catch (e) { |
100 threw = true; | 99 threw = true; |
101 Expect.equals(100, e.code); | 100 Expect.equals(100, e.code); |
102 Expect.isTrue(e is E); | 101 Expect.isTrue(e is E); |
103 } | 102 } |
104 Expect.isTrue(threw); | 103 Expect.isTrue(threw); |
105 } | 104 } |
OLD | NEW |