| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
es6id: 14.1.6 |
| 5 |
description: > |
| 6 |
Default parameters' effect on function length |
| 7 |
info: | |
| 8 |
Function length is counted by the non initialized parameters in the left. |
| 9 |
|
| 10 |
9.2.4 FunctionInitialize (F, kind, ParameterList, Body, Scope) |
| 11 |
|
| 12 |
[...] |
| 13 |
2. Let len be the ExpectedArgumentCount of ParameterList. |
| 14 |
3. Perform ! DefinePropertyOrThrow(F, "length", PropertyDescriptor{[[Value]]: |
| 15 |
len, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}). |
| 16 |
[...] |
| 17 |
|
| 18 |
FormalsList : FormalParameter |
| 19 |
|
| 20 |
1. If HasInitializer of FormalParameter is true return 0 |
| 21 |
2. Return 1. |
| 22 |
|
| 23 |
FormalsList : FormalsList , FormalParameter |
| 24 |
|
| 25 |
1. Let count be the ExpectedArgumentCount of FormalsList. |
| 26 |
2. If HasInitializer of FormalsList is true or HasInitializer of |
| 27 |
FormalParameter is true, return count. |
| 28 |
3. Return count+1. |
| 29 |
features: [generators, default-parameters] |
| 30 |
includes: [propertyHelper.js] |
| 31 |
---*/ |
| 32 |
|
| 33 |
|
| 34 |
var f1 = function* (x = 42) {}; |
| 35 |
|
| 36 |
assert.sameValue(f1.length, 0, 'FormalsList: x = 42'); |
| 37 |
verifyNotEnumerable(f1, 'length'); |
| 38 |
verifyNotWritable(f1, 'length'); |
| 39 |
verifyConfigurable(f1, 'length'); |
| 40 |
|
| 41 |
var f2 = function* (x = 42, y) {}; |
| 42 |
|
| 43 |
assert.sameValue(f2.length, 0, 'FormalsList: x = 42, y'); |
| 44 |
verifyNotEnumerable(f2, 'length'); |
| 45 |
verifyNotWritable(f2, 'length'); |
| 46 |
verifyConfigurable(f2, 'length'); |
| 47 |
|
| 48 |
var f3 = function* (x, y = 42) {}; |
| 49 |
|
| 50 |
assert.sameValue(f3.length, 1, 'FormalsList: x, y = 42'); |
| 51 |
verifyNotEnumerable(f3, 'length'); |
| 52 |
verifyNotWritable(f3, 'length'); |
| 53 |
verifyConfigurable(f3, 'length'); |
| 54 |
|
| 55 |
var f4 = function* (x, y = 42, z) {}; |
| 56 |
|
| 57 |
assert.sameValue(f4.length, 1, 'FormalsList: x, y = 42, z'); |
| 58 |
verifyNotEnumerable(f4, 'length'); |
| 59 |
verifyNotWritable(f4, 'length'); |
| 60 |
verifyConfigurable(f4, 'length'); |