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

Side by Side Diff: tests/compiler/dart2js_native/native_class_inheritance1_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 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
8 // subsequent resolving the subclass's method. This might happen if the 8 // subsequent resolving the subclass's method. This might happen if the
9 // superclass caches the method in the prototype, so shadowing the dispatcher 9 // superclass caches the method in the prototype, so shadowing the dispatcher
10 // stored on Object.prototype. 10 // stored on Object.prototype.
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 @Native("B2") 32 @Native("B2")
33 class B2 extends A2 { 33 class B2 extends A2 {
34 foo([z = 1000]) native; 34 foo([z = 1000]) native;
35 } 35 }
36 36
37 makeA2() native; 37 makeA2() native;
38 makeB2() native; 38 makeB2() native;
39 39
40 void setup() native """ 40 void setup() {
41 // This code is all inside 'setup' and so not accessible from the global scope. 41 JS('', r"""
42 function inherits(child, parent) { 42 (function(){
43 if (child.prototype.__proto__) { 43 // This code is inside 'setup' and so not accessible from the global scope.
44 child.prototype.__proto__ = parent.prototype; 44 function inherits(child, parent) {
45 } else { 45 if (child.prototype.__proto__) {
46 function tmp() {}; 46 child.prototype.__proto__ = parent.prototype;
47 tmp.prototype = parent.prototype; 47 } else {
48 child.prototype = new tmp(); 48 function tmp() {};
49 child.prototype.constructor = child; 49 tmp.prototype = parent.prototype;
50 child.prototype = new tmp();
51 child.prototype.constructor = child;
52 }
50 } 53 }
54 function A1(){}
55 function B1(){}
56 inherits(B1, A1);
57 A1.prototype.foo = function(){return 100;};
58 B1.prototype.foo = function(){return 200;};
59
60 makeA1 = function(){return new A1()};
61 makeB1 = function(){return new B1()};
62
63 function A2(){}
64 function B2(){}
65 inherits(B2, A2);
66 A2.prototype.foo = function(a){return a + 10000;};
67 B2.prototype.foo = function(z){return z + 20000;};
68
69 makeA2 = function(){return new A2()};
70 makeB2 = function(){return new B2()};
71
72 self.nativeConstructor(A1);
73 self.nativeConstructor(A2);
74 self.nativeConstructor(B1);
75 self.nativeConstructor(B2);
76 })()""");
51 } 77 }
52 function A1(){}
53 function B1(){}
54 inherits(B1, A1);
55 A1.prototype.foo = function(){return 100;}
56 B1.prototype.foo = function(){return 200;}
57
58 makeA1 = function(){return new A1};
59 makeB1 = function(){return new B1};
60
61 function A2(){}
62 function B2(){}
63 inherits(B2, A2);
64 A2.prototype.foo = function(a){return a + 10000;}
65 B2.prototype.foo = function(z){return z + 20000;}
66
67 makeA2 = function(){return new A2};
68 makeB2 = function(){return new B2};
69
70 self.nativeConstructor(A1);
71 self.nativeConstructor(A2);
72 self.nativeConstructor(B1);
73 self.nativeConstructor(B2);
74 """;
75 78
76 main() { 79 main() {
77 nativeTesting(); 80 nativeTesting();
78 setup(); 81 setup();
79 82
80 var a1 = makeA1(); 83 var a1 = makeA1();
81 var b1 = makeB1(); 84 var b1 = makeB1();
82 Expect.equals(100, a1.foo()); 85 Expect.equals(100, a1.foo());
83 Expect.equals(200, b1.foo()); 86 Expect.equals(200, b1.foo());
84 87
(...skipping 17 matching lines...) Expand all
102 caught = false; 105 caught = false;
103 try { 106 try {
104 var x = 123; 107 var x = 123;
105 x.foo(20); 108 x.foo(20);
106 } catch (ex) { 109 } catch (ex) {
107 caught = true; 110 caught = true;
108 Expect.isTrue(ex is NoSuchMethodError); 111 Expect.isTrue(ex is NoSuchMethodError);
109 } 112 }
110 Expect.isTrue(caught, "x.foo(20) should throw"); 113 Expect.isTrue(caught, "x.foo(20) should throw");
111 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698