Skip to content

Commit 263aa4c

Browse files
authored
Move DisposeResources to Evaluation of FunctionStatementList (#178)
1 parent e1ef220 commit 263aa4c

File tree

1 file changed

+37
-151
lines changed

1 file changed

+37
-151
lines changed

spec.emu

Lines changed: 37 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,25 +3097,6 @@ contributors: Ron Buckton, Ecma International
30973097
<emu-clause id="sec-function-definitions">
30983098
<h1>Function Definitions</h1>
30993099

3100-
<emu-clause id="sec-runtime-semantics-evaluatefunctionbody" oldids="sec-function-definitions-runtime-semantics-evaluatebody" type="sdo">
3101-
<h1>
3102-
Runtime Semantics: EvaluateFunctionBody (
3103-
_functionObject_: unknown,
3104-
_argumentsList_: a List,
3105-
): either a normal completion containing an ECMAScript language value or an abrupt completion
3106-
</h1>
3107-
<dl class="header">
3108-
</dl>
3109-
<emu-grammar>FunctionBody : FunctionStatementList</emu-grammar>
3110-
<emu-alg>
3111-
1. Perform ? FunctionDeclarationInstantiation(_functionObject_, _argumentsList_).
3112-
1. <del>Return ? Evaluation of |FunctionStatementList|.</del>
3113-
1. <ins>Let _result_ be Completion(Evaluation of |FunctionStatementList|).</ins>
3114-
1. <ins>Let _env_ be the running execution context's LexicalEnvironment.</ins>
3115-
1. <ins>Return ? DisposeResources(_env_.[[DisposeCapability]], _result_).</ins>
3116-
</emu-alg>
3117-
</emu-clause>
3118-
31193100
<emu-clause id="sec-runtime-semantics-instantiateordinaryfunctionexpression" type="sdo">
31203101
<h1>
31213102
Runtime Semantics: InstantiateOrdinaryFunctionExpression (
@@ -3154,6 +3135,43 @@ contributors: Ron Buckton, Ecma International
31543135
<p>The |BindingIdentifier| in a |FunctionExpression| can be referenced from inside the |FunctionExpression|'s |FunctionBody| to allow the function to call itself recursively. However, unlike in a |FunctionDeclaration|, the |BindingIdentifier| in a |FunctionExpression| cannot be referenced from and does not affect the scope enclosing the |FunctionExpression|.</p>
31553136
</emu-note>
31563137
</emu-clause>
3138+
3139+
<emu-clause id="sec-function-definitions-runtime-semantics-evaluation" type="sdo">
3140+
<h1>Runtime Semantics: Evaluation</h1>
3141+
<emu-grammar>FunctionDeclaration : `function` BindingIdentifier `(` FormalParameters `)` `{` FunctionBody `}`</emu-grammar>
3142+
<emu-alg>
3143+
1. Return ~empty~.
3144+
</emu-alg>
3145+
<emu-note>
3146+
<p>An alternative semantics is provided in <emu-xref href="#sec-block-level-function-declarations-web-legacy-compatibility-semantics"></emu-xref>.</p>
3147+
</emu-note>
3148+
<emu-grammar>FunctionDeclaration : `function` `(` FormalParameters `)` `{` FunctionBody `}`</emu-grammar>
3149+
<emu-alg>
3150+
1. Return ~empty~.
3151+
</emu-alg>
3152+
<emu-grammar>
3153+
FunctionExpression : `function` BindingIdentifier? `(` FormalParameters `)` `{` FunctionBody `}`
3154+
</emu-grammar>
3155+
<emu-alg>
3156+
1. Return InstantiateOrdinaryFunctionExpression of |FunctionExpression|.
3157+
</emu-alg>
3158+
<emu-note>
3159+
<p>A *"prototype"* property is automatically created for every function defined using a |FunctionDeclaration| or |FunctionExpression|, to allow for the possibility that the function will be used as a constructor.</p>
3160+
</emu-note>
3161+
<emu-grammar>FunctionStatementList : [empty]</emu-grammar>
3162+
<emu-alg>
3163+
1. Return *undefined*.
3164+
</emu-alg>
3165+
<ins class="block">
3166+
<emu-grammar>FunctionStatementList : StatementList</emu-grammar>
3167+
<emu-alg>
3168+
1. Let _result_ be Completion(Evaluation of |StatementList|).
3169+
1. Let _env_ be the running execution context's LexicalEnvironment.
3170+
1. Assert: _env_ is a Declarative Environment Record.
3171+
1. Return ? DisposeResources(_env_.[[DisposeCapability]], _result_).
3172+
</emu-alg>
3173+
</ins>
3174+
</emu-clause>
31573175
</emu-clause>
31583176

31593177
<emu-clause id="sec-generator-function-definitions">
@@ -4813,138 +4831,6 @@ contributors: Ron Buckton, Ecma International
48134831
</emu-clause>
48144832
</emu-clause>
48154833
</ins>
4816-
4817-
<emu-clause id="sec-generator-objects">
4818-
<h1>Generator Objects</h1>
4819-
4820-
<emu-clause id="sec-generator-abstract-operations">
4821-
<h1>Generator Abstract Operations</h1>
4822-
4823-
<emu-clause id="sec-generatorstart" type="abstract operation">
4824-
<h1>
4825-
GeneratorStart (
4826-
_generator_: unknown,
4827-
_generatorBody_: a |FunctionBody| Parse Node or an Abstract Closure with no parameters,
4828-
): ~unused~
4829-
</h1>
4830-
<dl class="header">
4831-
</dl>
4832-
<emu-alg>
4833-
1. Assert: The value of _generator_.[[GeneratorState]] is *undefined*.
4834-
1. Let _genContext_ be the running execution context.
4835-
1. Set the Generator component of _genContext_ to _generator_.
4836-
1. [fence-effects="user-code"] Set the code evaluation state of _genContext_ such that when evaluation is resumed for that execution context the following steps will be performed:
4837-
1. If _generatorBody_ is a Parse Node, then
4838-
1. Let _result_ be the result of evaluating _generatorBody_.
4839-
1. Else,
4840-
1. Assert: _generatorBody_ is an Abstract Closure with no parameters.
4841-
1. Let _result_ be _generatorBody_().
4842-
1. Assert: If we return here, the generator either threw an exception or performed either an implicit or explicit return.
4843-
1. Remove _genContext_ 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.
4844-
1. Set _generator_.[[GeneratorState]] to ~completed~.
4845-
1. 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.
4846-
1. <ins>Let _env_ be _genContext_'s LexicalEnvironment.</ins>
4847-
1. <ins>Set _result_ to DisposeResources(_env_.[[DisposeCapability]], _result_).</ins>
4848-
1. If _result_.[[Type]] is ~normal~, let _resultValue_ be *undefined*.
4849-
1. Else if _result_.[[Type]] is ~return~, let _resultValue_ be _result_.[[Value]].
4850-
1. Else,
4851-
1. Assert: _result_.[[Type]] is ~throw~.
4852-
1. Return ? _result_.
4853-
1. Return CreateIterResultObject(_resultValue_, *true*).
4854-
1. Set _generator_.[[GeneratorContext]] to _genContext_.
4855-
1. Set _generator_.[[GeneratorState]] to ~suspendedStart~.
4856-
1. Return ~unused~.
4857-
</emu-alg>
4858-
</emu-clause>
4859-
</emu-clause>
4860-
</emu-clause>
4861-
4862-
<emu-clause id="sec-asyncgenerator-objects">
4863-
<h1>AsyncGenerator Objects</h1>
4864-
4865-
<emu-clause id="sec-asyncgenerator-abstract-operations">
4866-
<h1>AsyncGenerator Abstract Operations</h1>
4867-
4868-
<emu-clause id="sec-asyncgeneratorstart" type="abstract operation">
4869-
<h1>
4870-
AsyncGeneratorStart (
4871-
_generator_: an AsyncGenerator,
4872-
_generatorBody_: a |FunctionBody| Parse Node or an Abstract Closure with no parameters,
4873-
): ~unused~
4874-
</h1>
4875-
<dl class="header">
4876-
</dl>
4877-
<emu-alg>
4878-
1. Assert: _generator_.[[AsyncGeneratorState]] is *undefined*.
4879-
1. Let _genContext_ be the running execution context.
4880-
1. Set the Generator component of _genContext_ to _generator_.
4881-
1. [fence-effects="user-code"] Set the code evaluation state of _genContext_ such that when evaluation is resumed for that execution context the following steps will be performed:
4882-
1. If _generatorBody_ is a Parse Node, then
4883-
1. Let _result_ be the result of evaluating _generatorBody_.
4884-
1. Else,
4885-
1. Assert: _generatorBody_ is an Abstract Closure with no parameters.
4886-
1. Let _result_ be Completion(_generatorBody_()).
4887-
1. Assert: If we return here, the async generator either threw an exception or performed either an implicit or explicit return.
4888-
1. Remove _genContext_ 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.
4889-
1. Set _generator_.[[AsyncGeneratorState]] to ~completed~.
4890-
1. <ins>Let _env_ be _genContext_'s LexicalEnvironment.</ins>
4891-
1. <ins>Set _result_ to DisposeResources(_env_.[[DisposeCapability]], _result_).</ins>
4892-
1. If _result_.[[Type]] is ~normal~, set _result_ to NormalCompletion(*undefined*).
4893-
1. If _result_.[[Type]] is ~return~, set _result_ to NormalCompletion(_result_.[[Value]]).
4894-
1. Perform AsyncGeneratorCompleteStep(_generator_, _result_, *true*).
4895-
1. Perform AsyncGeneratorDrainQueue(_generator_).
4896-
1. Return *undefined*.
4897-
1. Set _generator_.[[AsyncGeneratorContext]] to _genContext_.
4898-
1. Set _generator_.[[AsyncGeneratorState]] to ~suspendedStart~.
4899-
1. Set _generator_.[[AsyncGeneratorQueue]] to a new empty List.
4900-
1. Return ~unused~.
4901-
</emu-alg>
4902-
</emu-clause>
4903-
</emu-clause>
4904-
</emu-clause>
4905-
4906-
<emu-clause id="sec-async-function-objects">
4907-
<h1>AsyncFunction Objects</h1>
4908-
4909-
<emu-clause id="sec-async-functions-abstract-operations">
4910-
<h1>Async Functions Abstract Operations</h1>
4911-
4912-
<emu-clause id="sec-asyncblockstart" type="abstract operation">
4913-
<h1>
4914-
AsyncBlockStart (
4915-
_promiseCapability_: a PromiseCapability Record,
4916-
_asyncBody_: a Parse Node,
4917-
_asyncContext_: an execution context,
4918-
): ~unused~
4919-
</h1>
4920-
<dl class="header">
4921-
</dl>
4922-
<emu-alg>
4923-
1. Assert: _promiseCapability_ is a PromiseCapability Record.
4924-
1. Let _runningContext_ be the running execution context.
4925-
1. [fence-effects="user-code"] Set the code evaluation state of _asyncContext_ such that when evaluation is resumed for that execution context the following steps will be performed:
4926-
1. Let _result_ be the result of evaluating _asyncBody_.
4927-
1. Assert: If we return here, the async function either threw an exception or performed an implicit or explicit return; all awaiting is done.
4928-
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.
4929-
1. <ins>Let _env_ be _asyncContext_'s LexicalEnvironment.</ins>
4930-
1. <ins>Set _result_ to DisposeResources(_env_.[[DisposeCapability]], _result_).</ins>
4931-
1. If _result_.[[Type]] is ~normal~, then
4932-
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; *undefined* &raquo;).
4933-
1. Else if _result_.[[Type]] is ~return~, then
4934-
1. Perform ! Call(_promiseCapability_.[[Resolve]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
4935-
1. Else,
4936-
1. Assert: _result_.[[Type]] is ~throw~.
4937-
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, &laquo; _result_.[[Value]] &raquo;).
4938-
1. [id="step-asyncblockstart-return-undefined"] Return ~unused~.
4939-
1. Push _asyncContext_ onto the execution context stack; _asyncContext_ is now the running execution context.
4940-
1. <emu-meta effects="user-code">Resume the suspended evaluation of _asyncContext_</emu-meta>. Let _result_ be the value returned by the resumed computation.
4941-
1. Assert: When we return here, _asyncContext_ has already been removed from the execution context stack and _runningContext_ is the currently running execution context.
4942-
1. Assert: _result_ is a normal completion with a value of ~unused~. The possible sources of this value are Await or, if the async function doesn't await anything, step <emu-xref href="#step-asyncblockstart-return-undefined"></emu-xref> above.
4943-
1. Return ~unused~.
4944-
</emu-alg>
4945-
</emu-clause>
4946-
</emu-clause>
4947-
</emu-clause>
49484834
</emu-clause>
49494835

49504836
<emu-annex id="sec-additional-ecmascript-features-for-web-browsers" namespace="annexB" normative>

0 commit comments

Comments
 (0)