| 1 |
// |reftest| async |
| 2 |
// This file was procedurally generated from the following sources: |
| 3 |
// - src/dstr-binding-for-await/ary-init-iter-close.case |
| 4 |
// - src/dstr-binding-for-await/default/for-await-of-async-gen-let.template |
| 5 |
/*--- |
| 6 |
description: Iterator is closed when not exhausted by pattern evaluation (for-await-of statement) |
| 7 |
esid: sec-for-in-and-for-of-statements-runtime-semantics-labelledevaluation |
| 8 |
features: [Symbol.iterator, destructuring-binding, async-iteration] |
| 9 |
flags: [generated, async] |
| 10 |
info: | |
| 11 |
IterationStatement : |
| 12 |
for await ( ForDeclaration of AssignmentExpression ) Statement |
| 13 |
|
| 14 |
[...] |
| 15 |
2. Return ? ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult, |
| 16 |
lexicalBinding, labelSet, async). |
| 17 |
|
| 18 |
13.7.5.13 Runtime Semantics: ForIn/OfBodyEvaluation |
| 19 |
|
| 20 |
[...] |
| 21 |
4. Let destructuring be IsDestructuring of lhs. |
| 22 |
[...] |
| 23 |
6. Repeat |
| 24 |
[...] |
| 25 |
j. If destructuring is false, then |
| 26 |
[...] |
| 27 |
k. Else |
| 28 |
i. If lhsKind is assignment, then |
| 29 |
[...] |
| 30 |
ii. Else if lhsKind is varBinding, then |
| 31 |
[...] |
| 32 |
iii. Else, |
| 33 |
1. Assert: lhsKind is lexicalBinding. |
| 34 |
2. Assert: lhs is a ForDeclaration. |
| 35 |
3. Let status be the result of performing BindingInitialization |
| 36 |
for lhs passing nextValue and iterationEnv as arguments. |
| 37 |
[...] |
| 38 |
|
| 39 |
13.3.3.5 Runtime Semantics: BindingInitialization |
| 40 |
|
| 41 |
BindingPattern : ArrayBindingPattern |
| 42 |
|
| 43 |
[...] |
| 44 |
4. If iteratorRecord.[[done]] is false, return ? IteratorClose(iterator, |
| 45 |
result). |
| 46 |
[...] |
| 47 |
|
| 48 |
---*/ |
| 49 |
var doneCallCount = 0; |
| 50 |
var iter = {}; |
| 51 |
iter[Symbol.iterator] = function() { |
| 52 |
return { |
| 53 |
next() { |
| 54 |
return { value: null, done: false }; |
| 55 |
}, |
| 56 |
return() { |
| 57 |
doneCallCount += 1; |
| 58 |
return {}; |
| 59 |
} |
| 60 |
}; |
| 61 |
}; |
| 62 |
|
| 63 |
var iterCount = 0; |
| 64 |
|
| 65 |
async function *fn() { |
| 66 |
for await (let [x] of [iter]) { |
| 67 |
assert.sameValue(doneCallCount, 1); |
| 68 |
|
| 69 |
iterCount += 1; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
fn().next() |
| 74 |
.then(() => assert.sameValue(iterCount, 1, 'iteration occurred as expected'), $DONE) |
| 75 |
.then($DONE, $DONE); |
| 76 |
|