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

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

Issue 2383273002: Revert "Add native_testing library to mock @Native classes" (Closed)
Patch Set: Created 4 years, 2 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 "dart:_js_helper";
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 void setup2() native """ 50 void setup2() 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 self.nativeConstructor(E);
61 self.nativeConstructor(A);
62 """; 60 """;
63 61
64 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); 62 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
65 63
66 main() { 64 main() {
67 nativeTesting();
68 setup1(); 65 setup1();
69 setup2(); 66 setup2();
70 67
71 var things = [makeA(), new B()]; 68 var things = [makeA(), new B()];
72 var a = things[inscrutable(0)]; 69 var a = things[inscrutable(0)];
73 var b = things[inscrutable(1)]; 70 var b = things[inscrutable(1)];
74 71
75 Expect.equals(25, a.op(50)); 72 Expect.equals(25, a.op(50));
76 Expect.equals(123, b.op('hello')); 73 Expect.equals(123, b.op('hello'));
77 Expect.equals(666, b.code); 74 Expect.equals(666, b.code);
(...skipping 19 matching lines...) Expand all
97 threw = false; 94 threw = false;
98 try { 95 try {
99 var x = aa.op(51); 96 var x = aa.op(51);
100 } on E catch (e) { 97 } on E catch (e) {
101 threw = true; 98 threw = true;
102 Expect.equals(100, e.code); 99 Expect.equals(100, e.code);
103 Expect.isTrue(e is E); 100 Expect.isTrue(e is E);
104 } 101 }
105 Expect.isTrue(threw); 102 Expect.isTrue(threw);
106 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698