params-dflt-ref-arguments.js (2115B)
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 description: Referencing the arguments object from a default parameter (function declaration) 5 esid: sec-function-definitions-runtime-semantics-instantiatefunctionobject 6 es6id: 14.1.19 7 features: [default-parameters] 8 info: | 9 FunctionDeclaration : 10 function BindingIdentifier ( FormalParameters ) { FunctionBody } 11 12 [...] 13 3. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, 14 scope, strict). 15 [...] 16 17 9.2.1 [[Call]] ( thisArgument, argumentsList) 18 19 [...] 20 7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). 21 [...] 22 23 9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) 24 25 1. Let status be FunctionDeclarationInstantiation(F, argumentsList). 26 [...] 27 28 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) 29 30 [...] 31 23. Let iteratorRecord be Record {[[iterator]]: 32 CreateListIterator(argumentsList), [[done]]: false}. 33 24. If hasDuplicates is true, then 34 [...] 35 25. Else, 36 b. Let formalStatus be IteratorBindingInitialization for formals with 37 iteratorRecord and env as arguments. 38 [...] 39 40 14.1.19 Runtime Semantics: IteratorBindingInitialization 41 42 FormalsList : FormalsList , FormalParameter 43 44 1. Let status be the result of performing IteratorBindingInitialization for 45 FormalsList using iteratorRecord and environment as the arguments. 46 2. ReturnIfAbrupt(status). 47 3. Return the result of performing IteratorBindingInitialization for 48 FormalParameter using iteratorRecord and environment as the arguments. 49 ---*/ 50 51 var callCount = 0; 52 function f(x = arguments[2], y = arguments[3], z) { 53 assert.sameValue(x, 'third', 'first parameter'); 54 assert.sameValue(y, 'fourth', 'second parameter'); 55 assert.sameValue(z, 'third', 'third parameter'); 56 callCount = callCount + 1; 57 } 58 59 f(undefined, undefined, 'third', 'fourth'); 60 61 assert.sameValue(callCount, 1, 'function invoked exactly once'); 62 63 reportCompare(0, 0);