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

Normative: Propagate active ScriptOrModule with JobCallback Record #3195

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

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Oct 13, 2023

HTML HostEnqueuePromiseJob doesn't follow the requirements of ecma262 HostEnqueuePromiseJob as ecma262 defines that

However, HTML spec defines that the active ScriptOrModule is saved at the time of HostMakeJobCallback is invoked rather than at the time of HostEnqueuePromiseJob is invoked. The two host hooks are invoked with the same active script or module consecutively.

Update the steps of HostMakeJobCallback, HostCallJobCallback, and HostEnqueuePromiseJob to fix the inconsistency between ecma262 and the HTML spec.

This change also mandates that the active scripts are propagated through promise jobs and FinalizationRegistry cleanup callbacks. For example, the following example uses the original script's incumbent document URL appropriately.

const setLocationHref = Object
  .getOwnPropertyDescriptor(frames[0].location, "href")
  .set
  .bind(frames[0].location);

Promise.resolve("./page-1").then(setLocationHref);

This proposed behavior exists in the HTML spec since HTML HostMakeJobCallback already propagates the active script. This PR fixes the inconsistent requirement on ecma262 HostEnqueuePromiseJob and HTML HostMakeJobCallback.

@legendecas legendecas changed the title Nomative: Propagate active ScriptOrModule with JobRecord Nomative: Propagate active ScriptOrModule with JobCallback Record Oct 13, 2023
@nicolo-ribaudo
Copy link
Member

This should be discussed together with #3160 — we should move towards less dynamic scoping, not more.

@ljharb ljharb changed the title Nomative: Propagate active ScriptOrModule with JobCallback Record Normative: Propagate active ScriptOrModule with JobCallback Record Oct 13, 2023
@legendecas
Copy link
Member Author

Updated the example moving away from indirect eval. HTML propagates incumbent settings with HostMakeJobCallback and this should be aligned with ecma262 notes.

1. Set the ScriptOrModule of _jobContext_ to _scriptOrModule_.
1. Perform any necessary implementation-defined initialization of _jobContext_.
1. Let _result_ be Completion(Call(_jobCallback_.[[Callback]], _V_, _argumentsList_)).
1. Remove _jobContext_ from the execution context stack and restore _callerContext_ as the running execution context.
Copy link
Member

Choose a reason for hiding this comment

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

In #2962, we change this phrasing. Depending on the order these land, the latter PR will need to account for the former.

@michaelficarra
Copy link
Member

Otherwise LGTM editorially.

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.

3 participants