| 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. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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() { |
| 32 function A() {} | 32 JS('', r""" |
| 33 A.prototype.foo = function () { return arguments.length; }; | 33 (function(){ |
| 34 function A() {} |
| 35 A.prototype.foo = function () { return arguments.length; }; |
| 34 | 36 |
| 35 function B() {} | 37 function B() {} |
| 36 B.prototype.foo = function () { return arguments.length; }; | 38 B.prototype.foo = function () { return arguments.length; }; |
| 37 | 39 |
| 38 makeA = function(){return new A;}; | 40 makeA = function(){return new A()}; |
| 39 makeB = function(){return new B;}; | 41 makeB = function(){return new B()}; |
| 40 | 42 |
| 41 self.nativeConstructor(A); | 43 self.nativeConstructor(A); |
| 42 self.nativeConstructor(B); | 44 self.nativeConstructor(B); |
| 43 """; | 45 })()"""); |
| 46 } |
| 44 | 47 |
| 45 testDynamicContext() { | 48 testDynamicContext() { |
| 46 var a = confuse(makeA()); | 49 var a = confuse(makeA()); |
| 47 var b = confuse(makeB()); | 50 var b = confuse(makeB()); |
| 48 | 51 |
| 49 Expect.throws(() => a.foo()); | 52 Expect.throws(() => a.foo()); |
| 50 Expect.equals(1, a.foo(10)); | 53 Expect.equals(1, a.foo(10)); |
| 51 Expect.throws(() => a.foo(10, 20)); | 54 Expect.throws(() => a.foo(10, 20)); |
| 52 Expect.throws(() => a.foo(10, 20, 30)); | 55 Expect.throws(() => a.foo(10, 20, 30)); |
| 53 | 56 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 | 78 |
| 76 Expect.throws(() => b.foo(10, 20, 30, 40)); | 79 Expect.throws(() => b.foo(10, 20, 30, 40)); |
| 77 } | 80 } |
| 78 | 81 |
| 79 main() { | 82 main() { |
| 80 nativeTesting(); | 83 nativeTesting(); |
| 81 setup(); | 84 setup(); |
| 82 testDynamicContext(); | 85 testDynamicContext(); |
| 83 testStaticContext(); | 86 testStaticContext(); |
| 84 } | 87 } |
| OLD | NEW |