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