Skip to content
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: GlobalObject cannot be undefined in the GetGlobalObject #3445

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kimjg1119
Copy link
Contributor

The [[GlobalObject]] of the Realm record is an Object or undefined. However, it seems that in GetGlobalObject, the slot cannot be undefined. To make this clear(and resolve some ESMeta alarms), I suggest adding an assertion.

@kimjg1119 kimjg1119 changed the title Add assertion for GetGlobalObject must not be undefined Editorial: GlobalObject cannot be undefined in the GetGlobalObject Oct 9, 2024
@michaelficarra michaelficarra added the editor call to be discussed in the next editor call label Nov 20, 2024
@bakkot
Copy link
Contributor

bakkot commented Nov 20, 2024

Thanks for the contribution. However, in practice, this is never actually *undefined* except between steps 4 and 16 of InitializeHostDefinedRealm, which is the thing which initializes Realm Records. So it would be better to instead remove *undefined* from the type and remove the Set realm.[[GlobalObject]] to undefined. step from InitializeHostDefinedRealm.

@michaelficarra michaelficarra removed the editor call to be discussed in the next editor call label Nov 20, 2024
@jmdyck
Copy link
Collaborator

jmdyck commented Nov 21, 2024

... remove the Set realm.[[GlobalObject]] to undefined. step from InitializeHostDefinedRealm.

So then the running execution context's Realm would be missing a [[GlobalObject]] field between steps 11 and 16. Which is okay because steps 12-15 don't care about the running execution context? (If that's the case, I think I'll submit a PR to move the execution context stuff to the end of InitializeHostDefinedRealm, after the realm has finished initializing.)

@kimjg1119
Copy link
Contributor Author

So then the running execution context's Realm would be missing a [[GlobalObject]] field between steps 11 and 16. Which is okay because steps 12-15 don't care about the running execution context? (If that's the case, I think I'll submit a PR to move the execution context stuff to the end of InitializeHostDefinedRealm, after the realm has finished initializing.)

Sorry, but I’m a bit confused about this. Does this mean that the type of [[GlobalObject]] is not undefined in step 12-15? I’m aware of issue #3482, and I’m unable to determine the type of this field after the proposed solution is applied.

@bakkot
Copy link
Contributor

bakkot commented Nov 21, 2024

@kimjg1119 Whenever we are initializing fields or slots imperatively the type of a field is not necessarily realized until the step which initializes it. Compare, for example, NewGlobalEnvironment: what is the type of _env_.[[VarNames]] at step 5 of that algorithm? The answer is that it doesn't really have one; it hasn't been initialized yet. But nothing refers to it so that doesn't matter.

@kimjg1119
Copy link
Contributor Author

kimjg1119 commented Nov 21, 2024

@kimjg1119 Whenever we are initializing fields or slots imperatively the type of a field is not necessarily realized until the step which initializes it. Compare, for example, NewGlobalEnvironment: what is the type of _env_.[[VarNames]] at step 5 of that algorithm? The answer is that it doesn't really have one; it hasn't been initialized yet. But nothing refers to it so that doesn't matter.

Thanks! I agree that simply removing the initialization step with undefined should be sufficient to resolve the ESMeta alarm, so I’m completely on board with it.

NOTE: We will temporarily put this in esmeta-ignore.json until v0.5.1 since we handle the type system manually; thus ESMeta does not know undefined has been removed.

@@ -12054,6 +12053,7 @@ <h1>GetGlobalObject ( ): an Object</h1>
</dl>
<emu-alg>
1. Let _currentRealm_ be the current Realm Record.
1. Assert: _currentRealm_.[[GlobalObject]] is not *undefined*.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is no longer necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants