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

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: some nits 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 // Flags: --harmony-optional-params
6
7 function return_specified() { return "specified"; }
8
9 var method_returns_specified = {
10 method() { return "specified"; }
11 };
12
13
14 (function testOptionalFunctions() {
15 function optional_function(handler = function() { }) {
16 assertEquals("function", typeof handler);
17
18 // TODO(caitp): infer function name correctly
19 // (https://code.google.com/p/v8/issues/detail?id=3699)
20 // assertEquals("handler", handler.name);
21
22 return handler();
23 }
24 assertEquals(undefined, optional_function());
25 assertEquals(undefined, optional_function(undefined));
26 assertEquals("specified", optional_function(return_specified));
27 })();
28
29
30 (function testOptionalObjects() {
31 function optional_object(object = { method() { return "method"; } }) {
32 assertEquals("object", typeof object);
33
34 assertEquals("function", typeof object.method);
35 return object.method();
36 }
37
38 assertEquals("method", optional_object());
39 assertEquals("method", optional_object(undefined));
40 assertEquals("specified", optional_object(method_returns_specified));
41 })();
42
43
44 // TDZ
45
46 (function testReferencesUninitializedParameter(x = 1) {
47 assertThrows(function(a = b, b) {}, ReferenceError);
48 })();
49
50
51 (function testReferencesInitializedParameter(x = 1) {
52 assertEquals(1, (function(a = 1, b = a) { return b; })());
53 })();
54
55
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
56 // Scoping
57 //
58 // TODO(caitp): fix scoping --- var declarations in function body can't be
59 // resolved in formal parameters
60 // assertThrows(function referencesVariableBodyDeclaration(a = body_var) {
61 // var body_var = true;
62 // return a;
63 // }, ReferenceError);
64
65
66 // TODO(caitp): default function length does not include any parameters
67 // following the first optional parameter
68 // assertEquals(0, (function(a = 1) {}).length);
69 // assertEquals(1, (function(a, b = 1) {}).length);
70 // assertEquals(2, (function(a, b, c = 1) {}).length);
71 // assertEquals(3, (function(a, b, c, d = 1) {}).length);
72 // assertEquals(1, (function(a, b = 1, c, d = 1) {}).length);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698