Skip to content

Commit

Permalink
Editorial: Tweak the param list of Function constructors (#2902)
Browse files Browse the repository at this point in the history
In the specification of each of the constructors:
- Function
- GeneratorFunction
- AsyncGeneratorFunction
- AsyncFunction

change the parameter list from
`( _p1_, _p2_, … , _pn_, _body_ )`
to
`( _parameterArgs_, _bodyArg_ )`

Also, modify CreateDynamicFunction to take
`_parameterArgs_` and `_bodyArg_` separately.
  • Loading branch information
jmdyck authored and ljharb committed Nov 29, 2022
1 parent fff9c19 commit e26fa78
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -29575,13 +29575,13 @@ <h1>The Function Constructor</h1>
</ul>

<emu-clause id="sec-function-p1-p2-pn-body">
<h1>Function ( _p1_, _p2_, … , _pn_, _body_ )</h1>
<h1>Function ( ..._parameterArgs_, _bodyArg_ )</h1>
<p>The last argument (if any) specifies the body (executable code) of a function; any preceding arguments specify formal parameters.</p>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Let _C_ be the active function object.
1. [declared="argumentsList"] Let _args_ be the _argumentsList_ that was passed to this function by [[Call]] or [[Construct]].
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~normal~, _args_).
1. If _bodyArg_ is not present, set _bodyArg_ to the empty String.
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~normal~, _parameterArgs_, _bodyArg_).
</emu-alg>
<emu-note>
<p>It is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the following expressions produce the same result:</p>
Expand All @@ -29598,12 +29598,13 @@ <h1>
_constructor_: a constructor,
_newTarget_: a constructor,
_kind_: ~normal~, ~generator~, ~async~, or ~asyncGenerator~,
_args_: a List of ECMAScript language values,
_parameterArgs_: a List of ECMAScript language values,
_bodyArg_: an ECMAScript language value,
): either a normal completion containing a function object or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>_constructor_ is the constructor function that is performing this action. _newTarget_ is the constructor that `new` was initially applied to. _args_ is the argument values that were passed to _constructor_.</dd>
<dd>_constructor_ is the constructor function that is performing this action. _newTarget_ is the constructor that `new` was initially applied to. _parameterArgs_ and _bodyArg_ reflect the argument values that were passed to _constructor_.</dd>
</dl>
<emu-alg>
1. Let _currentRealm_ be the current Realm Record.
Expand Down Expand Up @@ -29634,21 +29635,17 @@ <h1>
1. Let _bodySym_ be the grammar symbol |AsyncGeneratorBody|.
1. Let _parameterSym_ be the grammar symbol |FormalParameters[+Yield, +Await]|.
1. Let _fallbackProto_ be *"%AsyncGeneratorFunction.prototype%"*.
1. Let _argCount_ be the number of elements in _args_.
1. Let _argCount_ be the number of elements in _parameterArgs_.
1. Let _P_ be the empty String.
1. If _argCount_ = 0, let _bodyArg_ be the empty String.
1. Else if _argCount_ = 1, let _bodyArg_ be _args_[0].
1. Else,
1. Assert: _argCount_ > 1.
1. Let _firstArg_ be _args_[0].
1. If _argCount_ > 0, then
1. Let _firstArg_ be _parameterArgs_[0].
1. Set _P_ to ? ToString(_firstArg_).
1. Let _k_ be 1.
1. Repeat, while _k_ &lt; _argCount_ - 1,
1. Let _nextArg_ be _args_[_k_].
1. Repeat, while _k_ &lt; _argCount_,
1. Let _nextArg_ be _parameterArgs_[_k_].
1. Let _nextArgString_ be ? ToString(_nextArg_).
1. Set _P_ to the string-concatenation of _P_, *","* (a comma), and _nextArgString_.
1. Set _k_ to _k_ + 1.
1. Let _bodyArg_ be _args_[_k_].
1. Let _bodyString_ be the string-concatenation of 0x000A (LINE FEED), ? ToString(_bodyArg_), and 0x000A (LINE FEED).
1. Let _sourceString_ be the string-concatenation of _prefix_, *" anonymous("*, _P_, 0x000A (LINE FEED), *") {"*, _bodyString_, and *"}"*.
1. Let _sourceText_ be StringToCodePoints(_sourceString_).
Expand Down Expand Up @@ -44666,13 +44663,13 @@ <h1>The GeneratorFunction Constructor</h1>
</ul>

<emu-clause id="sec-generatorfunction">
<h1>GeneratorFunction ( _p1_, _p2_, … , _pn_, _body_ )</h1>
<h1>GeneratorFunction ( ..._parameterArgs_, _bodyArg_ )</h1>
<p>The last argument (if any) specifies the body (executable code) of a generator function; any preceding arguments specify formal parameters.</p>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Let _C_ be the active function object.
1. [declared="argumentsList"] Let _args_ be the _argumentsList_ that was passed to this function by [[Call]] or [[Construct]].
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~generator~, _args_).
1. If _bodyArg_ is not present, set _bodyArg_ to the empty String.
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~generator~, _parameterArgs_, _bodyArg_).
</emu-alg>
<emu-note>
<p>See NOTE for <emu-xref href="#sec-function-p1-p2-pn-body"></emu-xref>.</p>
Expand Down Expand Up @@ -44772,13 +44769,13 @@ <h1>The AsyncGeneratorFunction Constructor</h1>
</ul>

<emu-clause id="sec-asyncgeneratorfunction">
<h1>AsyncGeneratorFunction ( _p1_, _p2_, … , _pn_, _body_ )</h1>
<h1>AsyncGeneratorFunction ( ..._parameterArgs_, _bodyArg_ )</h1>
<p>The last argument (if any) specifies the body (executable code) of an async generator function; any preceding arguments specify formal parameters.</p>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Let _C_ be the active function object.
1. [declared="argumentsList"] Let _args_ be the _argumentsList_ that was passed to this function by [[Call]] or [[Construct]].
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~asyncGenerator~, _args_).
1. If _bodyArg_ is not present, set _bodyArg_ to the empty String.
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~asyncGenerator~, _parameterArgs_, _bodyArg_).
</emu-alg>
<emu-note>
<p>See NOTE for <emu-xref href="#sec-function-p1-p2-pn-body"></emu-xref>.</p>
Expand Down Expand Up @@ -45618,14 +45615,14 @@ <h1>The AsyncFunction Constructor</h1>
</ul>

<emu-clause id="sec-async-function-constructor-arguments">
<h1>AsyncFunction ( _p1_, _p2_, … , _pn_, _body_ )</h1>
<h1>AsyncFunction ( ..._parameterArgs_, _bodyArg_ )</h1>
<p>The last argument (if any) specifies the body (executable code) of an async function. Any preceding arguments specify formal parameters.</p>
<p>This function performs the following steps when called:</p>

<emu-alg>
1. Let _C_ be the active function object.
1. [declared="argumentsList"] Let _args_ be the _argumentsList_ that was passed to this function by [[Call]] or [[Construct]].
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~async~, _args_).
1. If _bodyArg_ is not present, set _bodyArg_ to the empty String.
1. Return ? CreateDynamicFunction(_C_, NewTarget, ~async~, _parameterArgs_, _bodyArg_).
</emu-alg>

<emu-note>See NOTE for <emu-xref href="#sec-function-p1-p2-pn-body"></emu-xref>.</emu-note>
Expand Down

0 comments on commit e26fa78

Please sign in to comment.