length-dflt.js (1635B)
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: [default-parameters] 30 includes: [propertyHelper.js] 31 ---*/ 32 33 34 var f1 = function (x = 42) {}; 35 36 verifyProperty(f1, "length", { 37 value: 0, 38 writable: false, 39 enumerable: false, 40 configurable: true, 41 }); 42 43 var f2 = function (x = 42, y) {}; 44 45 verifyProperty(f2, "length", { 46 value: 0, 47 writable: false, 48 enumerable: false, 49 configurable: true, 50 }); 51 52 var f3 = function (x, y = 42) {}; 53 54 verifyProperty(f3, "length", { 55 value: 1, 56 writable: false, 57 enumerable: false, 58 configurable: true, 59 }); 60 61 var f4 = function (x, y = 42, z) {}; 62 63 verifyProperty(f4, "length", { 64 value: 1, 65 writable: false, 66 enumerable: false, 67 configurable: true, 68 }); 69 70 reportCompare(0, 0);