-
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: Fix null [[ScriptOrModule]] of function declarations in modules #1670
Conversation
@ljharb suggested adding a [[Module]] slot to module environments and using that in FunctionInitialize. I'm fine with either approach. |
Why don't we fix this instead, i.e. make modules and scripts symmetrical? |
My understanding is that for exported declarations, the module isn’t evaluating, so it doesn’t belong on the stack - iow, they can’t be symmetrical because they have a linking phase that scripts lack. |
You could still put it on the stack, even if you're not evaluating anything, in order to get the correct results from various algorithms in the spec. |
@domenic the module's context doesn't exist until evaluation |
I see. It still seems better to me to move that to linking time. I.e. create the context, and push it onto the stack during linking. (Then pop it off.) Then evaluation can just push/pop the already-created context. In particular, I find this PR bad because it indicates that there are a lot of mechanisms in the spec that expect a context to be on the stack while setting up functions. We found out that that is not always true, but I'd rather preserve that invariant and restore the assumption, instead of compensating for it. |
Yes, and the parts of InitializeEnvironment that correspond to "linking" should not have evaluation-time dependencies because we don't want to preclude doing them with an ahead-of-time linker. To me, it would seem better to add an scriptOrModule parameter to InstantiateFunctionObject so module InitializeEnvironment can explicitly pass it when instantiating module top-level functions. |
8eba4e1
to
ea4cbc2
Compare
This comment has been minimized.
This comment has been minimized.
d7891db
to
3cf3dc8
Compare
3cf3dc8
to
05927a9
Compare
this changeset has been verified with engine262 👍 |
b266fd5
to
36c17fc
Compare
36c17fc
to
45b9007
Compare
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.
Looks okay to me.
45b9007
to
83621de
Compare
There is no context on the stack that contains the current module while modules are setting up their environments, unlike scripts which push their context right before GlobalDeclarationInstantiation. This results in function declarations in modules having null [[ScriptOrModule]] slots. This breaks import.meta and dynamic import inside modules.