| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // Test similar to NativeCallArity1FrogTest, but with default values to | 8 // Test similar to NativeCallArity1FrogTest, but with default values to |
| 9 // parameters set to null. These parameters should be treated as if they | 9 // parameters set to null. These parameters should be treated as if they |
| 10 // do not have a default value for the native methods. | 10 // do not have a default value for the native methods. |
| 11 | 11 |
| 12 @Native("A") | 12 @Native("A") |
| 13 class A { | 13 class A { |
| 14 int foo(int x) native; | 14 int foo(int x) native ; |
| 15 } | 15 } |
| 16 | 16 |
| 17 @Native("B") | 17 @Native("B") |
| 18 class B { | 18 class B { |
| 19 int foo([x = null, y, z = null]) native; | 19 int foo([x = null, y, z = null]) native ; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // TODO(sra): Add a case where the parameters have default values. Wait until | 22 // TODO(sra): Add a case where the parameters have default values. Wait until |
| 23 // dart:html need non-null default values. | 23 // dart:html need non-null default values. |
| 24 | 24 |
| 25 A makeA() native; | 25 A makeA() native ; |
| 26 B makeB() native; | 26 B makeB() native ; |
| 27 | 27 |
| 28 void setup() native """ | 28 void setup() native """ |
| 29 function A() {} | 29 function A() {} |
| 30 A.prototype.foo = function () { return arguments.length; }; | 30 A.prototype.foo = function () { return arguments.length; }; |
| 31 | 31 |
| 32 function B() {} | 32 function B() {} |
| 33 B.prototype.foo = function () { return arguments.length; }; | 33 B.prototype.foo = function () { return arguments.length; }; |
| 34 | 34 |
| 35 makeA = function(){return new A;}; | 35 makeA = function(){return new A;}; |
| 36 makeB = function(){return new B;}; | 36 makeB = function(){return new B;}; |
| 37 """; | 37 """; |
| 38 | 38 |
| 39 | |
| 40 testDynamicContext() { | 39 testDynamicContext() { |
| 41 var things = [makeA(), makeB()]; | 40 var things = [makeA(), makeB()]; |
| 42 var a = things[0]; | 41 var a = things[0]; |
| 43 var b = things[1]; | 42 var b = things[1]; |
| 44 | 43 |
| 45 Expect.throws(() => a.foo()); | 44 Expect.throws(() => a.foo()); |
| 46 Expect.equals(1, a.foo(10)); | 45 Expect.equals(1, a.foo(10)); |
| 47 Expect.throws(() => a.foo(10, 20)); | 46 Expect.throws(() => a.foo(10, 20)); |
| 48 Expect.throws(() => a.foo(10, 20, 30)); | 47 Expect.throws(() => a.foo(10, 20, 30)); |
| 49 | 48 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 76 Expect.equals(2, b.foo(null, 20)); | 75 Expect.equals(2, b.foo(null, 20)); |
| 77 Expect.equals(3, b.foo(null, null, 30)); | 76 Expect.equals(3, b.foo(null, null, 30)); |
| 78 Expect.throws(() => b.foo(10, 20, 30, 40)); | 77 Expect.throws(() => b.foo(10, 20, 30, 40)); |
| 79 } | 78 } |
| 80 | 79 |
| 81 main() { | 80 main() { |
| 82 setup(); | 81 setup(); |
| 83 testDynamicContext(); | 82 testDynamicContext(); |
| 84 testStaticContext(); | 83 testStaticContext(); |
| 85 } | 84 } |
| OLD | NEW |