| 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 (generator function expression) |
| 5 |
esid: sec-generator-function-definitions-runtime-semantics-evaluation |
| 6 |
es6id: 14.4.14 |
| 7 |
features: [generators, default-parameters] |
| 8 |
info: | |
| 9 |
GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } |
| 10 |
|
| 11 |
[...] |
| 12 |
3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, |
| 13 |
GeneratorBody, scope, strict). |
| 14 |
[...] |
| 15 |
|
| 16 |
9.2.1 [[Call]] ( thisArgument, argumentsList) |
| 17 |
|
| 18 |
[...] |
| 19 |
7. Let result be OrdinaryCallEvaluateBody(F, argumentsList). |
| 20 |
[...] |
| 21 |
|
| 22 |
9.2.1.3 OrdinaryCallEvaluateBody ( F, argumentsList ) |
| 23 |
|
| 24 |
1. Let status be FunctionDeclarationInstantiation(F, argumentsList). |
| 25 |
[...] |
| 26 |
|
| 27 |
9.2.12 FunctionDeclarationInstantiation(func, argumentsList) |
| 28 |
|
| 29 |
[...] |
| 30 |
23. Let iteratorRecord be Record {[[iterator]]: |
| 31 |
CreateListIterator(argumentsList), [[done]]: false}. |
| 32 |
24. If hasDuplicates is true, then |
| 33 |
[...] |
| 34 |
25. Else, |
| 35 |
b. Let formalStatus be IteratorBindingInitialization for formals with |
| 36 |
iteratorRecord and env as arguments. |
| 37 |
[...] |
| 38 |
|
| 39 |
14.1.19 Runtime Semantics: IteratorBindingInitialization |
| 40 |
|
| 41 |
FormalsList : FormalsList , FormalParameter |
| 42 |
|
| 43 |
1. Let status be the result of performing IteratorBindingInitialization for |
| 44 |
FormalsList using iteratorRecord and environment as the arguments. |
| 45 |
2. ReturnIfAbrupt(status). |
| 46 |
3. Return the result of performing IteratorBindingInitialization for |
| 47 |
FormalParameter using iteratorRecord and environment as the arguments. |
| 48 |
---*/ |
| 49 |
|
| 50 |
var callCount = 0; |
| 51 |
var f; |
| 52 |
f = function*(x, _ = 0) { |
| 53 |
assert.sameValue(x, undefined, 'parameter binding value (initial)'); |
| 54 |
assert.sameValue( |
| 55 |
arguments[0], undefined, 'arguments property value (initial)' |
| 56 |
); |
| 57 |
|
| 58 |
arguments[0] = 1; |
| 59 |
|
| 60 |
assert.sameValue( |
| 61 |
x, undefined, 'parameter binding value (after arguments modification)' |
| 62 |
); |
| 63 |
assert.sameValue( |
| 64 |
arguments[0], 1, 'arguments property value (after arguments modification)' |
| 65 |
); |
| 66 |
|
| 67 |
x = 2; |
| 68 |
|
| 69 |
assert.sameValue( |
| 70 |
x, 2, 'parameter binding value (after parameter binding modification)' |
| 71 |
); |
| 72 |
assert.sameValue( |
| 73 |
arguments[0], |
| 74 |
1, |
| 75 |
'arguments property value (after parameter binding modification)' |
| 76 |
); |
| 77 |
callCount = callCount + 1; |
| 78 |
}; |
| 79 |
|
| 80 |
f().next(); |
| 81 |
|
| 82 |
assert.sameValue(callCount, 1, 'generator function invoked exactly once'); |