Editorial: Merge FunctionAllocate and FunctionInitialize#1562
Editorial: Merge FunctionAllocate and FunctionInitialize#1562ljharb merged 5 commits intotc39:masterfrom
Conversation
spec.html
Outdated
| 1. Else, let _allocKind_ be `"normal"`. | ||
| 1. Let _F_ be FunctionAllocate(_prototype_, _Strict_, _allocKind_). | ||
| 1. Return FunctionInitialize(_F_, _kind_, _ParameterList_, _Body_, _Scope_). | ||
| 1. Return ! OrdinaryFunctionCreate(_prototype_, _ParameterList_, _Body_, _allocKind_, _kind_, _Strict_, _Scope_). |
There was a problem hiding this comment.
Is there a reason you didn’t keep the same param order - prototype, strict, allocKind, and then the initialize args?
There was a problem hiding this comment.
The resulting order didn't make sense to me.
There was a problem hiding this comment.
At the least, strict seems to me like it should come before body and parameter list, since it determines how it’s parsed.
There was a problem hiding this comment.
Maybe in the real world, but not in spec-world. In general, the spec can't even ask whether some code is strict until after it's been parsed. And anyhow, parsing is well in the past by the time this operation is called. A function's [[Strict]] value is only used to affect the creation of an "arguments" object, and how 'this' gets bound. (I think.)
(Moreover, #1563 eliminates the _Strict_ parameter, so its position in the parameter list may be a moot point.)
7cd5329 to
1dc95e2
Compare
|
(force-pushed to resolve merge conflicts) |
1dc95e2 to
b284baf
Compare
|
(force-pushed to resolve merge conflicts again) |
b284baf to
c28a7bb
Compare
|
(force-pushed to resolve merge conflicts /3) |
c28a7bb to
a8cac86
Compare
|
(force-pushed to resolve merge conflicts /4) |
spec.html
Outdated
| 1. Let _realmF_ be the current Realm Record. | ||
| 1. Let _scope_ be _realmF_.[[GlobalEnv]]. | ||
| 1. Perform FunctionInitialize(_F_, ~Normal~, _parameters_, _body_, _scope_). | ||
| 1. Let _F_ be ! OrdinaryFunctionCreate(_proto_, _parameters_, _body_, _kind_, ~Normal~, _scope_). |
There was a problem hiding this comment.
Nice cleanup here for _scope_.
spec.html
Outdated
| <h1>FunctionAllocate ( _functionPrototype_, _functionKind_ )</h1> | ||
| <p>The abstract operation FunctionAllocate requires the two arguments _functionPrototype_ and _functionKind_. FunctionAllocate performs the following steps:</p> | ||
| <emu-clause id="sec-ordinaryfunctioncreate" aoid="OrdinaryFunctionCreate" oldids="sec-functionallocate,sec-functioninitialize"> | ||
| <h1>OrdinaryFunctionCreate ( _functionPrototype_, _ParameterList_, _Body_, _functionKind_, _kind_, _Scope_ )</h1> |
There was a problem hiding this comment.
It's unfortunate there's both a _kind_ and a _functionKind_. AFAICT the ~Method~ case of _kind_ doesn't do anything, and _kind_ is only used to determine the this scope lookup mode. I would prefer to pass that directly, i.e. a new _thisMode_ that's ~LexicalThis~ or ~NonLexicalThis~ and have the non-lexical case checked for strictness inside this AO.
@jmdyck WDYT?
There was a problem hiding this comment.
Ah, currently _kind_ is still used to determine the allocation kind for non-constructibles. It's all rather circuitous logic in there. Do you plan to layer this on top of #1546, after which my suggestion above makes more sense?
There was a problem hiding this comment.
I would prefer to pass that directly, i.e. a new
_thisMode_that's~LexicalThis~or~NonLexicalThis~
Done! (modulo naming)
and have the non-lexical case checked for strictness inside this AO.
I wasn't sure what you meant by this.
The only effect of OrdinaryFunctionCreate's _kind_ parameter is on the [[ThisMode]] of the new function. And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~), the only thing that matters is whether or not it's ~Arrow~. So replace it with parameter _thisMode_ that has two possible values: ~lexical-this~ and ~nonlexical-this~. Suggested by @syg in: tc39#1562 (comment)
a8cac86 to
b30238b
Compare
|
Force-pushed to resolve merge conflicts, and also to add 2 commits. |
The only effect of OrdinaryFunctionCreate's _kind_ parameter is on the [[ThisMode]] of the new function. And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~), the only thing that matters is whether or not it's ~Arrow~. So replace it with parameter _thisMode_ that has two possible values: ~lexical-this~ and ~non-lexical-this~. Suggested by @syg in: tc39#1562 (comment)
b30238b to
324cc1c
Compare
michaelficarra
left a comment
There was a problem hiding this comment.
LGTM. This will probably have lots of variable renaming conflicts with #1477.
FunctionAllocate() always returns a function object whose [[Realm]] is the current Realm Record.
FunctionAllocate and FunctionInitialize are always invoked in tandem. Moreover, the division between them seems somewhat arbitrary. So, merge the two operations into one, called OrdinaryFunctionCreate.
(This seems like a sensible order to me, at least.)
... specifically: - FunctionCreate - GeneratorFunctionCreate - AsyncGeneratorFunctionCreate - AsyncFunctionCreate After the refactorings of PR tc39#1546 and the prior commits in this PR, these have slimmed down to very thin wrappers around OrdinaryFunctionCreate. The only thing they hide is the choice of prototype; all their parameters are simply passed through. I don't think they provide a useful abstraction layer any more. In fact, I think they're kind of an obstacle. Any change in the interface of OrdinaryFunctionCreate would require a corresponding change to each of these operations, an unnecessary complication and possible inhibitor. Downstream specs: - ES Intl doesn't use any of these operations. - WebIDL doesn't use any of these operations. - HTML has one call to FunctionCreate.
) The only effect of OrdinaryFunctionCreate's _kind_ parameter is on the [[ThisMode]] of the new function. And although _kind_ has three possible values (~Normal~, ~Method~, ~Arrow~), the only thing that matters is whether or not it's ~Arrow~. So replace it with parameter _thisMode_ that has two possible values: ~lexical-this~ and ~non-lexical-this~. Suggested in: tc39#1562 (comment)
324cc1c to
3899f59
Compare
|
Yay! Thanks for the merge. |
In the ECMAScript spec, the recently merged [PR whatwg#1562](tc39/ecma262#1562) replaced the `FunctionCreate` operation (and some others) with the new operation `OrdinaryFunctionCreate`. This commit makes the necessary changes to HTML's only call to `FunctionCreate`.
FunctionAllocate and FunctionInitialize are always invoked in tandem. Moreover, the division between them seems somewhat arbitrary. So, merge the two operations into one, called OrdinaryFunctionCreate.
(Yeah, it's got 7 parameters, but I'm pretty sure we can eliminate one of them in a future refactoring.)
The second commit is the main one; the others are prep and cleanup.
(Web IDL and HTML do not reference FunctionAllocate or FunctionInitialize.)