OLD | NEW |
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 "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; |
6 | 7 |
7 // Test that native methods with unnamed* optional arguments are called with the | 8 // Test that native methods with unnamed* optional arguments are called with the |
8 // number of arguments in the call site. This is necessary because native | 9 // number of arguments in the call site. This is necessary because native |
9 // methods can dispatch on the number of arguments. Passing null or undefined | 10 // methods can dispatch on the number of arguments. Passing null or undefined |
10 // as the last argument is not the same as passing one fewer argument. | 11 // as the last argument is not the same as passing one fewer argument. |
11 // | 12 // |
12 // * Optional positional arguments are passed in the correct position, so | 13 // * Optional positional arguments are passed in the correct position, so |
13 // require preceding arguments to be passed. | 14 // require preceding arguments to be passed. |
14 | 15 |
15 @Native("A") | 16 @Native("A") |
(...skipping 14 matching lines...) Expand all Loading... |
30 | 31 |
31 void setup() native """ | 32 void setup() native """ |
32 function A() {} | 33 function A() {} |
33 A.prototype.foo = function () { return arguments.length; }; | 34 A.prototype.foo = function () { return arguments.length; }; |
34 | 35 |
35 function B() {} | 36 function B() {} |
36 B.prototype.foo = function () { return arguments.length; }; | 37 B.prototype.foo = function () { return arguments.length; }; |
37 | 38 |
38 makeA = function(){return new A;}; | 39 makeA = function(){return new A;}; |
39 makeB = function(){return new B;}; | 40 makeB = function(){return new B;}; |
40 | |
41 self.nativeConstructor(A); | |
42 self.nativeConstructor(B); | |
43 """; | 41 """; |
44 | 42 |
45 testDynamicContext() { | 43 testDynamicContext() { |
46 var a = confuse(makeA()); | 44 var things = [makeA(), makeB()]; |
47 var b = confuse(makeB()); | 45 var a = things[0]; |
| 46 var b = things[1]; |
48 | 47 |
49 Expect.throws(() => a.foo()); | 48 Expect.throws(() => a.foo()); |
50 Expect.equals(1, a.foo(10)); | 49 Expect.equals(1, a.foo(10)); |
51 Expect.throws(() => a.foo(10, 20)); | 50 Expect.throws(() => a.foo(10, 20)); |
52 Expect.throws(() => a.foo(10, 20, 30)); | 51 Expect.throws(() => a.foo(10, 20, 30)); |
53 | 52 |
54 Expect.equals(0, b.foo()); | 53 Expect.equals(0, b.foo()); |
55 Expect.equals(1, b.foo(10)); | 54 Expect.equals(1, b.foo(10)); |
56 Expect.equals(2, b.foo(10, 20)); | 55 Expect.equals(2, b.foo(10, 20)); |
57 Expect.equals(3, b.foo(10, 20, 30)); | 56 Expect.equals(3, b.foo(10, 20, 30)); |
(...skipping 12 matching lines...) Expand all Loading... |
70 | 69 |
71 Expect.equals(0, b.foo()); | 70 Expect.equals(0, b.foo()); |
72 Expect.equals(1, b.foo(10)); | 71 Expect.equals(1, b.foo(10)); |
73 Expect.equals(2, b.foo(10, 20)); | 72 Expect.equals(2, b.foo(10, 20)); |
74 Expect.equals(3, b.foo(10, 20, 30)); | 73 Expect.equals(3, b.foo(10, 20, 30)); |
75 | 74 |
76 Expect.throws(() => b.foo(10, 20, 30, 40)); | 75 Expect.throws(() => b.foo(10, 20, 30, 40)); |
77 } | 76 } |
78 | 77 |
79 main() { | 78 main() { |
80 nativeTesting(); | |
81 setup(); | 79 setup(); |
82 testDynamicContext(); | 80 testDynamicContext(); |
83 testStaticContext(); | 81 testStaticContext(); |
84 } | 82 } |
OLD | NEW |