From a879fd542718bcab6accd2d38964c410fffa28a9 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sat, 12 Jan 2019 23:18:39 -0800 Subject: [PATCH] Editorial: Fix return value logic for async arrow functions (#1406) Introduce a new production ExpressionBody for both plain and async arrow functions, and allow correctly handling return value logic for both. Currently, AsyncFunctionStart does not correctly handle the return value of async arrow functions correctly. --- spec.html | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/spec.html b/spec.html index 6bf91d31ff..3cb79b1a5b 100644 --- a/spec.html +++ b/spec.html @@ -19825,8 +19825,11 @@

Syntax

CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await] #parencover ConciseBody[In] : - [lookahead != `{` ] AssignmentExpression[?In, ~Yield, ~Await] + [lookahead != `{` ] ExpressionBody[?In, ~Await] `{` FunctionBody[~Yield, ~Await] `}` + + ExpressionBody[In, Await] : + AssignmentExpression[?In, ~Yield, ?Await]

Supplemental Syntax

When the production @@ -19909,7 +19912,7 @@

Static Semantics: ContainsExpression

Static Semantics: ContainsUseStrict

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Return *false*. @@ -19970,7 +19973,7 @@

Static Semantics: CoveredFormalsList

Static Semantics: LexicallyDeclaredNames

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Return a new empty List. @@ -19979,7 +19982,7 @@

Static Semantics: LexicallyDeclaredNames

Static Semantics: LexicallyScopedDeclarations

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Return a new empty List. @@ -19988,7 +19991,7 @@

Static Semantics: LexicallyScopedDeclarations

Static Semantics: VarDeclaredNames

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Return a new empty List. @@ -19997,7 +20000,7 @@

Static Semantics: VarDeclaredNames

Static Semantics: VarScopedDeclarations

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Return a new empty List. @@ -20030,12 +20033,10 @@

Runtime Semantics: IteratorBindingInitialization

Runtime Semantics: EvaluateBody

With parameters _functionObject_ and List _argumentsList_.

- ConciseBody : AssignmentExpression + ConciseBody : ExpressionBody 1. Perform ? FunctionDeclarationInstantiation(_functionObject_, _argumentsList_). - 1. Let _exprRef_ be the result of evaluating |AssignmentExpression|. - 1. Let _exprValue_ be ? GetValue(_exprRef_). - 1. Return Completion { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }. + 1. Return the result of evaluating |ExpressionBody|.
@@ -20063,6 +20064,12 @@

Runtime Semantics: Evaluation

An |ArrowFunction| does not define local bindings for `arguments`, `super`, `this`, or `new.target`. Any reference to `arguments`, `super`, `this`, or `new.target` within an |ArrowFunction| must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an |ArrowFunction| may contain references to `super`, the function object created in step 3 is not made into a method by performing MakeMethod. An |ArrowFunction| that references `super` is always contained within a non-|ArrowFunction| and the necessary state to implement `super` is accessible via the _scope_ that is captured by the function object of the |ArrowFunction|.

+ ExpressionBody : AssignmentExpression + + 1. Let _exprRef_ be the result of evaluating |AssignmentExpression|. + 1. Let _exprValue_ be ? GetValue(_exprRef_). + 1. Return Completion { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }. +
@@ -21541,7 +21548,7 @@

Syntax

CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] [no LineTerminator here] `=>` AsyncConciseBody[?In] #callcover AsyncConciseBody[In] : - [lookahead != `{`] AssignmentExpression[?In, ~Yield, +Await] + [lookahead != `{`] ExpressionBody[?In, +Await] `{` AsyncFunctionBody `}` AsyncArrowBindingIdentifier[Yield] : @@ -21683,7 +21690,7 @@

Static Semantics: IsSimpleParameterList

Static Semantics: LexicallyDeclaredNames

- AsyncConciseBody : AssignmentExpression + AsyncConciseBody : ExpressionBody 1. Return a new empty List. @@ -21693,7 +21700,7 @@

Static Semantics: LexicallyDeclaredNames

Static Semantics: LexicallyScopedDeclarations

- AsyncConciseBody : AssignmentExpression + AsyncConciseBody : ExpressionBody 1. Return a new empty List. @@ -21703,7 +21710,7 @@

Static Semantics: LexicallyScopedDeclarations

Static Semantics: VarDeclaredNames

- AsyncConciseBody : AssignmentExpression + AsyncConciseBody : ExpressionBody 1. Return a new empty List. @@ -21713,7 +21720,7 @@

Static Semantics: VarDeclaredNames

Static Semantics: VarScopedDeclarations

- AsyncConciseBody : AssignmentExpression + AsyncConciseBody : ExpressionBody 1. Return a new empty List. @@ -21745,23 +21752,17 @@

Runtime Semantics: IteratorBindingInitialization

Runtime Semantics: EvaluateBody

With parameters _functionObject_ and List _argumentsList_.

- AsyncConciseBody : AssignmentExpression + AsyncConciseBody : ExpressionBody 1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%). 1. Let _declResult_ be FunctionDeclarationInstantiation(_functionObject_, _argumentsList_). 1. If _declResult_ is not an abrupt completion, then - 1. Perform ! AsyncFunctionStart(_promiseCapability_, |AssignmentExpression|). + 1. Perform ! AsyncFunctionStart(_promiseCapability_, |ExpressionBody|). 1. Else, 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _declResult_.[[Value]] »). 1. Return Completion { [[Type]]: ~return~, [[Value]]: _promiseCapability_.[[Promise]], [[Target]]: ~empty~ }. - - AsyncConciseBody : `{` AsyncFunctionBody `}` - - - 1. Return the result of EvaluateBody of |AsyncFunctionBody| passing _functionObject_ and _argumentsList_ as the arguments. -
@@ -21836,10 +21837,6 @@

Static Semantics: HasCallInTailPosition

Statement Rules

- ConciseBody : AssignmentExpression - - 1. Return HasCallInTailPosition of |AssignmentExpression| with argument _call_. - StatementList : StatementList StatementListItem 1. Let _has_ be HasCallInTailPosition of |StatementList| with argument _call_.