Skip to content

Commit c754979

Browse files
bakkotljharb
authored andcommitted
Editorial: more explicit validation in CreateDynamicFunction (#2374)
1 parent 26061c0 commit c754979

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spec.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24956,20 +24956,24 @@ <h1>CreateDynamicFunction ( _constructor_, _newTarget_, _kind_, _args_ )</h1>
2495624956
1. If _newTarget_ is *undefined*, set _newTarget_ to _constructor_.
2495724957
1. If _kind_ is ~normal~, then
2495824958
1. Let _exprSym_ be the grammar symbol |FunctionExpression|.
24959-
1. Let _bodySym_ be the grammar symbol |FunctionBody|.
24959+
1. Let _bodySym_ be the grammar symbol |FunctionBody[~Yield, ~Await]|.
24960+
1. Let _parameterSym_ be the grammar symbol |FormalParameters[~Yield, ~Await]|.
2496024961
1. Let _fallbackProto_ be *"%Function.prototype%"*.
2496124962
1. Else if _kind_ is ~generator~, then
2496224963
1. Let _exprSym_ be the grammar symbol |GeneratorExpression|.
2496324964
1. Let _bodySym_ be the grammar symbol |GeneratorBody|.
24965+
1. Let _parameterSym_ be the grammar symbol |FormalParameters[+Yield, ~Await]|.
2496424966
1. Let _fallbackProto_ be *"%GeneratorFunction.prototype%"*.
2496524967
1. Else if _kind_ is ~async~, then
2496624968
1. Let _exprSym_ be the grammar symbol |AsyncFunctionExpression|.
2496724969
1. Let _bodySym_ be the grammar symbol |AsyncFunctionBody|.
24970+
1. Let _parameterSym_ be the grammar symbol |FormalParameters[~Yield, +Await]|.
2496824971
1. Let _fallbackProto_ be *"%AsyncFunction.prototype%"*.
2496924972
1. Else,
2497024973
1. Assert: _kind_ is ~asyncGenerator~.
2497124974
1. Let _exprSym_ be the grammar symbol |AsyncGeneratorExpression|.
2497224975
1. Let _bodySym_ be the grammar symbol |AsyncGeneratorBody|.
24976+
1. Let _parameterSym_ be the grammar symbol |FormalParameters[+Yield, +Await]|.
2497324977
1. Let _fallbackProto_ be *"%AsyncGeneratorFunction.prototype%"*.
2497424978
1. Let _argCount_ be the number of elements in _args_.
2497524979
1. Let _P_ be the empty String.
@@ -24990,10 +24994,14 @@ <h1>CreateDynamicFunction ( _constructor_, _newTarget_, _kind_, _args_ )</h1>
2499024994
1. Let _prefix_ be the prefix associated with _kind_ in <emu-xref href="#table-dynamic-function-sourcetext-prefixes"></emu-xref>.
2499124995
1. Let _sourceString_ be the string-concatenation of _prefix_, *" anonymous("*, _P_, 0x000A (LINE FEED), *") {"*, _bodyString_, and *"}"*.
2499224996
1. Let _sourceText_ be ! StringToCodePoints(_sourceString_).
24997+
1. Let _parameters_ be ParseText(! StringToCodePoints(_P_), _parameterSym_).
24998+
1. If _parameters_ is a List of errors, throw a *SyntaxError* exception.
24999+
1. Let _body_ be ParseText(! StringToCodePoints(_bodyString_), _bodySym_).
25000+
1. If _body_ is a List of errors, throw a *SyntaxError* exception.
25001+
1. NOTE: The parameters and body are parsed separately to ensure that each is valid alone. For example, `new Function("/*", "*/ ) {")` is not legal.
25002+
1. NOTE: If this step is reached, _sourceText_ must match _exprSym_ (although the reverse implication does not hold). The purpose of the next two steps is to enforce any Early Error rules which apply to _exprSym_ directly.
2499325003
1. Let _expr_ be ParseText(_sourceText_, _exprSym_).
2499425004
1. If _expr_ is a List of errors, throw a *SyntaxError* exception.
24995-
1. Let _parameters_ be the |FormalParameters| of _expr_.
24996-
1. Let _body_ be the child of _expr_ that is an instance of _bodySym_.
2499725005
1. Let _proto_ be ? GetPrototypeFromConstructor(_newTarget_, _fallbackProto_).
2499825006
1. Let _realmF_ be the current Realm Record.
2499925007
1. Let _scope_ be _realmF_.[[GlobalEnv]].

0 commit comments

Comments
 (0)