From c7560a59d295080776907b96e412567e9fe92186 Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Wed, 10 Jan 2024 12:14:10 -0800 Subject: [PATCH] Editorial: Use "is a foo completion" instead of testing [[Type]] field (#3163) Mostly, change: _x_.[[Type]] is ~foo~ to: _x_ is a foo completion Resolves issue #2644. --- esmeta-ignore.json | 5 +-- spec.html | 90 +++++++++++++++++++++++----------------------- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/esmeta-ignore.json b/esmeta-ignore.json index 90673a02eb..63a4c5bf38 100644 --- a/esmeta-ignore.json +++ b/esmeta-ignore.json @@ -11,16 +11,12 @@ "ArrayAssignmentPattern[2,3].DestructuringAssignmentEvaluation", "ArrayCreate", "AsyncGeneratorBody[0,0].EvaluateAsyncGeneratorBody", - "AsyncGeneratorUnwrapYieldResumption", "BindingPattern[1,0].BindingInitialization", "BoundFunctionCreate", "Catch[0,0].CatchClauseEvaluation", "Catch[1,0].CatchClauseEvaluation", "ClassStaticBlockBody[0,0].EvaluateClassStaticBlockBody", "CreateBuiltinFunction", - "CreateIterResultObject", - "ECMAScriptFunctionObject.Call", - "ECMAScriptFunctionObject.Construct", "FlattenIntoArray", "ForIn/OfBodyEvaluation", "FunctionBody[0,0].EvaluateFunctionBody", @@ -37,6 +33,7 @@ "ModuleNamespaceExoticObject.OwnPropertyKeys", "OrdinaryObject.OwnPropertyKeys", "ProxyCreate", + "ScriptEvaluation", "SerializeJSONObject", "SetFunctionLength", "SourceTextModuleRecord.ExecuteModule", diff --git a/spec.html b/spec.html index c8ab3a4d44..564755c931 100644 --- a/spec.html +++ b/spec.html @@ -4127,7 +4127,7 @@

- 1. Assert: If _completionRecord_.[[Type]] is either ~return~ or ~throw~, then _completionRecord_.[[Value]] is not ~empty~. + 1. Assert: If _completionRecord_ is either a return completion or a throw completion, then _completionRecord_.[[Value]] is not ~empty~. 1. If _completionRecord_.[[Value]] is not ~empty~, return ? _completionRecord_. 1. Return Completion Record { [[Type]]: _completionRecord_.[[Type]], [[Value]]: _value_, [[Target]]: _completionRecord_.[[Target]] }. @@ -4489,7 +4489,7 @@

The Environment Record Specification Type

The Abstract Closure Specification Type

The Abstract Closure specification type is used to refer to algorithm steps together with a collection of values. Abstract Closures are meta-values and are invoked using function application style such as _closure_(_arg1_, _arg2_). Like abstract operations, invocations perform the algorithm steps described by the Abstract Closure.

In algorithm steps that create an Abstract Closure, values are captured with the verb "capture" followed by a list of aliases. When an Abstract Closure is created, it captures the value that is associated with each alias at that time. In steps that specify the algorithm to be performed when an Abstract Closure is called, each captured value is referred to by the alias that was used to capture the value.

-

If an Abstract Closure returns a Completion Record, that Completion Record's [[Type]] must be either ~normal~ or ~throw~.

+

If an Abstract Closure returns a Completion Record, that Completion Record must be either a normal completion or a throw completion.

Abstract Closures are created inline as part of other algorithms, shown in the following example.

1. Let _addend_ be 41. @@ -7008,12 +7008,12 @@

1. Assert: _iteratorRecord_.[[Iterator]] is an Object. 1. Let _iterator_ be _iteratorRecord_.[[Iterator]]. 1. Let _innerResult_ be Completion(GetMethod(_iterator_, *"return"*)). - 1. If _innerResult_.[[Type]] is ~normal~, then + 1. If _innerResult_ is a normal completion, then 1. Let _return_ be _innerResult_.[[Value]]. 1. If _return_ is *undefined*, return ? _completion_. 1. Set _innerResult_ to Completion(Call(_return_, _iterator_)). - 1. If _completion_.[[Type]] is ~throw~, return ? _completion_. - 1. If _innerResult_.[[Type]] is ~throw~, return ? _innerResult_. + 1. If _completion_ is a throw completion, return ? _completion_. + 1. If _innerResult_ is a throw completion, return ? _innerResult_. 1. If _innerResult_.[[Value]] is not an Object, throw a *TypeError* exception. 1. Return ? _completion_. @@ -7048,13 +7048,13 @@

1. Assert: _iteratorRecord_.[[Iterator]] is an Object. 1. Let _iterator_ be _iteratorRecord_.[[Iterator]]. 1. Let _innerResult_ be Completion(GetMethod(_iterator_, *"return"*)). - 1. If _innerResult_.[[Type]] is ~normal~, then + 1. If _innerResult_ is a normal completion, then 1. Let _return_ be _innerResult_.[[Value]]. 1. If _return_ is *undefined*, return ? _completion_. 1. Set _innerResult_ to Completion(Call(_return_, _iterator_)). - 1. If _innerResult_.[[Type]] is ~normal~, set _innerResult_ to Completion(Await(_innerResult_.[[Value]])). - 1. If _completion_.[[Type]] is ~throw~, return ? _completion_. - 1. If _innerResult_.[[Type]] is ~throw~, return ? _innerResult_. + 1. If _innerResult_ is a normal completion, set _innerResult_ to Completion(Await(_innerResult_.[[Value]])). + 1. If _completion_ is a throw completion, return ? _completion_. + 1. If _innerResult_ is a throw completion, return ? _innerResult_. 1. If _innerResult_.[[Value]] is not an Object, throw a *TypeError* exception. 1. Return ? _completion_. @@ -13257,7 +13257,7 @@

1. Perform OrdinaryCallBindThis(_F_, _calleeContext_, _thisArgument_). 1. Let _result_ be Completion(OrdinaryCallEvaluateBody(_F_, _argumentsList_)). 1. [id="step-call-pop-context-stack"] Remove _calleeContext_ from the execution context stack and restore _callerContext_ as the running execution context. - 1. If _result_.[[Type]] is ~return~, return _result_.[[Value]]. + 1. If _result_ is a return completion, return _result_.[[Value]]. 1. ReturnIfAbrupt(_result_). 1. Return *undefined*. @@ -13431,7 +13431,7 @@

1. Let _constructorEnv_ be the LexicalEnvironment of _calleeContext_. 1. Let _result_ be Completion(OrdinaryCallEvaluateBody(_F_, _argumentsList_)). 1. Remove _calleeContext_ from the execution context stack and restore _callerContext_ as the running execution context. - 1. If _result_.[[Type]] is ~return~, then + 1. If _result_ is a return completion, then 1. If _result_.[[Value]] is an Object, return _result_.[[Value]]. 1. If _kind_ is ~base~, return _thisArgument_. 1. If _result_.[[Value]] is not *undefined*, throw a *TypeError* exception. @@ -21696,8 +21696,8 @@

- 1. If _completion_.[[Type]] is ~normal~, return *true*. - 1. If _completion_.[[Type]] is not ~continue~, return *false*. + 1. If _completion_ is a normal completion, return *true*. + 1. If _completion_ is not a continue completion, return *false*. 1. If _completion_.[[Target]] is ~empty~, return *true*. 1. If _labelSet_ contains _completion_.[[Target]], return *true*. 1. Return *false*. @@ -22869,7 +22869,7 @@

BreakableStatement : IterationStatement 1. Let _stmtResult_ be Completion(LoopEvaluation of |IterationStatement| with argument _labelSet_). - 1. If _stmtResult_.[[Type]] is ~break~, then + 1. If _stmtResult_ is a break completion, then 1. If _stmtResult_.[[Target]] is ~empty~, then 1. If _stmtResult_.[[Value]] is ~empty~, set _stmtResult_ to NormalCompletion(*undefined*). 1. Else, set _stmtResult_ to NormalCompletion(_stmtResult_.[[Value]]). @@ -22878,7 +22878,7 @@

BreakableStatement : SwitchStatement 1. Let _stmtResult_ be Completion(Evaluation of |SwitchStatement|). - 1. If _stmtResult_.[[Type]] is ~break~, then + 1. If _stmtResult_ is a break completion, then 1. If _stmtResult_.[[Target]] is ~empty~, then 1. If _stmtResult_.[[Value]] is ~empty~, set _stmtResult_ to NormalCompletion(*undefined*). 1. Else, set _stmtResult_ to NormalCompletion(_stmtResult_.[[Value]]). @@ -22892,7 +22892,7 @@

1. Let _label_ be the StringValue of |LabelIdentifier|. 1. Let _newLabelSet_ be the list-concatenation of _labelSet_ and « _label_ ». 1. Let _stmtResult_ be Completion(LabelledEvaluation of |LabelledItem| with argument _newLabelSet_). - 1. If _stmtResult_.[[Type]] is ~break~ and _stmtResult_.[[Target]] is _label_, then + 1. If _stmtResult_ is a break completion and _stmtResult_.[[Target]] is _label_, then 1. Set _stmtResult_ to NormalCompletion(_stmtResult_.[[Value]]). 1. Return ? _stmtResult_. @@ -23023,7 +23023,7 @@

Runtime Semantics: Evaluation

TryStatement : `try` Block Catch 1. Let _B_ be Completion(Evaluation of |Block|). - 1. If _B_.[[Type]] is ~throw~, let _C_ be Completion(CatchClauseEvaluation of |Catch| with argument _B_.[[Value]]). + 1. If _B_ is a throw completion, let _C_ be Completion(CatchClauseEvaluation of |Catch| with argument _B_.[[Value]]). 1. Else, let _C_ be _B_. 1. Return ? UpdateEmpty(_C_, *undefined*). @@ -23031,16 +23031,16 @@

Runtime Semantics: Evaluation

1. Let _B_ be Completion(Evaluation of |Block|). 1. Let _F_ be Completion(Evaluation of |Finally|). - 1. If _F_.[[Type]] is ~normal~, set _F_ to _B_. + 1. If _F_ is a normal completion, set _F_ to _B_. 1. Return ? UpdateEmpty(_F_, *undefined*). TryStatement : `try` Block Catch Finally 1. Let _B_ be Completion(Evaluation of |Block|). - 1. If _B_.[[Type]] is ~throw~, let _C_ be Completion(CatchClauseEvaluation of |Catch| with argument _B_.[[Value]]). + 1. If _B_ is a throw completion, let _C_ be Completion(CatchClauseEvaluation of |Catch| with argument _B_.[[Value]]). 1. Else, let _C_ be _B_. 1. Let _F_ be Completion(Evaluation of |Finally|). - 1. If _F_.[[Type]] is ~normal~, set _F_ to _C_. + 1. If _F_ is a normal completion, set _F_ to _C_. 1. Return ? UpdateEmpty(_F_, *undefined*). @@ -24121,7 +24121,7 @@

Runtime Semantics: Evaluation

1. Let _iterator_ be _iteratorRecord_.[[Iterator]]. 1. Let _received_ be NormalCompletion(*undefined*). 1. Repeat, - 1. If _received_.[[Type]] is ~normal~, then + 1. If _received_ is a normal completion, then 1. Let _innerResult_ be ? Call(_iteratorRecord_.[[NextMethod]], _iteratorRecord_.[[Iterator]], « _received_.[[Value]] »). 1. If _generatorKind_ is ~async~, set _innerResult_ to ? Await(_innerResult_). 1. If _innerResult_ is not an Object, throw a *TypeError* exception. @@ -24130,7 +24130,7 @@

Runtime Semantics: Evaluation

1. Return ? IteratorValue(_innerResult_). 1. If _generatorKind_ is ~async~, set _received_ to Completion(AsyncGeneratorYield(? IteratorValue(_innerResult_))). 1. Else, set _received_ to Completion(GeneratorYield(_innerResult_)). - 1. Else if _received_.[[Type]] is ~throw~, then + 1. Else if _received_ is a throw completion, then 1. Let _throw_ be ? GetMethod(_iterator_, *"throw"*). 1. If _throw_ is not *undefined*, then 1. Let _innerResult_ be ? Call(_throw_, _iterator_, « _received_.[[Value]] »). @@ -24150,7 +24150,7 @@

Runtime Semantics: Evaluation

1. NOTE: The next step throws a *TypeError* to indicate that there was a `yield*` protocol violation: _iterator_ does not have a `throw` method. 1. Throw a *TypeError* exception. 1. Else, - 1. Assert: _received_.[[Type]] is ~return~. + 1. Assert: _received_ is a return completion. 1. Let _return_ be ? GetMethod(_iterator_, *"return"*). 1. If _return_ is *undefined*, then 1. Set _value_ to _received_.[[Value]]. @@ -25976,9 +25976,9 @@

1. Push _scriptContext_ onto the execution context stack; _scriptContext_ is now the running execution context. 1. Let _script_ be _scriptRecord_.[[ECMAScriptCode]]. 1. Let _result_ be Completion(GlobalDeclarationInstantiation(_script_, _globalEnv_)). - 1. If _result_.[[Type]] is ~normal~, then + 1. If _result_ is a normal completion, then 1. Set _result_ to Completion(Evaluation of _script_). - 1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then + 1. If _result_ is a normal completion and _result_.[[Value]] is ~empty~, then 1. Set _result_ to NormalCompletion(*undefined*). 1. Suspend _scriptContext_ and remove it from the execution context stack. 1. Assert: The execution context stack is not empty. @@ -28256,7 +28256,7 @@

Runtime Semantics: Evaluation

ModuleBody : ModuleItemList 1. Let _result_ be Completion(Evaluation of |ModuleItemList|). - 1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then + 1. If _result_ is a normal completion and _result_.[[Value]] is ~empty~, then 1. Return *undefined*. 1. Return ? _result_. @@ -29007,9 +29007,9 @@

1. Set _evalContext_'s PrivateEnvironment to _privateEnv_. 1. Push _evalContext_ onto the execution context stack; _evalContext_ is now the running execution context. 1. Let _result_ be Completion(EvalDeclarationInstantiation(_body_, _varEnv_, _lexEnv_, _privateEnv_, _strictEval_)). - 1. If _result_.[[Type]] is ~normal~, then + 1. If _result_ is a normal completion, then 1. Set _result_ to Completion(Evaluation of _body_). - 1. If _result_.[[Type]] is ~normal~ and _result_.[[Value]] is ~empty~, then + 1. If _result_ is a normal completion and _result_.[[Value]] is ~empty~, then 1. Set _result_ to NormalCompletion(*undefined*). 1. Suspend _evalContext_ and remove it from the execution context stack. 1. Resume the context that is now on the top of the execution context stack as the running execution context. @@ -47600,12 +47600,12 @@

1. Remove _acGenContext_ 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. Set _acGenerator_.[[GeneratorState]] to ~completed~. 1. NOTE: Once a generator enters the ~completed~ state it never leaves it and its associated execution context is never resumed. Any execution state associated with _acGenerator_ can be discarded at this point. - 1. If _result_.[[Type]] is ~normal~, then + 1. If _result_ is a normal completion, then 1. Let _resultValue_ be *undefined*. - 1. Else if _result_.[[Type]] is ~return~, then + 1. Else if _result_ is a return completion, then 1. Let _resultValue_ be _result_.[[Value]]. 1. Else, - 1. Assert: _result_.[[Type]] is ~throw~. + 1. Assert: _result_ is a throw completion. 1. Return ? _result_. 1. Return CreateIterResultObject(_resultValue_, *true*). 1. Set the code evaluation state of _genContext_ such that when evaluation is resumed for that execution context, _closure_ will be called with no arguments. @@ -47677,7 +47677,7 @@

1. NOTE: Once a generator enters the ~completed~ state it never leaves it and its associated execution context is never resumed. Any execution state associated with _generator_ can be discarded at this point. 1. Set _state_ to ~completed~. 1. If _state_ is ~completed~, then - 1. If _abruptCompletion_.[[Type]] is ~return~, then + 1. If _abruptCompletion_ is a return completion, then 1. Return CreateIterResultObject(_abruptCompletion_.[[Value]], *true*). 1. Return ? _abruptCompletion_. 1. Assert: _state_ is ~suspended-yield~. @@ -47956,8 +47956,8 @@

1. Assert: If we return here, the async generator either threw an exception or performed either an implicit or explicit return. 1. Remove _acGenContext_ 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. Set _acGenerator_.[[AsyncGeneratorState]] to ~completed~. - 1. If _result_.[[Type]] is ~normal~, set _result_ to NormalCompletion(*undefined*). - 1. If _result_.[[Type]] is ~return~, set _result_ to NormalCompletion(_result_.[[Value]]). + 1. If _result_ is a normal completion, set _result_ to NormalCompletion(*undefined*). + 1. If _result_ is a return completion, set _result_ to NormalCompletion(_result_.[[Value]]). 1. Perform AsyncGeneratorCompleteStep(_acGenerator_, _result_, *true*). 1. Perform AsyncGeneratorDrainQueue(_acGenerator_). 1. Return *undefined*. @@ -48021,10 +48021,10 @@

1. Remove the first element from _generator_.[[AsyncGeneratorQueue]]. 1. Let _promiseCapability_ be _next_.[[Capability]]. 1. Let _value_ be _completion_.[[Value]]. - 1. If _completion_.[[Type]] is ~throw~, then + 1. If _completion_ is a throw completion, then 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _value_ »). 1. Else, - 1. Assert: _completion_.[[Type]] is ~normal~. + 1. Assert: _completion_ is a normal completion. 1. If _realm_ is present, then 1. Let _oldRealm_ be the running execution context's Realm. 1. Set the running execution context's Realm to _realm_. @@ -48069,10 +48069,10 @@

- 1. If _resumptionValue_.[[Type]] is not ~return~, return ? _resumptionValue_. + 1. If _resumptionValue_ is not a return completion, return ? _resumptionValue_. 1. Let _awaited_ be Completion(Await(_resumptionValue_.[[Value]])). - 1. If _awaited_.[[Type]] is ~throw~, return ? _awaited_. - 1. Assert: _awaited_.[[Type]] is ~normal~. + 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~ }. @@ -48124,7 +48124,7 @@

1. Assert: _queue_ is not empty. 1. Let _next_ be the first element of _queue_. 1. Let _completion_ be Completion(_next_.[[Completion]]). - 1. Assert: _completion_.[[Type]] is ~return~. + 1. Assert: _completion_ is a return completion. 1. Let _promise_ be ? PromiseResolve(%Promise%, _completion_.[[Value]]). 1. Let _fulfilledClosure_ be a new Abstract Closure with parameters (_value_) that captures _generator_ and performs the following steps when called: 1. Set _generator_.[[AsyncGeneratorState]] to ~completed~. @@ -48163,12 +48163,12 @@

1. Repeat, while _done_ is *false*, 1. Let _next_ be the first element of _queue_. 1. Let _completion_ be Completion(_next_.[[Completion]]). - 1. If _completion_.[[Type]] is ~return~, then + 1. If _completion_ is a return completion, then 1. Set _generator_.[[AsyncGeneratorState]] to ~awaiting-return~. 1. Perform ! AsyncGeneratorAwaitReturn(_generator_). 1. Set _done_ to *true*. 1. Else, - 1. If _completion_.[[Type]] is ~normal~, then + 1. If _completion_ is a normal completion, then 1. Set _completion_ to NormalCompletion(*undefined*). 1. Perform AsyncGeneratorCompleteStep(_generator_, _completion_, *true*). 1. If _queue_ is empty, set _done_ to *true*. @@ -48340,12 +48340,12 @@

1. Let _result_ be Completion(Evaluation of _asyncBody_). 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 _acAsyncContext_ 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_ is a normal completion, then 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « *undefined* »). - 1. Else if _result_.[[Type]] is ~return~, then + 1. Else if _result_ is a return completion, then 1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, « _result_.[[Value]] »). 1. Else, - 1. Assert: _result_.[[Type]] is ~throw~. + 1. Assert: _result_ is a throw completion. 1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _result_.[[Value]] »). 1. [id="step-asyncblockstart-return-undefined"] Return ~unused~. 1. Set the code evaluation state of _asyncContext_ such that when evaluation is resumed for that execution context, _closure_ will be called with no arguments.