Chromium Code Reviews| Index: test/mjsunit/harmony/optional-arguments.js |
| diff --git a/test/mjsunit/harmony/optional-arguments.js b/test/mjsunit/harmony/optional-arguments.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39580b217f4a2deba11b7e44b241b0f3f7dcc594 |
| --- /dev/null |
| +++ b/test/mjsunit/harmony/optional-arguments.js |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --harmony-optional-params |
| + |
| +function return_specified() { return "specified"; } |
| + |
| +var method_returns_specified = { |
| + method() { return "specified"; } |
| +}; |
| + |
| + |
| +(function testOptionalFunctions() { |
| + function optional_function(handler = function() { }) { |
| + assertEquals("function", typeof handler); |
| + |
| + // TODO(caitp): infer function name correctly |
| + // (https://code.google.com/p/v8/issues/detail?id=3699) |
| + // assertEquals("handler", handler.name); |
| + |
| + return handler(); |
| + } |
| + assertEquals(undefined, optional_function()); |
| + assertEquals(undefined, optional_function(undefined)); |
| + assertEquals("specified", optional_function(return_specified)); |
| +})(); |
| + |
| + |
| +(function testOptionalObjects() { |
| + function optional_object(object = { method() { return "method"; } }) { |
| + assertEquals("object", typeof object); |
| + |
| + assertEquals("function", typeof object.method); |
| + return object.method(); |
| + } |
| + |
| + assertEquals("method", optional_object()); |
| + assertEquals("method", optional_object(undefined)); |
| + assertEquals("specified", optional_object(method_returns_specified)); |
| +})(); |
| + |
| + |
| +// TDZ |
| + |
| +(function testReferencesUninitializedParameter(x = 1) { |
| + assertThrows(function(a = b, b) {}, ReferenceError); |
| +})(); |
| + |
| + |
| +(function testReferencesInitializedParameter(x = 1) { |
| + assertEquals(1, (function(a = 1, b = a) { return b; })()); |
| +})(); |
| + |
| + |
|
rossberg
2015/05/12 14:04:53
More tests, e.g.:
- (function(x = this) { return
caitp (gmail)
2015/05/12 18:35:35
Added eval and arrow variants to a bunch of these
rossberg
2015/05/20 07:41:47
Please add a couple of lazy parsing tests as well
caitp (gmail)
2015/05/20 11:29:38
I wasn't able to reproduce it with the regular des
|
| +// Scoping |
| +// |
| +// TODO(caitp): fix scoping --- var declarations in function body can't be |
| +// resolved in formal parameters |
| +// assertThrows(function referencesVariableBodyDeclaration(a = body_var) { |
| +// var body_var = true; |
| +// return a; |
| +// }, ReferenceError); |
| + |
| + |
| +// TODO(caitp): default function length does not include any parameters |
| +// following the first optional parameter |
| +// assertEquals(0, (function(a = 1) {}).length); |
| +// assertEquals(1, (function(a, b = 1) {}).length); |
| +// assertEquals(2, (function(a, b, c = 1) {}).length); |
| +// assertEquals(3, (function(a, b, c, d = 1) {}).length); |
| +// assertEquals(1, (function(a, b = 1, c, d = 1) {}).length); |