Editorial: non-syntactic async/generator functions use ReturnCompletion #3605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This moves the machinery for handling implicit returns in syntactic async/generator functions into the branches for evaluating parse nodes, instead of also using that logic for evaluating Abstract Closures.
It assumes that non-syntactic async/generator functions always internally return ThrowCompletions or ReturnCompletions. Right now they can use both ReturnCompletions or NormalCompletions, which provides an unnecessary degree of freedom. The alternative is to enforce that non-syntactic async/generator functions return ThrowCompletions or NormalCompletions, for which see #3606.
This makes non-syntactic async/generator functions unlike non-syntactic ordinary functions, which never use ReturnCompletion (and the machinery isn't set up to handle them). For that reason, I prefer #3606 over this PR.
You'll note a certain awkwardness in AsyncGeneratorStart: later in the algorithm ReturnCompletions are translated to NormalCompletions, for use as an argument to AsyncGeneratorCompleteStep. This accomplishes the same thing as the current
If _result_ is a normal completion, set _result_ to NormalCompletion(*undefined*)
, but in a more roundabout way, and is necessary to avoid refactoring AsyncGeneratorCompleteStep.(This PR would also require changing the existing built-in generators/async functions to never return NormalCompletions. I'll push up a commit doing that if we go this route.)