Skip to content

Commit

Permalink
Editorial: Fix return value logic for async arrow functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TimothyGu committed May 2, 2019
1 parent 5527c80 commit 1feb3d8
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -18522,8 +18522,11 @@ <h2>Syntax</h2>
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]
</emu-grammar>
<h2>Supplemental Syntax</h2>
<p>When the production
Expand Down Expand Up @@ -18606,7 +18609,7 @@ <h1>Static Semantics: ContainsExpression</h1>
<emu-clause id="sec-arrow-function-definitions-static-semantics-containsusestrict">
<h1>Static Semantics: ContainsUseStrict</h1>
<emu-see-also-para op="ContainsUseStrict"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
Expand Down Expand Up @@ -18667,7 +18670,7 @@ <h1>Static Semantics: CoveredFormalsList</h1>
<emu-clause id="sec-arrow-function-definitions-static-semantics-lexicallydeclarednames">
<h1>Static Semantics: LexicallyDeclaredNames</h1>
<emu-see-also-para op="LexicallyDeclaredNames"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
Expand All @@ -18676,7 +18679,7 @@ <h1>Static Semantics: LexicallyDeclaredNames</h1>
<emu-clause id="sec-arrow-function-definitions-static-semantics-lexicallyscopeddeclarations">
<h1>Static Semantics: LexicallyScopedDeclarations</h1>
<emu-see-also-para op="LexicallyScopedDeclarations"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
Expand All @@ -18685,7 +18688,7 @@ <h1>Static Semantics: LexicallyScopedDeclarations</h1>
<emu-clause id="sec-arrow-function-definitions-static-semantics-vardeclarednames">
<h1>Static Semantics: VarDeclaredNames</h1>
<emu-see-also-para op="VarDeclaredNames"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
Expand All @@ -18694,7 +18697,7 @@ <h1>Static Semantics: VarDeclaredNames</h1>
<emu-clause id="sec-arrow-function-definitions-static-semantics-varscopeddeclarations">
<h1>Static Semantics: VarScopedDeclarations</h1>
<emu-see-also-para op="VarScopedDeclarations"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
Expand Down Expand Up @@ -18727,12 +18730,10 @@ <h1>Runtime Semantics: IteratorBindingInitialization</h1>
<h1>Runtime Semantics: EvaluateBody</h1>
<p>With parameters _functionObject_ and List _argumentsList_.</p>
<emu-see-also-para op="EvaluateBody"></emu-see-also-para>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-grammar>ConciseBody : ExpressionBody</emu-grammar>
<emu-alg>
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|.
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -18761,6 +18762,12 @@ <h1>Runtime Semantics: Evaluation</h1>
<emu-note>
<p>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 4 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|.</p>
</emu-note>
<emu-grammar>ExpressionBody : AssignmentExpression</emu-grammar>
<emu-alg>
1. Let _exprRef_ be the result of evaluating |AssignmentExpression|.
1. Let _exprValue_ be ? GetValue(_exprRef_).
1. Return Completion { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }.
</emu-alg>
</emu-clause>
</emu-clause>

Expand Down Expand Up @@ -20268,7 +20275,7 @@ <h2>Syntax</h2>
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] [no LineTerminator here] `=>` AsyncConciseBody[?In] #callcover

AsyncConciseBody[In] :
[lookahead != `{`] AssignmentExpression[?In, ~Yield, +Await]
[lookahead != `{`] ExpressionBody[?In, +Await]
`{` AsyncFunctionBody `}`

AsyncArrowBindingIdentifier[Yield] :
Expand Down Expand Up @@ -20401,7 +20408,7 @@ <h1>Static Semantics: IsSimpleParameterList</h1>
<emu-clause id="sec-async-arrow-function-definitions-static-semantics-LexicallyDeclaredNames">
<h1>Static Semantics: LexicallyDeclaredNames</h1>
<emu-grammar>
AsyncConciseBody : AssignmentExpression
AsyncConciseBody : ExpressionBody
</emu-grammar>
<emu-alg>
1. Return a new empty List.
Expand All @@ -20411,7 +20418,7 @@ <h1>Static Semantics: LexicallyDeclaredNames</h1>
<emu-clause id="sec-async-arrow-function-definitions-static-semantics-LexicallyScopedDeclarations">
<h1>Static Semantics: LexicallyScopedDeclarations</h1>
<emu-grammar>
AsyncConciseBody : AssignmentExpression
AsyncConciseBody : ExpressionBody
</emu-grammar>
<emu-alg>
1. Return a new empty List.
Expand All @@ -20421,7 +20428,7 @@ <h1>Static Semantics: LexicallyScopedDeclarations</h1>
<emu-clause id="sec-async-arrow-function-definitions-static-semantics-VarDeclaredNames">
<h1>Static Semantics: VarDeclaredNames</h1>
<emu-grammar>
AsyncConciseBody : AssignmentExpression
AsyncConciseBody : ExpressionBody
</emu-grammar>
<emu-alg>
1. Return a new empty List.
Expand All @@ -20431,7 +20438,7 @@ <h1>Static Semantics: VarDeclaredNames</h1>
<emu-clause id="sec-async-arrow-function-definitions-static-semantics-VarScopedDeclarations">
<h1>Static Semantics: VarScopedDeclarations</h1>
<emu-grammar>
AsyncConciseBody : AssignmentExpression
AsyncConciseBody : ExpressionBody
</emu-grammar>
<emu-alg>
1. Return a new empty List.
Expand Down Expand Up @@ -20463,23 +20470,17 @@ <h1>Runtime Semantics: IteratorBindingInitialization</h1>
<h1>Runtime Semantics: EvaluateBody</h1>
<p>With parameters _functionObject_ and List _argumentsList_.</p>
<emu-grammar>
AsyncConciseBody : AssignmentExpression
AsyncConciseBody : ExpressionBody
</emu-grammar>
<emu-alg>
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*, &laquo; _declResult_.[[Value]] &raquo;).
1. Return Completion { [[Type]]: ~return~, [[Value]]: _promiseCapability_.[[Promise]], [[Target]]: ~empty~ }.
</emu-alg>
<emu-grammar>
AsyncConciseBody : `{` AsyncFunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return the result of EvaluateBody of |AsyncFunctionBody| passing _functionObject_ and _argumentsList_ as the arguments.
</emu-alg>
</emu-clause>

<emu-clause id="sec-async-arrow-function-definitions-runtime-semantics-namedevaluation">
Expand Down Expand Up @@ -20554,10 +20555,6 @@ <h1>Static Semantics: HasCallInTailPosition</h1>

<emu-clause id="sec-statement-rules">
<h1>Statement Rules</h1>
<emu-grammar>ConciseBody : AssignmentExpression</emu-grammar>
<emu-alg>
1. Return HasCallInTailPosition of |AssignmentExpression| with argument _call_.
</emu-alg>
<emu-grammar>StatementList : StatementList StatementListItem</emu-grammar>
<emu-alg>
1. Let _has_ be HasCallInTailPosition of |StatementList| with argument _call_.
Expand Down

0 comments on commit 1feb3d8

Please sign in to comment.