Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit a996238

Browse files
committed
Move value unwrapping back to the producer side
This closes #15; see #15 (comment). It ensures that async generators always (*) produce objects which conform to the async iterator contract, namely in not producing Promise<IterationResult<Promise<T>>> from their next() methods. It then removes the double-unwrapping from for-await-of, as for-await-of should be able to assume that it is dealing with a contract-following producer. As a bonus, this makes for-await-of consistent with yield* (in that now neither do double-unwrapping). This involves much fewer changes than f03e40e, which did the opposite by moving the unwrapping from the consumer to the producer side. This is largely because that commit also was removing double-unwrapping in yield* at the same time that it added it to for-await-of. (*): "always" caveat: if you yield* an async iterator which does not follow the contract, you will not follow the contract.
1 parent de0ebd7 commit a996238

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

spec/generator-definitions-patch.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<emu-clause id="sec-asyncgenerator-definitions-evaluation">
22
<h1>Runtime Semantics: Evaluation</h1>
33

4+
<emu-grammar>YieldExpression : `yield` AssignmentExpression</emu-grammar>
5+
<emu-alg>
6+
1. Let _exprRef_ be the result of evaluating |AssignmentExpression|.
7+
1. Let _value_ be ? GetValue(_exprRef_).
8+
1. <ins>Let _generatorKind_ be ! GetGeneratorKind().</ins>
9+
1. <ins>If _generatorKind_ is ~async~, then set _value_ to ? Await(_value_).</ins>
10+
1. Return ? GeneratorYield(CreateIterResultObject(_value_, *false*)).
11+
</emu-alg>
12+
413
<emu-grammar>
514
YieldExpression : `yield` `*` AssignmentExpression
615
</emu-grammar>

spec/iteration-statements-patch.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ <h1>Runtime Semantics: ForIn/OfBodyEvaluation ( _lhs_, _stmt_, _iterator_, _lhsK
383383
1. Let _done_ be ? IteratorComplete(_iterator_).
384384
1. If _done_ is *true*, return NormalCompletion(_V_).
385385
1. Let _nextValue_ be ? IteratorValue(_nextResult_).
386-
1. <ins>If _iteratorKind_ is ~async~, then set _nextValue_ to ? Await(_nextResult_).</ins>
387386
1. If _lhsKind_ is either ~assignment~ or ~varBinding~, then
388387
1. If _destructuring_ is *false*, then
389388
1. Let _lhsRef_ be the result of evaluating _lhs_ (it may be evaluated repeatedly).

0 commit comments

Comments
 (0)