Commit graph

130 commits

Author SHA1 Message Date
Jens Stutte
21001eee69 Bug 1823391 - Have a static WorkerScriptLoader::Create and try to shutdown when the workerRef is notified. r=yulia,edenchuang,asuth
This patch does:
- use our common `Create` pattern also here to move some complexity out of the constructor and improve the error handling.
- give each strong worker ref a unique name for better diagnostics.
- add a `TryShutdown` to the life-cycle worker ref, presumably this may help if the worker dies before any DispatchLoadScript(s) has been called.

Differential Revision: https://phabricator.services.mozilla.com/D192936
2023-11-15 07:00:02 +00:00
Yoshi Cheng-Hao Huang
ae3bdd69fe Bug 1824498 - Call shutdown when there isn't any ongoing fetching modules. r=jonco
In the test file, worker_bug1824498.mjs, it imports two module scripts,
"foo" and "bar", both are invalid specifiers.

The ModuleLoadRequest of "foo" will be canceled, which in turn will:
1. Cancel all imports of the parent ModuleLoadRequest (worker_bug1824498.mjs)
2. Cancel the ModuleLoadRequest of "bar".

After the step 1, WorkerModuleLoader::OnModuleLoadComplete will be
called, and will shutdown the script loader.

The shutdown causes two problems:
1. When step 2 is executed, it will reject the mReady promise in
ModuleLoadRequest, however when the MozPromise is dispatched, its event
target has been shutdown so an assertion failure is triggered.

2. Also when the ScriptLoaderRunnable of "bar" is received, it also
triggers the assertion failure of the valid SyncLoopEventTarget.

To fix the problem, we delay the shutdown until there's no ongoing module
requests.

Differential Revision: https://phabricator.services.mozilla.com/D175476
2023-04-20 17:41:47 +00:00
Yulia Startsev
b8d4d67ca2 Bug 1540913 - Part 6: Implement Dynamic import for workers; r=jonco
This is the final change for dynamic imports, and makes the necessary modifications to properly load
them.

Differential Revision: https://phabricator.services.mozilla.com/D169629
2023-03-14 18:16:32 +00:00
Yulia
0350774d47 Bug 1540913 - Part 4: Introduce WorkerScriptLoader configuration for dynamic import; r=jonco
Earlier, we introduced GetBaseURI to the module loader. This allows us to get the BaseURI for a
dynamic import even after the importing script/module's ScriptLoader has been cleaned up. However,
we now need to be able to handle the case where we need to run the dynamic import and load it. In
order to do this, we need to create a scriptloader configured for dynamic import. The most important
difference between this scriptloader and the one that is normally used for script loading in workers
is that we *do not have a syncLoopTarget* to which we return. There are a couple of reasons for
this:

* Dynamic import (and modules in general) relies on the event loop to resolve. If we create a
syncLoop here, we will end up pausing execution, and this breaks the StartModuleLoad algorithm. We
will never complete and the result will be that we are in the wrong state when we return here.
* We do not have perfect knowledge of the future, so we cannot keep the existing script loader alive
in the case that it might be used for loading in the future.
* We cannot migrate the ModuleLoader to not use sync loading without significantly changing other
aspects of how loading scripts on workers works. This becomes particularily evident with error
handling
(https://searchfox.org/mozilla-central/rev/00ea1649b59d5f427979e2d6ba42be96f62d6e82/dom/workers/WorkerPrivate.cpp#383-444),
and in addition, for reasons I wasn't able to discern, using the CurrentEventTarget results in hard
to identify errors. When there is time to investigate this fully, the ModuleLoader may move away
from using a syncLoop itself.

For now, all main-script loads (whether they are modules or classic scripts) will use the sync loop,
and all dynamic imports will create a new script loader for their needs that is not using the sync
loop. The book keeping for this is in the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D171685
2023-03-14 18:16:31 +00:00
Yulia Startsev
e6d68fc585 Bug 1805676 - Implement modules for shared workers; r=asuth
This patch introduces modules workers to shared workers. This includes the necessary chagnes to pass
the "type: module" to the shared worker. Beyond that, this patch relies on the work landed in
dedicated workers.

Depends on D162743

Differential Revision: https://phabricator.services.mozilla.com/D156103
2023-02-14 09:04:59 +00:00
Marian-Vasile Laza
2b10b4cf84 Backed out 4 changesets (bug 1805676) for wpt failures on shared-worker-import-csp.html. CLOSED TREE
Backed out changeset 95d1e02df42c (bug 1805676)
Backed out changeset 79f32abb379d (bug 1805676)
Backed out changeset 2d35363f5937 (bug 1805676)
Backed out changeset b173c8e2beba (bug 1805676)
2023-02-13 21:14:00 +02:00
Yulia Startsev
a3e98a92c7 Bug 1805676 - Implement modules for shared workers; r=asuth
This patch introduces modules workers to shared workers. This includes the necessary chagnes to pass
the "type: module" to the shared worker. Beyond that, this patch relies on the work landed in
dedicated workers.

Depends on D162743

Differential Revision: https://phabricator.services.mozilla.com/D156103
2023-02-13 16:09:46 +00:00
Stanca Serban
35c5dff6e9 Backed out 4 changesets (bug 1805676) for causing wpt failures in /workers/modules/shared-worker-import-csp.html. CLOSED TREE
Backed out changeset 3d943ee00682 (bug 1805676)
Backed out changeset 34da8cbd7db2 (bug 1805676)
Backed out changeset 1573d31341db (bug 1805676)
Backed out changeset 212f36c3a9e0 (bug 1805676)
2023-02-13 10:41:28 +02:00
Yulia Startsev
fad5626a3b Bug 1805676 - Implement modules for shared workers; r=asuth
This patch introduces modules workers to shared workers. This includes the necessary chagnes to pass
the "type: module" to the shared worker. Beyond that, this patch relies on the work landed in
dedicated workers.

Depends on D162743

Differential Revision: https://phabricator.services.mozilla.com/D156103
2023-02-13 07:35:59 +00:00
Yulia Startsev
1c5ad3e91d Bug 1247687 - Implement csp for Module Workers; r=evilpie,asuth,rpl,ckerschb
Depends on D155691

Differential Revision: https://phabricator.services.mozilla.com/D156102
2023-01-18 13:46:33 +00:00
Yulia Startsev
51e7e0e857 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2023-01-18 13:46:30 +00:00
Yulia Startsev
24d2db5bf6 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2023-01-18 13:46:30 +00:00
Yulia Startsev
56c6f79308 Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2023-01-18 13:46:29 +00:00
Norisz Fay
8cf029b070 Backed out 15 changesets (bug 1247687) as requested by dev CLOSED TREE
Backed out changeset 81d052cabf84 (bug 1247687)
Backed out changeset d698041e5174 (bug 1247687)
Backed out changeset 2adf67f910e8 (bug 1247687)
Backed out changeset 0bc871906e97 (bug 1247687)
Backed out changeset 1700d5b79273 (bug 1247687)
Backed out changeset 31888ffde37a (bug 1247687)
Backed out changeset 9153182c650d (bug 1247687)
Backed out changeset 45de9ffeec19 (bug 1247687)
Backed out changeset 59207e959b7c (bug 1247687)
Backed out changeset 49f18430c465 (bug 1247687)
Backed out changeset 0ae1fd421d4f (bug 1247687)
Backed out changeset 7770ec4717fd (bug 1247687)
Backed out changeset 68b476066248 (bug 1247687)
Backed out changeset c94a9dc60dff (bug 1247687)
Backed out changeset 0ab366c6eaaf (bug 1247687)
2022-12-21 10:48:15 +02:00
Yulia Startsev
dcbacd54c8 Bug 1247687 - Implement csp for Module Workers; r=evilpie,asuth,rpl,ckerschb
Depends on D155691

Differential Revision: https://phabricator.services.mozilla.com/D156102
2022-12-20 20:56:15 +00:00
Yulia Startsev
83dd3f6844 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2022-12-20 20:56:13 +00:00
Yulia Startsev
85669b74b0 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2022-12-20 20:56:12 +00:00
Yulia Startsev
e859be10b8 Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2022-12-20 20:56:12 +00:00
Csoregi Natalia
c382c6a7ca Backed out 16 changesets (bug 1247687) for frequent string bundle related crashes with PDF viewer (bug 1806064). a=backout
Backed out changeset 721f612fd09f (bug 1247687)
Backed out changeset c6c5750cf713 (bug 1247687)
Backed out changeset 5d05ab0c7cde (bug 1247687)
Backed out changeset 2429599729cb (bug 1247687)
Backed out changeset 55f13fb4ee3f (bug 1247687)
Backed out changeset 354711cf113a (bug 1247687)
Backed out changeset 40b8abaf1c0b (bug 1247687)
Backed out changeset 0c9650a1ac48 (bug 1247687)
Backed out changeset e7b103c79b1a (bug 1247687)
Backed out changeset 4dbd510fb042 (bug 1247687)
Backed out changeset 9276c7e1ddd9 (bug 1247687)
Backed out changeset 6ee318df6641 (bug 1247687)
Backed out changeset 6c129bd72b61 (bug 1247687)
Backed out changeset 4b0a4fcc6894 (bug 1247687)
Backed out changeset 34680059b9f0 (bug 1247687)
Backed out changeset 85b827971a48 (bug 1247687)
2022-12-17 11:27:32 +02:00
Yulia Startsev
4916e53611 Bug 1247687 - Implement csp for Module Workers; r=evilpie,asuth,rpl,ckerschb
Depends on D155691

Differential Revision: https://phabricator.services.mozilla.com/D156102
2022-12-14 14:55:38 +00:00
Yulia Startsev
3d4f58ac76 Bug 1247687 - Implement initial Static Module Loading for Workers; r=jonco
This is the first pass of getting static module loading to work. This roughly implements
https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-worklet/module-worker-script-graph --
without some of the settings objects correctly set.

Th WorkerModuleLoader itself is implementing step 5, with the StartFetch method handling moving the work back to the main thread. The algorithm in step 5 is generic to all modules.

Depends on D147329

Differential Revision: https://phabricator.services.mozilla.com/D147327
2022-12-14 14:55:35 +00:00
Yulia Startsev
33b96ee278 Bug 1247687 - Disallow ImportScripts from module workers; r=jonco
ImportScripts should be disallowed for module works, which are initialized in the following way:
`new Worker("url", { module:true})`. We set the WorkerType for workers accordingly, and can use that
to detect if import scripts are being incorrectly used.

Depends on D147326

Differential Revision: https://phabricator.services.mozilla.com/D147329
2022-12-14 14:55:35 +00:00
Yulia Startsev
a40b702d6e Bug 1247687 - Implement InitModuleLoader methods for WorkerScriptLoader and WorkerGlobalScope; r=jonco
This implements a method to initialize the moduleLoader for workers. This will initialize only once, for all worker types (module and classic).

Depends on D147324

Differential Revision: https://phabricator.services.mozilla.com/D147326
2022-12-14 14:55:35 +00:00
Yulia Startsev
2a09430d95 Bug 1800496 - Revert mCacheCreator to being defined as part of ScriptLoaderRunnable; r=asuth
Previously, in the cancellation refactor, we removed knowledge of the list of scripts being loaded on the main thread. As a result of this, we could no longer clear the cache creator on the main thread after iterating over all requests. We can now do that once again, and it simplifies the code.

Differential Revision: https://phabricator.services.mozilla.com/D162220
2022-11-18 10:02:28 +00:00
Yulia Startsev
ddd2163a1b Bug 1800496 - Re-implement DispatchProcessPendingRequests; r=asuth
This brings back the "group" dispatch that existed before in https://searchfox.org/mozilla-central/rev/e0a7a014f3384ac1abc229d9961f244e3e70a52c/dom/workers/ScriptLoader.cpp#1027-1085

In my view, this is probably an optimization, but it may result in significant behavioral changes as timing has been a major issue with the cancellation refactor. What this does is, if two requests resolve in an order other than post order, then the requests will wait untill all of their dependencies have loaded before firing the dispatch. That means in some cases, we will have only one dispatch instead of two.

Differential Revision: https://phabricator.services.mozilla.com/D162219
2022-11-18 10:02:28 +00:00
Yulia Startsev
92dcd0556e Bug 1800496 - Re-introduce ScriptLoaderRunnable; r=asuth
The ScriptLoaderRunnable used to do double duty as both the runnable used to load a script, and as the data structure to hold on to loading information (what kind of worker, debugger status, etc, if we failed). The second half of these responsibilities remains with the WorkerScriptLoader. WorkerScriptLoader acts as a persistent data structure. ScriptLoaderRunnable is per batch of requests (such as ImportScripts, or a single module load). It works together with the ThreadSafeRequestHandle to load the script.

In the future, when we move to a single threaded implementation, ThreadSafeRequestHandle will likely be merged with WorkerLoadContext, but ScriptLoaderRunnable will stay as a datastructure to represent the batched request, and most of the existing fields (mSyncTarget, the request list) will stay. There is still some massaging to do here, but it gets closer to a final vision of how this should look.

Differential Revision: https://phabricator.services.mozilla.com/D162217
2022-11-18 10:02:27 +00:00
Yulia Startsev
a5b34cfc55 Bug 1800496 - Initial cancellation revert; r=asuth
This returns most of the behavior from https://searchfox.org/mozilla-central/rev/e0a7a014f3384ac1abc229d9961f244e3e70a52c/dom/workers/ScriptLoader.cpp#735-776

What is missing at this point is batch dispatching, as we once again cancel one-at-a-time rather than as a group.

Differential Revision: https://phabricator.services.mozilla.com/D162216
2022-11-18 10:02:27 +00:00
Yulia Startsev
2310f5b5b6 Bug 1800496 - Introduce ThreadSafeRequestHandle; r=asuth
This introduces a new datastructure that wraps the ScriptLoadRequest. Previously, we were using the WorkerLoadContext to access the request, and we made it not cycle collected in order to make it safe across threads. This, of course, broke module behavior, as the cycle needs to be broken in more places, and things get rather complex.

In the spirit of making everyone's life easier, the ThreadSafeRequestHandle exists as a way to move the request to the main thread, operate on it, and then return it to the worker. We no longer need to track and free the WorkerLoadContext. Once the ThreadSafeRequestHandle is returned to the worker, we release the request, and the handle is empty. There is a possibility that this will cause issues, so we should keep an eye on this. Alternatively, we can never release the ScriptLoadRequest and let the ThreadSafeRequestHandle clean it up on destruction.

In the case that we somehow end up releasing on the main thread, we will send a runnable to release the request correctly on the worker.

Differential Revision: https://phabricator.services.mozilla.com/D162213
2022-11-18 10:02:25 +00:00
Yulia Startsev
b122d68410 Bug 1800496 - Prep: Use nsISerialEventTarget for WorkerScriptLoader classes; r=dom-workers-and-storage-reviewers,asuth
We will be using the mSyncLoopTarget for module promises, and for returning to the worker thread
when cleaning up for ThreadSafeRequestHandle.

Differential Revision: https://phabricator.services.mozilla.com/D162212
2022-11-18 10:02:25 +00:00
Yulia Startsev
088ae95178 Bug 1797327 - Use RefPtrs for all WorkerLoadContexts; r=asuth
As WorkerLoadContexts now inherit from a non-CC'd loadContextBase, we have two outcomes.
1) we need to break cycles with ScriptLoadRequests manually, so that ScriptLoadRequests can be collected (ScriptLoadRequests must be CC'd).
2) we can now have refptrs to WorkerLoadContexts in the CacheLoadHandler and NetworkLoadHandler classes, and remove any remaining raw pointers to ScriptLoadRequest/WorkerLoadContext. There are cases where the NetworkLoadHandler or CacheLoadHandler might outlive the Worker Loader, so having refpointers here should help us recover in those cases.

Differential Revision: https://phabricator.services.mozilla.com/D160334
2022-11-01 18:03:34 +00:00
Yulia Startsev
a23d8dce11 Bug 1792984 - Introduce aggressive cancellation r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158558
2022-10-18 16:20:12 +00:00
Iulian Moraru
160a1a400d Backed out 3 changesets (bug 1792984) for causing multiple failures. CLOSED TREE
Backed out changeset 82816b3aa215 (bug 1792984)
Backed out changeset 4e8cea95745a (bug 1792984)
Backed out changeset 44324c5af215 (bug 1792984)
2022-10-13 16:31:35 +03:00
Yulia Startsev
84918803f0 Bug 1792984 - Introduce aggressive cancellation r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158558
2022-10-13 10:53:47 +00:00
Iulian Moraru
64f7ea66a0 Backed out 3 changesets (bug 1792984) for causing multiple failures. CLOSED TREE
Backed out changeset 67c10a19f5ce (bug 1792984)
Backed out changeset bb65c6e3135b (bug 1792984)
Backed out changeset d9ca4c5e8e61 (bug 1792984)
2022-10-13 11:16:36 +03:00
Yulia Startsev
75e1b76e92 Bug 1792984 - Introduce aggressive cancellation r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158558
2022-10-13 07:19:24 +00:00
Yulia Startsev
f593e162fd Bug 1784481 - Use ScriptLoaderInterface method for filling compile options; r=jonco
Depends on D147314

Differential Revision: https://phabricator.services.mozilla.com/D147315
2022-10-04 16:01:29 +00:00
Yulia Startsev
7bf63f5988 Bug 1784481 - Use ScriptLoaderInterface methods for reporting errors; r=jonco
Fill out the ReportErrorToConsole method, and add documentation for ReportWarningToConsole

Depends on D147313

Differential Revision: https://phabricator.services.mozilla.com/D147314
2022-10-04 16:01:29 +00:00
Yulia Startsev
0dd649a319 Bug 1784481 - Implement ScriptLoaderInterface Skeleton in WorkerScriptLoader; r=jonco
This introduces the basic skeleton to make WorkerScriptLoader a ScriptLoaderInterface.
ScriptLoaderInterface defines the methods that are shared between any given ScriptLoader (for
example the DOM script loader, the ComponentScriptLoader) and the ModuleLoader for a particular
component.

This patch also adds documentation to make the role and responsibilities of the
ScriptLoaderInterface clear.

Depends on D147321

Differential Revision: https://phabricator.services.mozilla.com/D147313
2022-10-04 16:01:28 +00:00
Jens Stutte
ecb5da0fbc Bug 1786571 - Add IsCancelled checks to NetworkLoadHandler::OnStreamComplete and have a GetCancelResult r=dom-worker-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D157307
2022-09-20 05:58:45 +00:00
Cosmin Sabou
9281cd6961 Backed out changeset 374cb9c09095 (bug 1786571) for causing several service_worker related regressions. 2022-09-16 18:27:46 +03:00
Jens Stutte
d4688e2641 Bug 1786571 - Add IsCancelled checks to NetworkLoadHandler::OnStreamComplete and have a GetCancelResult r=dom-worker-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D157307
2022-09-16 03:53:53 +00:00
Noemi Erli
0123802021 Backed out changeset b246c998fb8f (bug 1786571) for causing ScriptLoader failures CLOSED TREE 2022-09-15 14:20:23 +03:00
Jens Stutte
a5bd0870c0 Bug 1786571 - Add IsCancelled checks to NetworkLoadHandler::OnStreamComplete and have a GetCancelResult r=dom-worker-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D157307
2022-09-15 10:37:50 +00:00
Yulia Startsev
dbb424426a Bug 1783190 - Introduce lock for cancellation in case of race;r=jstutte
Differential Revision: https://phabricator.services.mozilla.com/D156943
2022-09-09 13:22:42 +00:00
Yulia Startsev
0f84338a77 Bug 1784482 - Implement method for single script loading; r=asuth
This will be used by child modules. This is currently not used, but it will be in modules. I can
move this over to the other bug, if necessary.

Depends on D147325

Differential Revision: https://phabricator.services.mozilla.com/D147321
2022-09-08 17:13:28 +00:00
Yulia Startsev
53ed8260e3 Bug 1783190 - In the case of cancellation, cleanup cache; r=asuth
This brings back the behavior to iterated over all of the load requests to cancel the cache
promise. I tried a couple of different ways of doing this, including deleting the cache, but this
seemed to be the cleanest way.

Depends on D147322

Differential Revision: https://phabricator.services.mozilla.com/D154382
2022-09-08 17:13:27 +00:00
Yulia Startsev
4a09a4f2aa Bug 1784482 - Move shutdown operation to be always after ProcessRequests; r=asuth
This moves the shutdown operations out of the ScriptExecutorRunnable, and into something that can be
called independent. This does not change the behavior in this case, however it is important for
modules, which will have promises that resolve after the ScriptExecutorRunnable has closed.

Depends on D155231

Differential Revision: https://phabricator.services.mozilla.com/D147322
2022-09-08 17:13:27 +00:00
Yulia Startsev
55e47a4cc9 Bug 1784482 - Do not rely on ScriptLoadRequestList in the main thread; r=asuth
This enables us to send files to load that are not part of our executing scripts list. This unlocks
the ability to send single module scripts to be loaded without executing them. It also gives
us a way to get the list of files that are to be loaded.

Depends on D147318

Differential Revision: https://phabricator.services.mozilla.com/D155231
2022-09-08 17:13:27 +00:00
Yulia Startsev
9601e09968 Bug 1784482 - Move creation of ScriptLoadRequests into own functions; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D147318
2022-09-08 17:13:26 +00:00
Butkovits Atila
4b03a9e7f7 Backed out 6 changesets (bug 1783190, bug 1784482) for causing crashes at mozilla::dom::Promise::MaybeReject(nsresult)]. CLOSED TREE
Backed out changeset 3bbb7bedfa0a (bug 1784482)
Backed out changeset a67c04d83558 (bug 1784482)
Backed out changeset 593c1d517530 (bug 1783190)
Backed out changeset 25311707288f (bug 1784482)
Backed out changeset 13e623b3779f (bug 1784482)
Backed out changeset f1f81f81af17 (bug 1784482)
2022-09-07 16:12:45 +03:00