Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normative: allow await in parameter defaults (#917) #1136

Closed

Conversation

pemrouz
Copy link

@pemrouz pemrouz commented Mar 18, 2018

This addresses a spec bug to allow using the await keyword in parameter
defaults for non-arrow async functions:

async function foo(bar = await baz) { ... }

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)

This addresses a spec bug to allow using the await keyword in parameter
defaults for non-arrow async functions:

  async function foo(bar = await baz) { ... }

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] tc39#917 (comment)
@littledan
Copy link
Member

The plan is to extend this change to async generators, right?

@ljharb ljharb added needs consensus This needs committee consensus before it can be eligible to be merged. has test262 tests labels Mar 18, 2018
@bakkot
Copy link
Contributor

bakkot commented Nov 21, 2019

I'm going to close this in light of #917 (comment) and the discussion in plenary.

@bakkot bakkot closed this Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has test262 tests needs consensus This needs committee consensus before it can be eligible to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants