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

Side by Side Diff: tests/compiler/dart2js_native/native_class_inheritance1_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 to see if resolving a hidden native class's method interferes with 7 // Test to see if resolving a hidden native class's method interferes with
9 // subsequent resolving the subclass's method. This might happen if the 8 // subsequent resolving the subclass's method. This might happen if the
10 // superclass caches the method in the prototype, so shadowing the dispatcher 9 // superclass caches the method in the prototype, so shadowing the dispatcher
11 // stored on Object.prototype. 10 // stored on Object.prototype.
12 11
13 // Version 1: It might be possible to call foo directly. 12 // Version 1: It might be possible to call foo directly.
14 @Native("A1") 13 @Native("A1")
15 class A1 { 14 class A1 {
16 foo() native ; 15 foo() native ;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 makeB1 = function(){return new B1}; 59 makeB1 = function(){return new B1};
61 60
62 function A2(){} 61 function A2(){}
63 function B2(){} 62 function B2(){}
64 inherits(B2, A2); 63 inherits(B2, A2);
65 A2.prototype.foo = function(a){return a + 10000;} 64 A2.prototype.foo = function(a){return a + 10000;}
66 B2.prototype.foo = function(z){return z + 20000;} 65 B2.prototype.foo = function(z){return z + 20000;}
67 66
68 makeA2 = function(){return new A2}; 67 makeA2 = function(){return new A2};
69 makeB2 = function(){return new B2}; 68 makeB2 = function(){return new B2};
69
70 self.nativeConstructor(A1);
71 self.nativeConstructor(A2);
72 self.nativeConstructor(B1);
73 self.nativeConstructor(B2);
70 """; 74 """;
71 75
72 main() { 76 main() {
77 nativeTesting();
73 setup(); 78 setup();
74 79
75 var a1 = makeA1(); 80 var a1 = makeA1();
76 var b1 = makeB1(); 81 var b1 = makeB1();
77 Expect.equals(100, a1.foo()); 82 Expect.equals(100, a1.foo());
78 Expect.equals(200, b1.foo()); 83 Expect.equals(200, b1.foo());
79 84
80 var a2 = makeA2(); 85 var a2 = makeA2();
81 var b2 = makeB2(); 86 var b2 = makeB2();
82 Expect.equals(10000 + 99, a2.foo()); 87 Expect.equals(10000 + 99, a2.foo());
(...skipping 14 matching lines...) Expand all
97 caught = false; 102 caught = false;
98 try { 103 try {
99 var x = 123; 104 var x = 123;
100 x.foo(20); 105 x.foo(20);
101 } catch (ex) { 106 } catch (ex) {
102 caught = true; 107 caught = true;
103 Expect.isTrue(ex is NoSuchMethodError); 108 Expect.isTrue(ex is NoSuchMethodError);
104 } 109 }
105 Expect.isTrue(caught, "x.foo(20) should throw"); 110 Expect.isTrue(caught, "x.foo(20) should throw");
106 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698