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