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..0b121aa63254563e0528739e514ef86075004e4a |
--- /dev/null |
+++ b/test/mjsunit/harmony/optional-arguments.js |
@@ -0,0 +1,70 @@ |
+// 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. |
+ |
+ |
+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 |
arv (Not doing code reviews)
2015/05/06 20:32:38
https://code.google.com/p/v8/issues/detail?id=3699
caitp (gmail)
2015/05/06 20:42:55
Acknowledged.
|
+ // 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; })()); |
+})(); |
+ |
+ |
+// 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); |