Closed Bug 1784457 Opened 1 year ago Closed 1 year ago

implement is top-level flag for worker scripts


(Core :: DOM: Workers, task)




106 Branch
Tracking Status
firefox106 --- fixed


(Reporter: yulia, Assigned: yulia)




(4 files)

TL;DR -- it makes more sense to put the is top-level bit on the WorkerLoadContext than on the loader itself.

When we are running a worker, we currently distinguish between a main worker script (the one that the worker is loaded with) and subsequent scripts loaded via importScripts or similar. Part of this gated work is implementing step 14 of

However, when modules land, storing the "is top-level" flag duplicates information already present on the ScriptLoadRequest. The loading strategy used by importScripts uses a blocking sync loop which allows the imported script to load, and run, synchronously.

Modules on the other hand are asynchronous, and their order of resolution is not significant. If we use a blocking sync loop, then we would only use it for the load and link portion, while potentially blocking other work as we go deeper into one branch of the module graph. For execution, everything will be executed on the root sync loop anyway, because module initialization and execution is only triggered by the main module running, after everything has already been loaded.

Dynamic modules present yet another execution model, which lies between these two models. Dynamic modules run when the code is reached by execution, they register a promise which will resolve separately, async, but inline. However, the internal modules that make up the dynamic import will follow the same rules as a regular module. However it does set custom properties such as csp that are independent of their parent.

After investigating this a bit, I found that this wasn't used. It seems safe to remove.

Depends on D154385

Assignee: nobody → ystartsev

GetBaseURI will implement the virtual method GetBaseURI from ScriptLoaderInterface
-- but the behavior needed there is only ever for child modules. By splitting this, we remove
contextual information which is only used for the initial script.

Depends on D154519

This implements the core of the change -- which is implementing an explicit IsTopLevel flag for
WorkerLoadContexts, and removing mIsMainScript from the loader. I've asked for some
clarification on this part of the spec from the whatwg editors, as I think this may be misnamed. It
is likely that what is meant here is IsInitialScript rather than IsTopLevel -- as there is a
note stating that this should be initialized with the agent cluster. Once this is clarified I may
update the name.

Depends on: 1783190
Pushed by
Remove unused mLoadingWorkerScript atomic boolean from WorkerPrivate; r=asuth
Split GetBaseURI into two functions; r=asuth
Implement IsTopLevel in place of IsMainWorkerModule; r=asuth
Add documentation to worker kinds; r=asuth
You need to log in before you can comment on or make changes to this bug.