| 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 |
esid: sec-generator-function-definitions-runtime-semantics-evaluation |
| 5 |
es6id: 14.4.14 |
| 6 |
description: > |
| 7 |
`value` property is not accessed when iteration is incomplete |
| 8 |
info: | |
| 9 |
YieldExpression : yield * AssignmentExpression |
| 10 |
|
| 11 |
1. Let exprRef be the result of evaluating AssignmentExpression. |
| 12 |
2. Let value be ? GetValue(exprRef). |
| 13 |
3. Let iterator be ? GetIterator(value). |
| 14 |
4. Let received be NormalCompletion(undefined). |
| 15 |
5. Repeat |
| 16 |
a. If received.[[Type]] is normal, then |
| 17 |
i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). |
| 18 |
ii. Let done be ? IteratorComplete(innerResult). |
| 19 |
iii. If done is true, then |
| 20 |
1. Return ? IteratorValue(innerResult). |
| 21 |
features: [generators, Symbol.iterator] |
| 22 |
---*/ |
| 23 |
|
| 24 |
var badIter = {}; |
| 25 |
var callCount = 0; |
| 26 |
var spyValue = Object.defineProperty({ done: false }, 'value', { |
| 27 |
get: function() { |
| 28 |
callCount += 1; |
| 29 |
} |
| 30 |
}); |
| 31 |
badIter[Symbol.iterator] = function() { |
| 32 |
return { |
| 33 |
next: function() { |
| 34 |
return spyValue; |
| 35 |
} |
| 36 |
}; |
| 37 |
}; |
| 38 |
var delegationComplete = false; |
| 39 |
function* g() { |
| 40 |
yield * badIter; |
| 41 |
delegationComplete = true; |
| 42 |
} |
| 43 |
var iter = g(); |
| 44 |
|
| 45 |
iter.next(); |
| 46 |
assert.sameValue(callCount, 0, 'access count (first iteration)'); |
| 47 |
assert.sameValue( |
| 48 |
delegationComplete, false, 'delegation ongoing (first iteration)' |
| 49 |
); |
| 50 |
|
| 51 |
iter.next(); |
| 52 |
assert.sameValue(callCount, 0, 'access count (second iteration)'); |
| 53 |
assert.sameValue( |
| 54 |
delegationComplete, false, 'delegation ongoing (second iteration)' |
| 55 |
); |
| 56 |
|
| 57 |
spyValue.done = true; |
| 58 |
iter.next(); |
| 59 |
assert.sameValue(callCount, 1, 'access count (final iteration)'); |
| 60 |
assert.sameValue(delegationComplete, true, 'delegation complete'); |