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