Skip to content

Commit

Permalink
Editorial: Fix return value logic in AsyncFunctionStart
Browse files Browse the repository at this point in the history
If the function body is concise (only has an expression) and evaluation
ends in a normal completion, we should just resolve with that value.
  • Loading branch information
TimothyGu committed Jan 13, 2019
1 parent 85ce767 commit 22aef2b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -38261,17 +38261,19 @@ <h1>AsyncFunctionStart ( _promiseCapability_, _asyncFunctionBody_ )</h1>
<emu-alg>
1. Let _runningContext_ be the running execution context.
1. Let _asyncContext_ be a copy of _runningContext_.
1. If _asyncFunctionBody_ is an instance of |AssignmentExpression|, let _isExpression_ be *true*. Otherwise let _isExpression_ be *false*.
1. Set the code evaluation state of _asyncContext_ such that when evaluation is resumed for that execution context the following steps will be performed:
1. Let _result_ be the result of evaluating _asyncFunctionBody_.
1. Assert: If we return here, the async function either threw an exception or performed an implicit or explicit return; all awaiting is done.
1. Remove _asyncContext_ from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
1. If _result_.[[Type]] is ~normal~, then
1. If _result_.[[Type]] is ~throw~, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
1. Else if _result_.[[Type]] is ~normal~ and _isExpression_ is *false*, then
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; *undefined* &raquo;).
1. Else if _result_.[[Type]] is ~return~, then
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
1. Else,
1. Assert: _result_.[[Type]] is ~throw~.
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
1. Assert: _result_.[[Type]] is ~return~ if _isExpression_ is *false*, or ~normal~ if _isExpression_ is *true*.
1. Assert: _result_.[[Value]] is not ~empty~.
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
1. Return.
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
1. Resume the suspended evaluation of _asyncContext_. Let _result_ be the value returned by the resumed computation.
Expand Down

0 comments on commit 22aef2b

Please sign in to comment.