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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_call_arity2_test.dart

Issue 23477028: Remove dart2js_foreign. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This is a similar test to NativeCallArity1FrogTest, but makes sure
6 // that subclasses also get the right number of arguments.
7
8 import "package:expect/expect.dart";
9 import 'native_metadata.dart';
10
11 @Native("*A")
12 class A {
13 @native int foo([x, y]);
14 }
15
16 @Native("*B")
17 class B extends A {
18 @native int foo([x, y]);
19 }
20
21 @native A makeA() { return new A(); }
22 @native B makeB() { return new B(); }
23
24 @Native("""
25 function inherits(child, parent) {
26 if (child.prototype.__proto__) {
27 child.prototype.__proto__ = parent.prototype;
28 } else {
29 function tmp() {};
30 tmp.prototype = parent.prototype;
31 child.prototype = new tmp();
32 child.prototype.constructor = child;
33 }
34 }
35 function A() {}
36 A.prototype.foo = function () { return arguments.length; };
37
38 function B() {}
39 B.prototype.foo = function () { return arguments.length; };
40 inherits(B, A);
41
42 makeA = function(){return new A;};
43 makeB = function(){return new B;};
44 """)
45 void setup();
46
47
48 testDynamicContext() {
49 var things = [makeA(), makeB()];
50 var a = things[0];
51 var b = things[1];
52
53 Expect.equals(0, a.foo());
54 Expect.equals(1, a.foo(10));
55 Expect.equals(2, a.foo(10, 20));
56 Expect.throws(() => a.foo(10, 20, 30));
57
58 Expect.equals(1, a.foo(x: 10)); // 1 = x
59 Expect.equals(2, a.foo(y: 20)); // 2 = x, y
60 Expect.throws(() => a.foo(10, 20, 30));
61
62 Expect.equals(0, b.foo());
63 Expect.equals(1, b.foo(10));
64 Expect.equals(2, b.foo(10, 20));
65 Expect.throws(() => b.foo(10, 20, 30));
66
67 Expect.equals(1, b.foo(x: 10)); // 1 = x
68 Expect.equals(2, b.foo(y: 20)); // 2 = x, y
69 Expect.throws(() => b.foo(10, 20, 30));
70 }
71
72 testStaticContext() {
73 A a = makeA();
74 B b = makeB();
75
76 Expect.equals(0, a.foo());
77 Expect.equals(1, a.foo(10));
78 Expect.equals(2, a.foo(10, 20));
79 Expect.throws(() => a.foo(10, 20, 30));
80
81 Expect.equals(1, a.foo(x: 10)); // 1 = x
82 Expect.equals(2, a.foo(y: 20)); // 2 = x, y
83 Expect.throws(() => a.foo(10, 20, 30));
84
85 Expect.equals(0, b.foo());
86 Expect.equals(1, b.foo(10));
87 Expect.equals(2, b.foo(10, 20));
88 Expect.throws(() => b.foo(10, 20, 30));
89
90 Expect.equals(1, b.foo(x: 10)); // 1 = x
91 Expect.equals(2, b.foo(y: 20)); // 2 = x, y
92 Expect.throws(() => b.foo(10, 20, 30));
93 }
94
95 main() {
96 setup();
97 testDynamicContext();
98 testStaticContext();
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698