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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/variables.cc ('k') | test/mjsunit/harmony/optional-arguments-debug.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5
6 function return_specified() { return "specified"; }
7
8 var method_returns_specified = {
9 method() { return "specified"; }
10 };
11
12
13 (function testOptionalFunctions() {
14 function optional_function(handler = function() { }) {
15 assertEquals("function", typeof handler);
16
17 // TODO(caitp): infer function name correctly
18 // assertEquals("handler", handler.name);
19
20 return handler();
21 }
22 assertEquals(undefined, optional_function());
23 assertEquals(undefined, optional_function(undefined));
24 assertEquals("specified", optional_function(return_specified));
25 })();
26
27
28 (function testOptionalObjects() {
29 function optional_object(object = { method() { return "method"; } }) {
30 assertEquals("object", typeof object);
31
32 assertEquals("function", typeof object.method);
33 return object.method();
34 }
35
36 assertEquals("method", optional_object());
37 assertEquals("method", optional_object(undefined));
38 assertEquals("specified", optional_object(method_returns_specified));
39 })();
40
41
42 // TDZ
43
44 (function testReferencesUninitializedParameter(x = 1) {
45 assertThrows(function(a = b, b) {}, ReferenceError);
46 })();
47
48
49 (function testReferencesInitializedParameter(x = 1) {
50 assertEquals(1, (function(a = 1, b = a) { return b; })());
51 })();
52
53
54 // Scoping
55 assertThrows(function referencesVariableBodyDeclaration(a = body_var) {
56 var body_var = true;
57 return a;
58 }, ReferenceError);
59
60
61 // TODO(caitp): default function length does not include any parameters
62 // following the first optional parameter
63 // assertEquals(0, (function(a = 1) {}).length);
64 // assertEquals(1, (function(a, b = 1) {}).length);
65 // assertEquals(2, (function(a, b, c = 1) {}).length);
66 // assertEquals(3, (function(a, b, c, d = 1) {}).length);
67 // assertEquals(1, (function(a, b = 1, c, d = 1) {}).length);
OLDNEW
« 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