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