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 | 16 |
17 // The exception type. | 17 // The exception type. |
18 @native("*E") | 18 @native("*E") |
19 class E { | 19 class E { |
20 @native E._used(); // Bogus native constructor, called only from fake body. | 20 @native E._used(); // Bogus native constructor, called only from fake body. |
21 | 21 |
22 final int code; | 22 final int code; |
23 } | 23 } |
24 | 24 |
25 // Type with exception-throwing methods. | 25 // Type with exception-throwing methods. |
26 @native("*A") | 26 @native("*A") |
27 class A { | 27 class A { |
28 @native op(int x) { | 28 @native op(int x) { |
29 // Fake body calls constructor to mark the exception class (E) as used. | 29 // Fake body calls constructor to mark the exception class (E) as used. |
30 throw new E._used(); | 30 throw new E._used(); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 // This class is here just so that a dynamic context is polymorphic. | 34 // This class is here just so that a dynamic context is polymorphic. |
35 class B { | 35 class B { |
36 int get code => 666; | 36 int get code => 666; |
37 op(String x) => 123; | 37 op(String x) => 123; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 threw = false; | 94 threw = false; |
95 try { | 95 try { |
96 var x = aa.op(51); | 96 var x = aa.op(51); |
97 } on E catch (e) { | 97 } on E catch (e) { |
98 threw = true; | 98 threw = true; |
99 Expect.equals(100, e.code); | 99 Expect.equals(100, e.code); |
100 Expect.isTrue(e is E); | 100 Expect.isTrue(e is E); |
101 } | 101 } |
102 Expect.isTrue(threw); | 102 Expect.isTrue(threw); |
103 } | 103 } |
OLD | NEW |