Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Unified Diff: test/mjsunit/harmony/optional-arguments.js

Issue 1104223002: [es6] implement optional parameters via desugaring (with scoping) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add a debugger test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/variables.cc ('k') | test/mjsunit/harmony/optional-arguments-debug.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d0fe0bbe239c5a3472d51a38004478d7c55f68b3
--- /dev/null
+++ b/test/mjsunit/harmony/optional-arguments.js
@@ -0,0 +1,67 @@
+// 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
+ // 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
+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);
« no previous file with comments | « src/variables.cc ('k') | test/mjsunit/harmony/optional-arguments-debug.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698