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: Create the realm execution context slightly later #3497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmdyck
Copy link
Collaborator

@jmdyck jmdyck commented Nov 21, 2024

InitializeHostDefinedRealm (IHDR), in addition to creating a realm, also creates an execution context (EC) to house it, and pushes that EC onto the EC stack. In the status quo, the EC-related steps appear in the midst of the realm-creation steps, which is odd, and doesn't appear to be necessary. (You might think that the later realm-creation steps somehow assume that the realm EC exists and has been pushed on the EC stack, but as far as I can tell, they don't. I think it's just an artifact of how IHDR was introduced in ES6.)

This PR moves the EC-related steps to a point after the realm's fields have been finalized.

(This makes it easier to see that the early settings of [[GlobalObject]] and [[GlobalEnv]] to *undefined* are superfluous. I would have deleted those steps, but that overlaps with PR #3445.)


I would have preferred to move the EC-related steps to just before the Return step. However, that would be a change in behavior. The invocation of SetDefaultGlobalBindings can return an abrupt completion, which is immediately returned by IHDR. In such a case, the status quo says that the EC-related things have happened, which is a side-effect that can be observed by IHDR's caller. In particular, when the HTML spec invokes IHDR, it ignores the return value; it fetches the realm EC from the EC stack regardless of whether IHDR returned an abrupt completion.

(Mind you, I think the only way that SetDefaultGlobalBindings could throw is if IHDR's caller provided a global object that was specifically designed to make that happen.)


I suggested this change in #3445 (comment)

This should probably have been a quick follow-up to PR #3139.

See also PR #3274, which considers changing some of the linkage between IHDR and its caller.

That is, in InitializeHostDefinedRealm,
take the steps that create + push the realm execution context,
and move them to after the realm's fields have been finalized.
Comment on lines 11807 to 11808
1. Perform ? SetDefaultGlobalBindings(_realm_).
1. Create any host-defined global object properties on _global_.
Copy link
Member

Choose a reason for hiding this comment

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

Is the only reason we can't also move these lines up because SetDefaultGlobalBindings might throw? If so, should we (normatively) reconsider whether those property definitions should be permitted to throw?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the only reason we can't also move these lines up because SetDefaultGlobalBindings might throw?

Well, the only other possible reason would be that those remaining steps need the realm EC to exist (and maybe that it be on the EC stack). That isn't the case if the global object is ordinary, but if it's a host-defined exotic object, then I suppose its relevant internal methods could be specified to access the realm EC.

Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

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

Definitely an improvement.

Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

Hmm, this causes trouble for me. I need to get my hands on the realm in the "created in a host-defined manner", and the current realm is the most well-defined way to do that. (See also #3274)

@jmdyck
Copy link
Collaborator Author

jmdyck commented Nov 26, 2024

Ah, in the sense of "the current Realm Record" = "the Realm component of the running execution context".

But if we first changed IHDR as described in #3274 (comment), that would give you a more direct way to access the realm being created, and then this PR wouldn't be a problem?

@Ms2ger
Copy link
Contributor

Ms2ger commented Nov 26, 2024

Yes, that would be fine. I just need a reasonable way to get the (new) realm.

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

Successfully merging this pull request may close these issues.

3 participants