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

`await` as a default parameter's name/value within a normal function nested inside an async function - what's the behavior? #987

Closed
isiahmeadows opened this Issue Aug 30, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@isiahmeadows

isiahmeadows commented Aug 30, 2017

Two separate examples, and I can't tell if it's a spec bug or V8 bug...

// Note: this should be considered a script
"use strict"
async function foo() {
  function bar({await}) { return await }
  return bar({await: 1})
}

My intuition is that this is valid, and foo() should return a same-tick promise to 1.

"use strict"
var await = 1
async function foo() {
  function bar({baz = await}) { return baz }
  return bar({})
}

My intuition is that this (and the sloppy mode equivalent) should have one of two behaviors:

  1. It should be an early error, since await is used outside the function, inside the scope of foo().
  2. It should be valid, and foo() should return a same-tick promise to 1.

Note that I expect sloppy mode to be similar in both cases.

@isiahmeadows

This comment has been minimized.

Show comment
Hide comment
@isiahmeadows

isiahmeadows Aug 30, 2017

From testing in V8, I did find that both cases returned a same-tick promise to 1.

isiahmeadows commented Aug 30, 2017

From testing in V8, I did find that both cases returned a same-tick promise to 1.

@littledan littledan added the question label Aug 30, 2017

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Aug 30, 2017

Member

V8 follows the JavaScript spec here and treats await as a simple identifier. See the definition of FunctionDeclaration, which parses parameters with the ~Await flag. As a property key, object literals generally allow any sort of keyword before the colon.

Member

littledan commented Aug 30, 2017

V8 follows the JavaScript spec here and treats await as a simple identifier. See the definition of FunctionDeclaration, which parses parameters with the ~Await flag. As a property key, object literals generally allow any sort of keyword before the colon.

@littledan littledan closed this Aug 30, 2017

@isiahmeadows

This comment has been minimized.

Show comment
Hide comment
@isiahmeadows

isiahmeadows Aug 30, 2017

Okay, thanks! I knew there was something subtle I was probably missing.

isiahmeadows commented Aug 30, 2017

Okay, thanks! I knew there was something subtle I was probably missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment