Skip to content

script: fix worklet implementation to fetch modules instead of classic scripts - #46856

Merged
mukilan merged 15 commits into
servo:mainfrom
niyabits:script/implement-task-manager-on-worklet-global-scope
Aug 5, 2026
Merged

mukilan merged 15 commits into
servo:mainfrom
niyabits:script/implement-task-manager-on-worklet-global-scope

Conversation

@niyabits

Copy link
Copy Markdown
Contributor

Fix the existing Worklet implementation by adding the necessary infrastructure for fetching modules (e.g., implementing task manager on Worklet) and using our implementation of fetch a worklet/module worker script graph instead of fetching classic scripts using load_whole_resource.

Testing: Tests in tests/wpt/mozilla/tests/mozilla/worklets already cover the changes, some fixes were made to comply with the specs.

Fixes: #45306

@niyabits
niyabits requested a review from gterzian as a code owner July 29, 2026 07:48
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 29, 2026
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch from e8d9ba6 to 6b53081 Compare July 29, 2026 07:52
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread tests/wpt/mozilla/tests/mozilla/worklets/test-worklet.html Outdated
Comment thread components/script/dom/worklet/paintworkletglobalscope.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/workletglobalscope.rs Outdated
Comment thread components/script/messaging.rs Outdated
Comment thread components/script/messaging.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated

@mukilan mukilan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are some lint failures because of spec link formats being different. You can follow the suggestion in the lint and replace it with the one in the message.
Also there are some long spec comments in the code that need to be reformatted to span multiple lines.

Comment thread components/script/dom/worklet/worklet.rs
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread tests/wpt/mozilla/tests/mozilla/worklets/test-worklet.html Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs
Comment thread components/script/dom/worklet/worklet.rs Outdated
Comment thread components/script/dom/worklet/workletglobalscope.rs
Comment thread components/script/messaging.rs Outdated
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch 10 times, most recently from 9448a32 to ffe3180 Compare August 2, 2026 06:33
// global object to perform the following steps:
// 6.4.5.1 If pendingTasks is not −1:
// 6.4.5.1.1 Set pendingTasks to pendingTasks − 1.
// 6.4.5.1.2 If pendingTasks is 0, then resolve promise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why spec in test ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's part of this note above:

// NOTE: The specification for AddModule does not use the promise returned by "run a module script",
// therefore an exception thrown when executing a module will not be propagated.
// <https://html.spec.whatwg.org/multipage/#dom-worklet-addmodule

It feels unintuitive that addModule will resolve the promise even when there is a syntax error while loading a module.

I think I initially added the steps to serve as extra context to explain the behavior the specification expects. Although looking back at it, I think maybe mentioning the step number in the NOTE comment maybe sufficient.

Relevant issue: w3c/css-houdini-drafts#407

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Taym95 I think the issue I referenced above was closed accidentally and the specification might change in the future. So it might be good to know what the spec said to justify the test in the future.

Are you okay with the steps?

@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch from ffe3180 to 91e5363 Compare August 3, 2026 14:29
@niyabits
niyabits requested a review from Taym95 August 3, 2026 14:30
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch from 91e5363 to e05bc6c Compare August 4, 2026 11:45
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
…k_manager

Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
Signed-off-by: Niya <niyabits@disroot.org>
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch from e05bc6c to eeba2ee Compare August 5, 2026 06:22
// Step 6. Run the following steps in parallel:
// Step 6.1. If workletInstance's global scopes is empty:
// Step 6.1.1. Create a worklet global scope given workletInstance.
let global_scope = self.window.as_global_scope();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The steps are still attached to this line, which makes them seem like they are related. You probably separate them by blank line and also add a note after the steps that they are implemented in those other functions. The comment block should probably include steps 6.1.2 and 6.1.3 below.

Comment thread components/script/dom/worklet/workletglobalscope.rs Outdated
Comment thread components/script/dom/worklet/worklet.rs Outdated
Signed-off-by: Niya <niyabits@disroot.org>
@niyabits

niyabits commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

I have moved the steps Step 6.1.2. and Step 6.1.3. above here,

        let global_scope = self.window.as_global_scope();

As I don't think there is a good reason to keep the steps after that line.

I have added a note for the steps as well:

        // Step 5. Let workletInstance be this.

        // Step 6. Run the following steps in parallel:
        // Step 6.1. If workletInstance's global scopes is empty:
        // Step 6.1.1. Create a worklet global scope given workletInstance.
        // Step 6.1.2. Optionally, create additional global scope instances given workletInstance, depending on the specific worklet in question and its specification.
        // Step 6.1.3. Wait for all steps of the creation process(es) — including those taking place within the worklet agents — to complete, before moving on.
        // NOTE: Step 6 is implemented by WorkletThread's run method.
        // Step 6.1, Step 6.1.1, and Step 6.1.3 are implemented in the `get_worklet_global_scope` method.

        let global_scope = self.window.as_global_scope();

I believe I do not need a longer explanation for the steps.

edit: I have removed space between each individual step.

@niyabits
niyabits requested a review from mukilan August 5, 2026 08:02
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch 2 times, most recently from 9625f66 to 25c4583 Compare August 5, 2026 09:58
@niyabits
niyabits force-pushed the script/implement-task-manager-on-worklet-global-scope branch from 25c4583 to 1ee5753 Compare August 5, 2026 10:08
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Aug 5, 2026
@mukilan
mukilan added this pull request to the merge queue Aug 5, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 5, 2026
Merged via the queue into servo:main with commit 086a3d6 Aug 5, 2026
33 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 5, 2026
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
…c scripts (servo#46856)

Fix the existing Worklet implementation by adding the necessary
infrastructure for fetching modules (e.g., implementing task manager on
Worklet) and using our implementation of `fetch a worklet/module worker
script graph` instead of fetching classic scripts using
`load_whole_resource`.

Testing: Tests in `tests/wpt/mozilla/tests/mozilla/worklets` already
cover the changes, some fixes were made to comply with the specs.

Fixes: servo#45306

---------

Signed-off-by: Niya <niyabits@disroot.org>
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.

script: Worklet.addModule should fetch and execute JS Modules instead of classic scripts.

6 participants