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

Side by Side Diff: tests/compiler/dart2js_native/native_call_arity2_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 // This is a similar test to NativeCallArity1FrogTest, but makes sure 7 // This is a similar test to NativeCallArity1FrogTest, but makes sure
8 // that subclasses also get the right number of arguments. 8 // that subclasses also get the right number of arguments.
9 9
10 @Native("A") 10 @Native("A")
11 class A { 11 class A {
12 int foo([x, y]) native; 12 int foo([x, y]) native;
13 } 13 }
14 14
15 @Native("B") 15 @Native("B")
16 class B extends A { 16 class B extends A {
17 int foo([x, y]) native; 17 int foo([x, y]) native;
18 } 18 }
19 19
20 makeA() native; 20 makeA() native;
21 makeB() native; 21 makeB() native;
22 22
23 void setup() native """ 23 void setup() {
24 function inherits(child, parent) { 24 JS('', r"""
25 if (child.prototype.__proto__) { 25 (function(){
26 child.prototype.__proto__ = parent.prototype; 26 function inherits(child, parent) {
27 } else { 27 if (child.prototype.__proto__) {
28 function tmp() {}; 28 child.prototype.__proto__ = parent.prototype;
29 tmp.prototype = parent.prototype; 29 } else {
30 child.prototype = new tmp(); 30 function tmp() {};
31 child.prototype.constructor = child; 31 tmp.prototype = parent.prototype;
32 child.prototype = new tmp();
33 child.prototype.constructor = child;
34 }
32 } 35 }
36 function A() {}
37 A.prototype.foo = function () { return arguments.length; };
38
39 function B() {}
40 B.prototype.foo = function () { return arguments.length; };
41 inherits(B, A);
42
43 makeA = function(){return new A()};
44 makeB = function(){return new B()};
45
46 self.nativeConstructor(A);
47 self.nativeConstructor(B);
48 })()""");
33 } 49 }
34 function A() {}
35 A.prototype.foo = function () { return arguments.length; };
36
37 function B() {}
38 B.prototype.foo = function () { return arguments.length; };
39 inherits(B, A);
40
41 makeA = function(){return new A;};
42 makeB = function(){return new B;};
43
44 self.nativeConstructor(A);
45 self.nativeConstructor(B);
46 """;
47 50
48 testDynamicContext() { 51 testDynamicContext() {
49 var a = confuse(makeA()); 52 var a = confuse(makeA());
50 var b = confuse(makeB()); 53 var b = confuse(makeB());
51 54
52 Expect.equals(0, a.foo()); 55 Expect.equals(0, a.foo());
53 Expect.equals(1, a.foo(10)); 56 Expect.equals(1, a.foo(10));
54 Expect.equals(2, a.foo(10, 20)); 57 Expect.equals(2, a.foo(10, 20));
55 Expect.throws(() => a.foo(10, 20, 30)); 58 Expect.throws(() => a.foo(10, 20, 30));
56 59
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Expect.equals(2, b.foo(null, 20)); 93 Expect.equals(2, b.foo(null, 20));
91 Expect.throws(() => b.foo(10, 20, 30)); 94 Expect.throws(() => b.foo(10, 20, 30));
92 } 95 }
93 96
94 main() { 97 main() {
95 nativeTesting(); 98 nativeTesting();
96 setup(); 99 setup();
97 testDynamicContext(); 100 testDynamicContext();
98 testStaticContext(); 101 testStaticContext();
99 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698