Skip to content

Commit

Permalink
Editorial: add a ReturnCompletion AO, mirroring Normal/Throw (tc39#3415)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra authored and ljharb committed Sep 23, 2024
1 parent 95b7997 commit 7df8f59
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ <h1>ReturnIfAbrupt Shorthands</h1>
<h1>Implicit Normal Completion</h1>
<p>In algorithms within abstract operations which are declared to return a Completion Record, and within all built-in functions, the returned value is first passed to NormalCompletion, and the result is used instead. This rule does not apply within the Completion algorithm or when the value being returned is clearly marked as a Completion Record in that step; these cases are:</p>
<ul>
<li>when the result of applying Completion, NormalCompletion, or ThrowCompletion is directly returned</li>
<li>when the result of applying Completion, NormalCompletion, ThrowCompletion, or ReturnCompletion is directly returned</li>
<li>when the result of constructing a Completion Record is directly returned</li>
</ul>
<p>It is an editorial error if a Completion Record is returned from such an abstract operation through any other means. For example, within these abstract operations,</p>
Expand Down Expand Up @@ -4180,6 +4180,19 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-returncompletion" type="abstract operation">
<h1>
ReturnCompletion (
_value_: an ECMAScript language value,
): a return completion
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
</emu-alg>
</emu-clause>

<emu-clause id="sec-updateempty" type="abstract operation">
<h1>
UpdateEmpty (
Expand Down Expand Up @@ -13422,7 +13435,7 @@ <h1>
1. Else,
1. Let _rhs_ be ? Evaluation of |AssignmentExpression|.
1. Let _value_ be ? GetValue(_rhs_).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_value_).
</emu-alg>
<emu-note>
<p>Even though field initializers constitute a function boundary, calling FunctionDeclarationInstantiation does not have any observable effect and so is omitted.</p>
Expand Down Expand Up @@ -22586,14 +22599,14 @@ <h2>Syntax</h2>
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>ReturnStatement : `return` `;`</emu-grammar>
<emu-alg>
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: *undefined*, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(*undefined*).
</emu-alg>
<emu-grammar>ReturnStatement : `return` Expression `;`</emu-grammar>
<emu-alg>
1. Let _exprRef_ be ? Evaluation of |Expression|.
1. Let _exprValue_ be ? GetValue(_exprRef_).
1. If GetGeneratorKind() is ~async~, set _exprValue_ to ? Await(_exprValue_).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_exprValue_).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -23695,7 +23708,7 @@ <h1>Runtime Semantics: Evaluation</h1>
<emu-alg>
1. Let _exprRef_ be ? Evaluation of |AssignmentExpression|.
1. Let _exprValue_ be ? GetValue(_exprRef_).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _exprValue_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_exprValue_).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -24020,7 +24033,7 @@ <h1>
1. Set _G_.[[GeneratorBrand]] to ~empty~.
1. Set _G_.[[GeneratorState]] to ~suspended-start~.
1. Perform GeneratorStart(_G_, |FunctionBody|).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _G_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_G_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -24160,14 +24173,14 @@ <h1>Runtime Semantics: Evaluation</h1>
1. Set _value_ to _received_.[[Value]].
1. If _generatorKind_ is ~async~, then
1. Set _value_ to ? Await(_value_).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_value_).
1. Let _innerReturnResult_ be ? Call(_return_, _iterator_, « _received_.[[Value]] »).
1. If _generatorKind_ is ~async~, set _innerReturnResult_ to ? Await(_innerReturnResult_).
1. If _innerReturnResult_ is not an Object, throw a *TypeError* exception.
1. Let _done_ be ? IteratorComplete(_innerReturnResult_).
1. If _done_ is *true*, then
1. Set _value_ to ? IteratorValue(_innerReturnResult_).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_value_).
1. If _generatorKind_ is ~async~, set _received_ to Completion(AsyncGeneratorYield(? IteratorValue(_innerReturnResult_))).
1. Else, set _received_ to Completion(GeneratorYield(_innerReturnResult_)).
</emu-alg>
Expand Down Expand Up @@ -24248,7 +24261,7 @@ <h1>
1. Set _generator_.[[GeneratorBrand]] to ~empty~.
1. Set _generator_.[[AsyncGeneratorState]] to ~suspended-start~.
1. Perform AsyncGeneratorStart(_generator_, |FunctionBody|).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _generator_, [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_generator_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -25264,7 +25277,7 @@ <h1>
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _completion_.[[Value]] »).
1. Else,
1. Perform AsyncFunctionStart(_promiseCapability_, |FunctionBody|).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _promiseCapability_.[[Promise]], [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_promiseCapability_.[[Promise]]).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -25371,7 +25384,7 @@ <h1>
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _completion_.[[Value]] »).
1. Else,
1. Perform AsyncFunctionStart(_promiseCapability_, |ExpressionBody|).
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _promiseCapability_.[[Promise]], [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_promiseCapability_.[[Promise]]).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -48042,7 +48055,7 @@ <h1>%GeneratorPrototype%.return ( _value_ )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _g_ be the *this* value.
1. Let _C_ be Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
1. Let _C_ be ReturnCompletion(_value_).
1. Return ? GeneratorResumeAbrupt(_g_, _C_, ~empty~).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -48371,7 +48384,7 @@ <h1>%AsyncGeneratorPrototype%.return ( _value_ )</h1>
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _result_ be Completion(AsyncGeneratorValidate(_generator_, ~empty~)).
1. IfAbruptRejectPromise(_result_, _promiseCapability_).
1. Let _completion_ be Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }.
1. Let _completion_ be ReturnCompletion(_value_).
1. Perform AsyncGeneratorEnqueue(_generator_, _completion_, _promiseCapability_).
1. Let _state_ be _generator_.[[AsyncGeneratorState]].
1. If _state_ is either ~suspended-start~ or ~completed~, then
Expand Down Expand Up @@ -48622,7 +48635,7 @@ <h1>
1. Let _awaited_ be Completion(Await(_resumptionValue_.[[Value]])).
1. If _awaited_ is a throw completion, return ? _awaited_.
1. Assert: _awaited_ is a normal completion.
1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _awaited_.[[Value]], [[Target]]: ~empty~ }.
1. Return ReturnCompletion(_awaited_.[[Value]]).
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 7df8f59

Please sign in to comment.