-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial: Simplify CreateDynamicFunction #2348
Conversation
spec.html
Outdated
1. If _strict_ is *true*, then | ||
1. If BoundNames of _parameters_ contains any duplicate elements, throw a *SyntaxError* exception. | ||
1. Let _expr_ be ParseText(_sourceText_, _exprSym_). | ||
1. NOTE: ParseText enforces all relevant Early Error rules, including those associated with _exprSym_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't think we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a commit to remove the NOTE step.
spec.html
Outdated
@@ -24986,21 +24986,21 @@ <h1>CreateDynamicFunction ( _constructor_, _newTarget_, _kind_, _args_ )</h1> | |||
1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _calleeRealm_). | |||
1. If _newTarget_ is *undefined*, set _newTarget_ to _constructor_. | |||
1. If _kind_ is ~normal~, then | |||
1. Let _goal_ be the grammar symbol |FunctionBody[~Yield, ~Await]|. | |||
1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, ~Await]|. | |||
1. Let _exprSym_ be the grammar symbol |FunctionExpression|. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be easier to use a table for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I'm pretty okay with the existing if-else cascade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a table for this would be fairly wide. (Its width would be determined by the AsyncGenerator row.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should perhaps go the other way and inline Table 51 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've got another PR planned that will take care of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still kinda prefer the tables for these cases. Maybe talk about it in the editor call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
spec.html
Outdated
@@ -24986,21 +24986,21 @@ <h1>CreateDynamicFunction ( _constructor_, _newTarget_, _kind_, _args_ )</h1> | |||
1. Perform ? HostEnsureCanCompileStrings(_callerRealm_, _calleeRealm_). | |||
1. If _newTarget_ is *undefined*, set _newTarget_ to _constructor_. | |||
1. If _kind_ is ~normal~, then | |||
1. Let _goal_ be the grammar symbol |FunctionBody[~Yield, ~Await]|. | |||
1. Let _parameterGoal_ be the grammar symbol |FormalParameters[~Yield, ~Await]|. | |||
1. Let _exprSym_ be the grammar symbol |FunctionExpression|. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I'm pretty okay with the existing if-else cascade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is greatly improved. I wish I knew why it was originally written with the more convoluted style - I'm worried there is some reason the two aren't equivalent, which necessitates the original complexity, but they really do appear to be the same.
Formerly, CreateDynamicFunction would parse the text for the parameters and body *separately*, so we didn't have a complete function decl/expr, so the Early Error rules for the function decl/expr production didn't apply automatically, so we had to apply them "manually". Instead, parse the text of a complete function expr (which text already exists in _sourceText_!), so that all the relevant Early Error rules apply automatically.
c162d7a
to
bbaac2f
Compare
For a call to the |
... into the if-else cascade in CreateDynamicFunction, as @bakkot suggested: tc39#2348 (comment)
... into the if-else cascade in CreateDynamicFunction, as @bakkot suggested: tc39#2348 (comment)
…2367) ... into the if-else cascade in CreateDynamicFunction, suggested in tc39#2348 (comment)
…2367) ... into the if-else cascade in CreateDynamicFunction, suggested in tc39#2348 (comment)
Formerly, CreateDynamicFunction would parse the text for the parameters and body separately, so we didn't have a complete function decl/expr, so the Early Error rules for the function decl/expr production didn't apply automatically, so we had to apply them "manually".
Instead, parse the text of a complete function expr (which text already exists in
_sourceText_
!), so that all the relevant Early Error rules apply automatically.I left a Note for the benefit of anyone who wonders where all the error-checking went, but it might be deemed unnecessary. (No other call to ParseText is accompanied by such a Note.)
This change has a side-benefit in that it will allow a simplification of the definition of "function code" (and strict function code). Currently, it's complicated by this one case (set of cases) where the Parameters and Body (and BindingIdentifier) of a function are not simply the children of a Declaration or Expression. This change will eliminate such cases.