implement is top-level flag for worker scripts
Categories
(Core :: DOM: Workers, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox106 | --- | fixed |
People
(Reporter: yulia, Assigned: yulia)
References
Details
Attachments
(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 https://html.spec.whatwg.org/multipage/workers.html#worker-processing-model
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.
Assignee | ||
Comment 1•2 years ago
|
||
After investigating this a bit, I found that this wasn't used. It seems safe to remove.
Depends on D154385
Updated•2 years ago
|
Assignee | ||
Comment 2•2 years ago
|
||
GetBaseURI
will implement the virtual method GetBaseURI
from ScriptLoaderInterface
(https://searchfox.org/mozilla-central/rev/6ec440e105c2b75d5cae9d34f957a2f85a106d54/js/loader/ModuleLoaderBase.h#64)
-- 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
Assignee | ||
Comment 3•2 years ago
|
||
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.
Assignee | ||
Comment 4•2 years ago
|
||
Depends on D147319
Comment 6•2 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/4a04d2b6a13a
https://hg.mozilla.org/mozilla-central/rev/9563cc483b5b
https://hg.mozilla.org/mozilla-central/rev/e46aad19c241
https://hg.mozilla.org/mozilla-central/rev/493caeca88c6
Description
•