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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_call_arity1_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 // Test that native methods with unnamed* optional arguments are called with the
6 // number of arguments in the call site. This is necessary because native
7 // methods can dispatch on the number of arguments. Passing null or undefined
8 // as the last argument is not the same as passing one fewer argument.
9 //
10 // * Named arguments are passed in the correct position, so require preceding
11 // arguments to be passed.
12
13 import "package:expect/expect.dart";
14 import 'native_metadata.dart';
15
16 @Native("*A")
17 class A {
18 @native int foo(int x);
19 }
20
21 @Native("*B")
22 class B {
23 @native int foo([x, y, z]);
24 }
25
26 // TODO(sra): Add a case where the parameters have default values. Wait until
27 // dart:html need non-null default values.
28
29 @native A makeA() { return new A(); }
30 @native B makeB() { return new B(); }
31
32 @Native("""
33 function A() {}
34 A.prototype.foo = function () { return arguments.length; };
35
36 function B() {}
37 B.prototype.foo = function () { return arguments.length; };
38
39 makeA = function(){return new A;};
40 makeB = function(){return new B;};
41 """)
42 void setup();
43
44
45 testDynamicContext() {
46 var things = [makeA(), makeB()];
47 var a = things[0];
48 var b = things[1];
49
50 Expect.throws(() => a.foo());
51 Expect.equals(1, a.foo(10));
52 Expect.throws(() => a.foo(10, 20));
53 Expect.throws(() => a.foo(10, 20, 30));
54
55 Expect.equals(0, b.foo());
56 Expect.equals(1, b.foo(10));
57 Expect.equals(2, b.foo(10, 20));
58 Expect.equals(3, b.foo(10, 20, 30));
59
60 Expect.equals(1, b.foo(x: 10)); // 1 = x
61 Expect.equals(2, b.foo(y: 20)); // 2 = x, y
62 Expect.equals(3, b.foo(z: 30)); // 3 = x, y, z
63 Expect.throws(() => b.foo(10, 20, 30, 40));
64 }
65
66 testStaticContext() {
67 A a = makeA();
68 B b = makeB();
69
70 Expect.throws(() => a.foo());
71 Expect.equals(1, a.foo(10));
72 Expect.throws(() => a.foo(10, 20));
73 Expect.throws(() => a.foo(10, 20, 30));
74
75 Expect.equals(0, b.foo());
76 Expect.equals(1, b.foo(10));
77 Expect.equals(2, b.foo(10, 20));
78 Expect.equals(3, b.foo(10, 20, 30));
79
80 Expect.equals(1, b.foo(x: 10));
81 Expect.equals(2, b.foo(y: 20));
82 Expect.equals(3, b.foo(z: 30));
83 Expect.throws(() => b.foo(10, 20, 30, 40));
84 }
85
86 main() {
87 setup();
88 testDynamicContext();
89 testStaticContext();
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698