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

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

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 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
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 'native_testing.dart';
6 import "package:expect/expect.dart";
7 6
8 // Test that hidden native exception classes can be marked as existing. 7 // Test that hidden native exception classes can be marked as existing.
9 // 8 //
10 // To infer which native hidden types exist, we need 9 // To infer which native hidden types exist, we need
11 // (1) return types of native methods and getters 10 // (1) return types of native methods and getters
12 // (2) argument types of callbacks 11 // (2) argument types of callbacks
13 // (3) exceptions thrown by the operation. 12 // (3) exceptions thrown by the operation.
14 // 13 //
15 // (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
16 // 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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 void setup2() native """ 49 void setup2() native """
51 // This code is all inside 'setup2' and so not accesible from the global scope. 50 // This code is all inside 'setup2' and so not accesible from the global scope.
52 function E(x){ this.code = x; } 51 function E(x){ this.code = x; }
53 52
54 function A(){} 53 function A(){}
55 A.prototype.op = function (x) { 54 A.prototype.op = function (x) {
56 if (x & 1) throw new E(100); 55 if (x & 1) throw new E(100);
57 return x / 2; 56 return x / 2;
58 }; 57 };
59 makeA = function(){return new A}; 58 makeA = function(){return new A};
59
60 self.nativeConstructor(E);
61 self.nativeConstructor(A);
60 """; 62 """;
61 63
62 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); 64 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
63 65
64 main() { 66 main() {
67 nativeTesting();
65 setup1(); 68 setup1();
66 setup2(); 69 setup2();
67 70
68 var things = [makeA(), new B()]; 71 var things = [makeA(), new B()];
69 var a = things[inscrutable(0)]; 72 var a = things[inscrutable(0)];
70 var b = things[inscrutable(1)]; 73 var b = things[inscrutable(1)];
71 74
72 Expect.equals(25, a.op(50)); 75 Expect.equals(25, a.op(50));
73 Expect.equals(123, b.op('hello')); 76 Expect.equals(123, b.op('hello'));
74 Expect.equals(666, b.code); 77 Expect.equals(666, b.code);
(...skipping 19 matching lines...) Expand all
94 threw = false; 97 threw = false;
95 try { 98 try {
96 var x = aa.op(51); 99 var x = aa.op(51);
97 } on E catch (e) { 100 } on E catch (e) {
98 threw = true; 101 threw = true;
99 Expect.equals(100, e.code); 102 Expect.equals(100, e.code);
100 Expect.isTrue(e is E); 103 Expect.isTrue(e is E);
101 } 104 }
102 Expect.isTrue(threw); 105 Expect.isTrue(threw);
103 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698