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

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

Issue 2984403002: dart2js_native tests: Migrate 'native STRING' to JS-calls (Closed)
Patch Set: the rest of the files Created 3 years, 4 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
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 'native_testing.dart'; 5 import 'native_testing.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
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 // 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.
36 class B { 36 class B {
37 int get code => 666; 37 int get code => 666;
38 op(String x) => 123; 38 op(String x) => 123;
39 } 39 }
40 40
41 makeA() native; 41 makeA() native;
42 42
43 void setup1() native """ 43 void setup1() {
44 // Ensure we are not relying on global names 'A' and 'E'. 44 JS('', r"""
45 A = null; 45 (function(){
46 E = null; 46 // Ensure we are not relying on global names 'A' and 'E'.
47 """; 47 A = null;
48 E = null;
49 })()""");
50 }
48 51
49 void setup2() native """ 52 void setup2() {
53 JS('', r"""
54 (function(){
50 // This code is all inside 'setup2' and so not accessible from the global scope. 55 // This code is all inside 'setup2' and so not accessible from the global scope.
51 function E(x){ this.code = x; } 56 function E(x){ this.code = x; }
52 57
53 function A(){} 58 function A(){}
54 A.prototype.op = function (x) { 59 A.prototype.op = function (x) {
55 if (x & 1) throw new E(100); 60 if (x & 1) throw new E(100);
56 return x / 2; 61 return x / 2;
57 }; 62 };
58 makeA = function(){return new A}; 63 makeA = function(){return new A()};
59 64
60 self.nativeConstructor(E); 65 self.nativeConstructor(E);
61 self.nativeConstructor(A); 66 self.nativeConstructor(A);
62 """; 67 })()""");
68 }
63 69
64 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); 70 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
65 71
66 main() { 72 main() {
67 nativeTesting(); 73 nativeTesting();
68 setup1(); 74 setup1();
69 setup2(); 75 setup2();
70 76
71 var things = [makeA(), new B()]; 77 var things = [makeA(), new B()];
72 var a = things[inscrutable(0)]; 78 var a = things[inscrutable(0)];
(...skipping 24 matching lines...) Expand all
97 threw = false; 103 threw = false;
98 try { 104 try {
99 var x = aa.op(51); 105 var x = aa.op(51);
100 } on E catch (e) { 106 } on E catch (e) {
101 threw = true; 107 threw = true;
102 Expect.equals(100, e.code); 108 Expect.equals(100, e.code);
103 Expect.isTrue(e is E); 109 Expect.isTrue(e is E);
104 } 110 }
105 Expect.isTrue(threw); 111 Expect.isTrue(threw);
106 } 112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698