Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/compiler/dart2js_native/native_exceptions1_frog_test.dart

Issue 383413003: Add @Native(...) annotation for native class names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "dart:_js_helper";
5 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
6 7
7 // Test that hidden native exception classes can be marked as existing. 8 // Test that hidden native exception classes can be marked as existing.
8 // 9 //
9 // To infer which native hidden types exist, we need 10 // To infer which native hidden types exist, we need
10 // (1) return types of native methods and getters 11 // (1) return types of native methods and getters
11 // (2) argument types of callbacks 12 // (2) argument types of callbacks
12 // (3) exceptions thrown by the operation. 13 // (3) exceptions thrown by the operation.
13 // 14 //
14 // (1) and (2) can be achieved by having nicely typed native methods, but there 15 // (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 16 // is no place in the Dart language to communicate (3). So we use the following
16 // fake body technique. 17 // fake body technique.
17 18
18 19
19 // The exception type. 20 // The exception type.
20 class E native "E" { 21 @Native("E")
22 class E {
21 E._used() native; // Bogus native constructor, called only from fake body. 23 E._used() native; // Bogus native constructor, called only from fake body.
22 24
23 final int code; 25 final int code;
24 } 26 }
25 27
26 // Type with exception-throwing methods. 28 // Type with exception-throwing methods.
27 class A native "A" { 29 @Native("A")
30 class A {
28 op(int x) native { 31 op(int x) native {
29 // Fake body calls constructor to mark the exception class (E) as used. 32 // Fake body calls constructor to mark the exception class (E) as used.
30 throw new E._used(); 33 throw new E._used();
31 } 34 }
32 } 35 }
33 36
34 // This class is here just so that a dynamic context is polymorphic. 37 // This class is here just so that a dynamic context is polymorphic.
35 class B { 38 class B {
36 int get code => 666; 39 int get code => 666;
37 op(String x) => 123; 40 op(String x) => 123;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 threw = false; 95 threw = false;
93 try { 96 try {
94 var x = aa.op(51); 97 var x = aa.op(51);
95 } on E catch (e) { 98 } on E catch (e) {
96 threw = true; 99 threw = true;
97 Expect.equals(100, e.code); 100 Expect.equals(100, e.code);
98 Expect.isTrue(e is E); 101 Expect.isTrue(e is E);
99 } 102 }
100 Expect.isTrue(threw); 103 Expect.isTrue(threw);
101 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698