normative: allow await in parameter defaults (#917) #1136
Closed
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 addresses a spec bug to allow using the await keyword in parameter
defaults for non-arrow async functions:
This enables developers to have a consistent way to default parameters
using both async and non-async values, which otherwise quickly becomes
a common pain point. A complete motivating example is described in [1].
The solution converged on here after several iterations has been refined
to avoid creating unnecessary duplication between the different cases. In
EvaluateBody (14.7.11) the promise is already created before
FunctionDeclarationInstantiation (which is also already rejected if
initialisation throws). Instead of creating an
AsyncFunctionDeclarationInstantiation, creating additional promises, or
duplicating the boilerplate in AsyncFunctionStart, the call to FDI has
simply been moved into AsyncFunctionStart which then allows usage of the
await keyword during initialisation. It also removes the corresponding
early errors in 14.7.1 (Static Semantics: Early Errors) and 19.2.1.1.1
(CreateDynamicFunction).
This PR is to use a basis for discussion in the committee. We are already
aware of and plan to make the analogous change to async generators before
landing.
Reviewers: @littledan, @bterlson, @syg
Tests:
https://github.com/tc39/test262/compare/master...pemrouz:normative/await-in-parameter-defaults?expand=1
[1] #917 (comment)