Commit graph

529 commits

Author SHA1 Message Date
Yulia Startsev
904f7c679e Bug 1247687 - Use requestCredentials to set secFlags for modules; r=jonco
This implements the specified request credentials behavior from the spec, and is tested in wpt.

Depends on D155566

Differential Revision: https://phabricator.services.mozilla.com/D155690
2022-12-14 14:55:37 +00:00
Yulia Startsev
5ac66699bc Bug 1247687 - Implement requestCredentials for Module Workers; r=jonco
This weaves credentials through from the private to script creation.

Depends on D155567

Differential Revision: https://phabricator.services.mozilla.com/D155566
2022-12-14 14:55:36 +00:00
Yulia Startsev
d3ca0aecd0 Bug 1247687 - Implement correct referrer for modules; r=jonco
In our implementation, we do not have "client" as a referrer, so we resolve the URI directly as part
of ScriptLoadRequest creation.

Depends on D147327

Differential Revision: https://phabricator.services.mozilla.com/D155567
2022-12-14 14:55:36 +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
4763aa8e30 Bug 1247687 - Call EnsureAndLoadStringBundle from Worker ScriptLoaderRunnable; r=allstarschh
Depends on D163238

Differential Revision: https://phabricator.services.mozilla.com/D163239
2022-12-14 14:55:33 +00:00
Stanca Serban
591b091f05 Backed out changeset 6499b9cc1cfc (bug 1803062) for causing worker related failures. CLOSED TREE 2022-12-13 10:21:29 +02:00
Jan Varga
1b5145d00f Bug 1803062 - GetSerialEventTarget should return the nested event target when a sync loop is running; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D163841
2022-12-13 04:56:35 +00:00
Nika Layzell
8351f7cc2d Bug 1804093 - Part 5: Eliminate WorkerPrincipal and WorkletPrincipals, r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D163856
2022-12-12 22:08:36 +00:00
Jan Varga
860132797b Bug 1803062 - Switch from ordinary bool errors to nsresult errors in code for handling sync loops; r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D163559
2022-12-12 16:09:12 +00:00
Yulia Startsev
efb8b72942 Bug 1801833 - ensure release request is only ever done in a lock; r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D162759
2022-11-23 21:02:10 +00:00
Yulia Startsev
d2114afee2 Bug 1801344 - fix iteration over ThreadSafeRequestHandler; r=asuth
This fixes a build error. It was a bit tricker than I expected, comments are inline.

Differential Revision: https://phabricator.services.mozilla.com/D162578
2022-11-21 18:24:22 +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
1b7f8a5326 Bug 1800496 - Re-introduce channel tracking for cancellation; r=asuth
This was removed as part of an attempt to simplify worker cancellaton. However, this channel cancellation is important, as without it the timing changes when we finish a request. Without it, we continue to load a script, even after a worker has been shut down.

This tracking will help us reimplement cancellation.

Differential Revision: https://phabricator.services.mozilla.com/D162215
2022-11-18 10:02:26 +00:00
Yulia Startsev
32c96913a6 Bug 1800496 - Re-introduce Cycle Collected LoadContextBase for Workers; r=jonco
The non-cycle collected LoadContextBase caused failures for Module Workers. This reverts that change

Differential Revision: https://phabricator.services.mozilla.com/D162214
2022-11-18 10:02:26 +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
Daniel Holbert
7f83cbcfba Bug 1800342: Make NS_NewPipe2 and NS_NewPipe infallible, to reflect reality. r=xpcom-reviewers,necko-reviewers,nika,kershaw
This patch doesn't change behavior; these APIs were already effectively
infallible, in the sense that it was impossible for them to return anything
other than NS_OK.

The actual API changes here are in xpcom/io/nsIPipe.idl and
xpcom/io/nsPipe3.cpp, and the rest of this patch is just updates to callsites,
removing code that handled failure-flavored return values from these functions.
(All of this removed code was already dead code, effectively.)

Differential Revision: https://phabricator.services.mozilla.com/D161947
2022-11-14 23:22:16 +00:00
Yulia Startsev
d2fa4ee51a Bug 1798667 - clear cache when finished with service worker scripts; r=asuth
I was over eager in introducing the strong pointers to WorkerLoadContext. It turns out that
previously when we were cycle collecting our ScriptLoadRequests, we were also cleaning up everything
related to WorkerLoadContext. Also, in an attempt to fix the cancellation for workers, We
accidentally stopped cleaning up the reference to the cache creator. This patch does the following:

1) cleans up the cache creator reference whenever we finish with a cache load handler. This is done
by calling Fail appropriately. This solves both bug 1798667 (we no longer reach NEW_URI if we fail)
and 1781295 (we no longer leak memory because things were not cleaned up properly).
2) Does no remove the back reference to WorkerLoadContext from the LoadRequest. It turns out that
this is sometimes necessary. There is a chance that we will accidently try to access the
WorkerLoadContext after cancellation. This actually causes problems later on in the module code.

Differential Revision: https://phabricator.services.mozilla.com/D161288
2022-11-04 15:04:27 +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
Jan Varga
940cf12bc4 Bug 1791747 - AutoSyncLoopHolder::GetEventTarget should return nsISerialEventTarget (instead of nsIEventTarget); r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D157805
2022-10-28 06:18:10 +00:00
Yulia Startsev
e6ba9b8b31 Bug 1792984 - Introduce asserts and refptrs r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158425
2022-10-18 16:20:13 +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
ea70cc191e Bug 1792984 - Introduce asserts r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158425
2022-10-13 10:53:48 +00: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
dba0139599 Bug 1792984 - Introduce asserts r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D158425
2022-10-13 07:19:25 +00: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
Yulia Startsev
5ad6240ade Bug 1786571 - Do not call LoadingFinished from handlers when cancelled; r=asuth
This largely keeps in tact what jstutte did. The initial crash was fixed by eagerly calling
LoadingFinished. The second crash is caused because we call it twice, and only in the service worker
case, where we call it once the promise rejects. Now, we check if we have cancelled, and if we have
then we don't call the scriptLoader methods from inside of the load handlers. LoadHandlers now only
use OnStreamComplete if they are "successful" -- that is, if they were not cancelled.

OnStreamComplete retains its assertion error in the case that something was cancelled and we somehow
ended up there. In a follow up, I will clean up the friend classes of the ScriptLoader so you can't
easily access these methods from the LoadHandlers.

Differential Revision: https://phabricator.services.mozilla.com/D158262
2022-09-29 16:28:30 +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
Yulia Startsev
8c7b1e9f2d 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-07 09:37:40 +00:00