-
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: Set [[SourceText]] inside OrdinaryFunctionCreate #1870
Conversation
spec.html
Outdated
@@ -8555,13 +8555,15 @@ <h1>[[Construct]] ( _argumentsList_, _newTarget_ )</h1> | |||
</emu-clause> | |||
|
|||
<emu-clause id="sec-ordinaryfunctioncreate" aoid="OrdinaryFunctionCreate" oldids="sec-functionallocate,sec-functioninitialize,sec-functioncreate,sec-generatorfunctioncreate,sec-asyncgeneratorfunctioncreate,sec-async-functions-abstract-operations-async-function-create"> | |||
<h1>OrdinaryFunctionCreate ( _functionPrototype_, _ParameterList_, _Body_, _thisMode_, _Scope_ )</h1> | |||
<p>The abstract operation OrdinaryFunctionCreate requires the arguments: an object _functionPrototype_, a parameter list Parse Node specified by _ParameterList_, a body Parse Node specified by _Body_, _thisMode_ which is either ~lexical-this~ or ~non-lexical-this~, and a Lexical Environment specified by _Scope_. OrdinaryFunctionCreate performs the following steps:</p> | |||
<h1>OrdinaryFunctionCreate ( _functionPrototype_, _definition_, _ParameterList_, _Body_, _thisMode_, _Scope_ )</h1> |
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.
it seems like this should be added last as an optional parameter, then it can default to ~empty~
?
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.
The parameter is almost always provided. I don't think using an optional parameter is worth it.
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.
Then, optional or not, why not at the end?
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.
The current parameter list has two Parse Node parameters (_ParameterList_
and _Body_
) for syntactic components of the function declaration. Since the new parameter is a Parse Node representing the whole declaration, it makes sense to put it next to those existing Parse Node parameters. Putting it before or after is somewhat debatable, but I put the new one before the existing ones because then the order of nonterminals in the invocations of OrdinaryFunctionCreate
is the same as in the associated production. E.g. for production:
FunctionDeclaration : `function` `(` FormalParameters `)` `{` FunctionBody `}`
the invocation is:
OrdinaryFunctionCreate(..., |FunctionDeclaration|, |FormalParameters|, |FunctionBody|, ...)
I think this makes it easier to understand/remember the order of parameters for this operation.
@jmdyck We discussed this during the editor call today. We'd feel more comfortable if the use of "the source text matched by" remained in the algorithm steps of the syntax-directed operations. We could still consolidate the assignment to |
I'm willing to go along with this, but (for possible future reference), can you articulate why it makes you feel more comfortable?
To be clear, are you saying
or
? Re the latter, it's uncommon for the spec to use a prose-y phrase as an argument to an operation, but it does occur, e.g.:
Or, to avoid the prose-y argument, we could 'extract' the source text via an operation. I suggested |
Either, but I'd prefer the former. |
(force-pushed a version that should be more acceptable to the editors) |
(force-pushed to resolve merge conflicts) |
(force-pushed to resolve merge conflicts) |
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.
lgtm. Holy cow there are a lot of users of OrdinaryFunctionCreate.
Formerly, every call to OrdinaryFunctionCreate was closely followed by a step that set the [[SourceText]] of the resulting function object. Instead, set the function's [[SourceText]] within OrdinaryFunctionCreate by passing it a _sourceText_ parameter.
... that accompanies the NamedEvaluation semantics for ArrowFunction : ArrowParameters `=>` ConciseBody PR tc39#1870 (among other things) inserted a step before the former step 3, but didn't update the note that referenced it.
... that accompanies the NamedEvaluation semantics for ArrowFunction : ArrowParameters `=>` ConciseBody PR tc39#1870 (among other things) inserted a step before the former step 3, but didn't update the note that referenced it.
Editorial: Reinstate an SDO rule PR tc39#1933 deleted SDO rules that are handled by the chain production rule, but it also deleted this one which isn't. (It has "TV" on the left and "TRV" on the right.) Editorial: Move an <emu-note> element PR tc39#1490 (among other things) moved the evaluation semantics for ArrowFunction from the Evaluation SDO to the NamedEvaluation SDO. The accompanying <emu-note> should have moved at the same time (in particular because of the reference to "step 3"). Editorial: Delete <emu-note> in TimeClip clause PR tc39#1827 (among other things) removed step 4 from the algorithm for TimeClip, obsoleting the accompanying emu-note that describes "the point of step 4". Conceivably, the note could be reworded to describe the effect of 'ToInteger' on step 3, but I don't think it'd be worth the bother. Editorial: Change "Step 2.a" to "Step 2.b" in RepeatMatcher note PR tc39#1889 (among other things) inserted a step before the former 2.a, but didn't update the note that referenced it. Editorial: Change step 7 to step 6 in SortCompare note Commit 9c1e076 (2015-10-26) introduced the '?' abbreviation for ReturnIfAbrupt. This caused the ToString call on step 7 to move to step 6, but the note that referred to it wasn't updated. Editorial: Fix typo: "Descritor" -> "Descriptor" Editorial: Fix typo: "GeneratorObject" -> "generator object" (There's no such thing as a GeneratorObject.) Editorial: Delete "as a parameter" after "is present" (It's the only place in the spec where we use that phrasing.) Editorial: Change "which" to "that" ... in "{String,Array,Map,Set} methods which return such iterators" Editorial: Insert a comma in SetDefaultGlobalBindings() Formerly, it read like "containing" modified "the property", when it actually modified "the property descriptor". Editorial: Change "lexical environment" to "Environment Record" ... in FunctionDeclarationInstantiation, to balance the NOTE in the other arm of the if-else, and also for consistency with the NOTE at 27.a. (I should have done this in PR tc39#1697.) Editorial: Change "step 3" to "step 4" in Note ... that accompanies the NamedEvaluation semantics for ArrowFunction : ArrowParameters `=>` ConciseBody PR tc39#1870 (among other things) inserted a step before the former step 3, but didn't update the note that referenced it.
Every call to OrdinaryFunctionCreate is closely followed by a step that sets the
[[SourceText]]
of the resulting function object. Replace all but one of the latter steps by passing another argumentto
OrdinaryFunctionCreate
.Re "all but one": the exception is in
CreateDynamicFunction
, where there isn't a Parse Node that represents the whole function, so we just pass~empty~
toOrdinaryFunctionCreate
and set the function's[[SourceText]]
explicitly later. If you'd like this case to be handled insideOrdinaryFunctionCreate
as well, I can think of a few ways:Say that the new parameter is either a Parse Node (handled as in this PR) or it's a sequence of Unicode code points (which gets assigned directly to
_F_.[[SourceText]]
). InCreateDynamicFunction
, we'd move up the definitions of_prefix_
and_sourceString_
, and then passUTF16DecodeString(_sourceString_)
to the new parameter.Say that the new parameter is always a sequence of Unicode code points.
CreateDynamicFunction
would be handled as above, but all the other invocations would be preceded by a stepLet _sourceText_ be the source text matched by |Foo|.
and then pass_sourceText_
rather than|Foo|
to the new parameter. This would undo most of the savings of this PR, although we could regain most of it if we defined an abstract operation that returned the source text matched by a Parse Node; then we could avoid the extra step and pass (say)SourceText(|Foo|)
to the new parameter.Say that the new parameter is always a Parse Node. In
CreateDynamicFunction
, you'd have to actually parseUTF16DecodeString(_sourceString_)
and then pass the result to the new parameter. Note that we're already parsing most of it, to get the values of_parameters_
and_body_
, so parsing the whole thing isn't that big a stretch (and you could extract_parameters_
and_body_
from it, instead of parsing them separately). The goal symbol for the parse would depend on_kind_
, so we could specify that in a new column in the following table.Downstream uses:
~empty~
. With any of the bulleted alternatives, it would have to do something else (possibly similar to whatCreateDynamicFunction
does). But it raises the question of what is web reality for the toString of a function created in this way.