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 "native_testing.dart"; |
6 | 6 |
7 // Test that native methods with unnamed* optional arguments are called with the | 7 // 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 | 8 // 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 | 9 // 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. | 10 // as the last argument is not the same as passing one fewer argument. |
11 // | 11 // |
12 // * Optional positional arguments are passed in the correct position, so | 12 // * Optional positional arguments are passed in the correct position, so |
13 // require preceding arguments to be passed. | 13 // require preceding arguments to be passed. |
14 | 14 |
15 @Native("A") | 15 @Native("A") |
16 class A { | 16 class A { |
17 int foo(int x) native ; | 17 int foo(int x) native; |
18 } | 18 } |
19 | 19 |
20 @Native("B") | 20 @Native("B") |
21 class B { | 21 class B { |
22 int foo([x, y, z]) native ; | 22 int foo([x, y, z]) native; |
23 } | 23 } |
24 | 24 |
25 // TODO(sra): Add a case where the parameters have default values. Wait until | 25 // TODO(sra): Add a case where the parameters have default values. Wait until |
26 // dart:html need non-null default values. | 26 // dart:html need non-null default values. |
27 | 27 |
28 A makeA() native ; | 28 A makeA() native; |
29 B makeB() native ; | 29 B makeB() native; |
30 | 30 |
31 void setup() native """ | 31 void setup() native """ |
32 function A() {} | 32 function A() {} |
33 A.prototype.foo = function () { return arguments.length; }; | 33 A.prototype.foo = function () { return arguments.length; }; |
34 | 34 |
35 function B() {} | 35 function B() {} |
36 B.prototype.foo = function () { return arguments.length; }; | 36 B.prototype.foo = function () { return arguments.length; }; |
37 | 37 |
38 makeA = function(){return new A;}; | 38 makeA = function(){return new A;}; |
39 makeB = function(){return new B;}; | 39 makeB = function(){return new B;}; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 Expect.throws(() => b.foo(10, 20, 30, 40)); | 76 Expect.throws(() => b.foo(10, 20, 30, 40)); |
77 } | 77 } |
78 | 78 |
79 main() { | 79 main() { |
80 nativeTesting(); | 80 nativeTesting(); |
81 setup(); | 81 setup(); |
82 testDynamicContext(); | 82 testDynamicContext(); |
83 testStaticContext(); | 83 testStaticContext(); |
84 } | 84 } |
OLD | NEW |