tc39 / proposal-async-iteration

Asynchronous iteration for JavaScript
https://tc39.github.io/proposal-async-iteration/
MIT License
858 stars 44 forks source link

GeneratorYield step 10.a is not necessary #89

Closed arai-a closed 7 years ago

arai-a commented 7 years ago

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).

IteratorComplete(iterNextObj) is done only if done parameter is not passed. there are only 2 cases that done parameter is not passed.

https://tc39.github.io/ecma262/#sec-generator-function-definitions-runtime-semantics-evaluation

YieldExpression: yield
  1. Return ? GeneratorYield(CreateIterResultObject(undefined, false)).
...
YieldExpression: yield AssignmentExpression
...
  3. Return ? GeneratorYield(CreateIterResultObject(value, false)).

There iterNextObj parameter is created by CreateIterResultObject, with done==false. So, it's known that IteratorComplete(iterNextObj) is always false, and it never fail.

Actually, even if done parameter is passed, it's also always false.

GeorgNeis commented 7 years ago

That's a good point, we only ever GeneratorYield a result that's not done. So we can actually get rid of IteratorComplete in GeneratorYield and remove the optional argument again.