From 7df8f590e9f3c57a2783c5c26eeb631fe211f51b Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Mon, 23 Sep 2024 12:15:46 -0700 Subject: [PATCH] Editorial: add a ReturnCompletion AO, mirroring Normal/Throw (#3415) --- spec.html | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/spec.html b/spec.html index 6fd4400dc0..2780ca01a1 100644 --- a/spec.html +++ b/spec.html @@ -1028,7 +1028,7 @@

ReturnIfAbrupt Shorthands

Implicit Normal Completion

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:

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,

@@ -4180,6 +4180,19 @@

+ +

+ ReturnCompletion ( + _value_: an ECMAScript language value, + ): a return completion +

+
+
+ + 1. Return Completion Record { [[Type]]: ~return~, [[Value]]: _value_, [[Target]]: ~empty~ }. + +
+

UpdateEmpty ( @@ -13422,7 +13435,7 @@

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_).

Even though field initializers constitute a function boundary, calling FunctionDeclarationInstantiation does not have any observable effect and so is omitted.

@@ -22586,14 +22599,14 @@

Syntax

Runtime Semantics: Evaluation

ReturnStatement : `return` `;` - 1. Return Completion Record { [[Type]]: ~return~, [[Value]]: *undefined*, [[Target]]: ~empty~ }. + 1. Return ReturnCompletion(*undefined*). ReturnStatement : `return` Expression `;` 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_). @@ -23695,7 +23708,7 @@

Runtime Semantics: Evaluation

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_). @@ -24020,7 +24033,7 @@

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_). @@ -24160,14 +24173,14 @@

Runtime Semantics: Evaluation

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_)). @@ -24248,7 +24261,7 @@

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_). @@ -25264,7 +25277,7 @@

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]]). @@ -25371,7 +25384,7 @@

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]]). @@ -48042,7 +48055,7 @@

%GeneratorPrototype%.return ( _value_ )

This method performs the following steps when called:

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~). @@ -48371,7 +48384,7 @@

%AsyncGeneratorPrototype%.return ( _value_ )

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 @@ -48622,7 +48635,7 @@

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]]).