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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_exceptions1_test.dart

Issue 11293272: Update dart2js_foreign suite as we now validate annotations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 1 month 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 // 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 'native_metadata.dart';
16 17
17 // The exception type. 18 // The exception type.
18 @native("*E") 19 @Native("*E")
19 class E { 20 class E {
20 @native E._used(); // Bogus native constructor, called only from fake body. 21 @native E._used(); // Bogus native constructor, called only from fake body.
21 22
22 final int code; 23 final int code;
23 } 24 }
24 25
25 // Type with exception-throwing methods. 26 // Type with exception-throwing methods.
26 @native("*A") 27 @Native("*A")
27 class A { 28 class A {
28 @native op(int x) { 29 @native op(int x) {
29 // Fake body calls constructor to mark the exception class (E) as used. 30 // Fake body calls constructor to mark the exception class (E) as used.
30 throw new E._used(); 31 throw new E._used();
31 } 32 }
32 } 33 }
33 34
34 // This class is here just so that a dynamic context is polymorphic. 35 // This class is here just so that a dynamic context is polymorphic.
35 class B { 36 class B {
36 int get code => 666; 37 int get code => 666;
37 op(String x) => 123; 38 op(String x) => 123;
38 } 39 }
39 40
40 @native makeA(); 41 @native makeA();
41 42
42 @native(""" 43 @Native("""
43 // Ensure we are not relying on global names 'A' and 'E'. 44 // Ensure we are not relying on global names 'A' and 'E'.
44 A = null; 45 A = null;
45 E = null; 46 E = null;
46 """) 47 """)
47 void setup1(); 48 void setup1();
48 49
49 @native(""" 50 @Native("""
50 // This code is all inside 'setup2' and so not accesible from the global scope. 51 // This code is all inside 'setup2' and so not accesible from the global scope.
51 function E(x){ this.code = x; } 52 function E(x){ this.code = x; }
52 53
53 function A(){} 54 function A(){}
54 A.prototype.op = function (x) { 55 A.prototype.op = function (x) {
55 if (x & 1) throw new E(100); 56 if (x & 1) throw new E(100);
56 return x / 2; 57 return x / 2;
57 }; 58 };
58 makeA = function(){return new A}; 59 makeA = function(){return new A};
59 """) 60 """)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 threw = false; 95 threw = false;
95 try { 96 try {
96 var x = aa.op(51); 97 var x = aa.op(51);
97 } on E catch (e) { 98 } on E catch (e) {
98 threw = true; 99 threw = true;
99 Expect.equals(100, e.code); 100 Expect.equals(100, e.code);
100 Expect.isTrue(e is E); 101 Expect.isTrue(e is E);
101 } 102 }
102 Expect.isTrue(threw); 103 Expect.isTrue(threw);
103 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698