tc39/proposal-async-iteration

Property access order mismatch between yield* with async iterator and yield* with sync iterator

arai-a opened this issue · 4 comments

not so much critical issue tho,
"value" property and "done" property of iterator result object are accessed in different order between async and sync cases in yield*.

https://tc39.github.io/proposal-async-iteration/#sec-asyncgenerator-definitions-evaluation

YieldExpression: yield * AssignmentExpression
...
6. Repeat
a. If received.[[Type]] is normal, then
ii. Let innerResult be ? Invoke(iterator, "next", « received.[[Value]] »).
...
v. Let done be ? IteratorComplete(innerResult).
vi. If done is true, then
1. Return ? IteratorValue(innerResult).
vii. Let received be GeneratorYield(innerResult, done).

https://tc39.github.io/proposal-async-iteration/#sec-generatoryield

6.2.1.2 GeneratorYield ( iterNextObj [ , done ] )
...
10. If generatorKind is async,
a. If done is not provided, let done be ? IteratorComplete(iterNextObj).
b. Let value be ? IteratorValue(iterNextObj).

https://tc39.github.io/proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%.next

6.1.3.2.1 %AsyncFromSyncIteratorPrototype%.next ( value )
...
7. Let nextValue be IteratorValue(nextResult).
8. IfAbruptRejectPromise(nextValue, promiseCapability).
9. Let nextDone be IteratorComplete(nextResult).
10. IfAbruptRejectPromise(nextDone, promiseCapability).
...

with async iterator, "done" is accessed first in yield* evaluation step 6.a.v,
and "value" is accessed after that in GeneratorYield step 10.b.

with sync iterator, "value" is accessed first in %AsyncFromSyncIteratorPrototype%.next step 7, and "done" is accessed after that in step 9.

Given the other stuff going on here I think it'll be easy to switch %AsyncFromSyncIteratorPrototype%.next and its friends to done-value order. Does that sound reasonable?

yeah, the current spec also uses done-value order everywhere (IteratorStep+IteratorValue, or IteratorComplete+IteratorValue),
and aligning %AsyncFromSyncIteratorPrototype% to it should be reasonable.

Somehow I let this slip off my to-do list. Fixed. /cc @caitp

/cc @leobalter in case this affects already-written tests.

caitp commented

I've positively regarded the changes that you had landed in March, but I'm not quite sure how this new change will affect debug-ability (in Chrome). I'm having a look at this now and should know within the next hour.