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

Side by Side Diff: dart/tests/compiler/dart2js_foreign/native_call_arity3_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) 2012, 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 similar to NativeCallArity1FrogTest, but with default values to
6 // parameters set to null. These parameters should be treated as if they
7 // do not have a default value for the native methods.
8
9 import "package:expect/expect.dart";
10 import 'native_metadata.dart';
11
12 @Native("*A")
13 class A {
14 @native int foo(int x);
15 }
16
17 @Native("*B")
18 class B {
19 @native int foo([x = null, y, z = null]);
20 }
21
22 // TODO(sra): Add a case where the parameters have default values. Wait until
23 // dart:html need non-null default values.
24
25 @native A makeA() { return new A(); }
26 @native B makeB() { return new B(); }
27
28 @Native("""
29 function A() {}
30 A.prototype.foo = function () { return arguments.length; };
31
32 function B() {}
33 B.prototype.foo = function () { return arguments.length; };
34
35 makeA = function(){return new A;};
36 makeB = function(){return new B;};
37 """)
38 void setup();
39
40
41 testDynamicContext() {
42 var things = [makeA(), makeB()];
43 var a = things[0];
44 var b = things[1];
45
46 Expect.throws(() => a.foo());
47 Expect.equals(1, a.foo(10));
48 Expect.throws(() => a.foo(10, 20));
49 Expect.throws(() => a.foo(10, 20, 30));
50
51 Expect.equals(0, b.foo());
52 Expect.equals(1, b.foo(10));
53 Expect.equals(2, b.foo(10, 20));
54 Expect.equals(3, b.foo(10, 20, 30));
55
56 Expect.equals(1, b.foo(x: 10)); // 1 = x
57 Expect.equals(2, b.foo(y: 20)); // 2 = x, y
58 Expect.equals(3, b.foo(z: 30)); // 3 = x, y, z
59 Expect.throws(() => b.foo(10, 20, 30, 40));
60 }
61
62 testStaticContext() {
63 A a = makeA();
64 B b = makeB();
65
66 Expect.throws(() => a.foo());
67 Expect.equals(1, a.foo(10));
68 Expect.throws(() => a.foo(10, 20));
69 Expect.throws(() => a.foo(10, 20, 30));
70
71 Expect.equals(0, b.foo());
72 Expect.equals(1, b.foo(10));
73 Expect.equals(2, b.foo(10, 20));
74 Expect.equals(3, b.foo(10, 20, 30));
75
76 Expect.equals(1, b.foo(x: 10));
77 Expect.equals(2, b.foo(y: 20));
78 Expect.equals(3, b.foo(z: 30));
79 Expect.throws(() => b.foo(10, 20, 30, 40));
80 }
81
82 main() {
83 setup();
84 testDynamicContext();
85 testStaticContext();
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698