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

Side by Side Diff: test/mjsunit/harmony/optional-arguments.js

Issue 1127063003: [es6] implement default parameters via desugaring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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
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.
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 //
56 // TODO(caitp): fix scoping --- var declarations in function body can't be
57 // resolved in formal parameters
58 // assertThrows(function referencesVariableBodyDeclaration(a = body_var) {
59 // var body_var = true;
60 // return a;
61 // }, ReferenceError);
62
63
64 // TODO(caitp): default function length does not include any parameters
65 // following the first optional parameter
66 // assertEquals(0, (function(a = 1) {}).length);
67 // assertEquals(1, (function(a, b = 1) {}).length);
68 // assertEquals(2, (function(a, b, c = 1) {}).length);
69 // assertEquals(3, (function(a, b, c, d = 1) {}).length);
70 // assertEquals(1, (function(a, b = 1, c, d = 1) {}).length);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698