Commit graph

624 commits

Author SHA1 Message Date
Eden Chuang
2f65cf28ae Bug 1769913 - P3 Remove WorkerRunnable::mWorkerPrivate. r=dom-worker-reviewers,asuth
WorkerRunnable no longer keeps a raw pointer(mWorkerPrivate) for the associated WorkerPrivate in this patch.
Removing the WorkerRunnable::mWorkerPrivate needs to fix the following problems.

1. Thread assertions in WorkerRunnable::Dispatch()

To fix this problem, the associated WorkerPrivate is as a parameter and passed to WorkerRunnable::Dispatch() for the dispatching thread assertions. This associated WorkerPrivate is also propagated to PreDispatch() and PostDispatch() for the children classes of WorkerRunnable()

2. Get the associated WorkerPrivate in WorkerRunnable::Run() for environment setup(GlobabObject, JSContext setting for the runnable)

- For WorkerThreadRunnable

Since WorkerThreadRunnable is supposed to run on the worker thread, it does not need to keep a raw pointer to WorkerPrivate as its class member. GetCurrentThreadWorkerPrivate() should always get the correct WorkerPrivate for WorkerThreadRunnable.

- For WorkerParentThreadRunnable

WorkerParentRef is introduced to keep a RefPtr<WorkerPrivate> for WorkerParentThreadRunnable instead of using a raw pointer.
Checking the associated WorkerPrivate existence by WorkerParentRef at the beginning of WorkerParentThreadRunnable::Run(). If the Worker has already shut down, WorkerParentThreadRunnable cannot do anything with the associated WorkerPrivate, so WorkerParentThreadRunnable::Run() will return NS_OK directly but with a warning.

The associated WorkerPrivate is also passed into WorkerRun(), PreRun(), and PostRun(), so the majority of implementations of child classes of WorkerRunnable do not need to be changed.

If there are any cases in which the child classes of WorkerThreadRunnable/WorkerParentThreadRunnable want to keep the associated WorkerPrivate, they should use WorkerRefs instead of raw pointers.

Depends on D205679

Differential Revision: https://phabricator.services.mozilla.com/D207039
2024-04-19 09:41:58 +00:00
Andrew Sutherland
5ab56cb0dd Bug 1886108 - Normalize error messages. r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D207104
2024-04-10 18:59:24 +00:00
Benjamin VanderSloot
19f8dbbd20 Bug 1876575, part 2 - Make Workers use ancestor chain for third-partiness check - r=anti-tracking-reviewers,timhuang,asuth
Differential Revision: https://phabricator.services.mozilla.com/D203289
2024-04-02 18:53:26 +00:00
Cristian Tuns
3ba835953e Backed out 6 changesets (bug 1876574, bug 1876575) for causing multiple failures in TestGetPrincipalCookieBehavior5 CLOSED TREE
Backed out changeset f00e9fde550f (bug 1876575)
Backed out changeset ca1c6f8819f7 (bug 1876575)
Backed out changeset d65ac05bd9f8 (bug 1876575)
Backed out changeset 5dcfe3aa8497 (bug 1876575)
Backed out changeset 9ae9252761ac (bug 1876575)
Backed out changeset 704e94d28ad7 (bug 1876574)
2024-04-02 09:58:52 -04:00
Benjamin VanderSloot
afb64f34d5 Bug 1876575, part 2 - Make Workers use ancestor chain for third-partiness check - r=anti-tracking-reviewers,timhuang,asuth
Differential Revision: https://phabricator.services.mozilla.com/D203289
2024-04-02 12:50:01 +00:00
Stanca Serban
23caed9eac Backed out 6 changesets (bug 1876574, bug 1876575) for causing multiple failures. CLOSED TREE
Backed out changeset 8c7a9f405031 (bug 1876575)
Backed out changeset 49739f9ec590 (bug 1876575)
Backed out changeset 1c49f0c3b677 (bug 1876575)
Backed out changeset 1ca7a0f27bc0 (bug 1876575)
Backed out changeset bfa9862e3480 (bug 1876575)
Backed out changeset 58576ed7eb22 (bug 1876574)
2024-03-29 20:52:30 +02:00
Benjamin VanderSloot
a9cc33eb14 Bug 1876575, part 2 - Make Workers use ancestor chain for third-partiness check - r=anti-tracking-reviewers,timhuang,asuth
Differential Revision: https://phabricator.services.mozilla.com/D203289
2024-03-29 17:12:14 +00:00
Sandor Molnar
09e7cbd0b7 Backed out 6 changesets (bug 1876575, bug 1876574) for causing build bustages @ toolkit/components/resistfingerprinting/nsRFPService.cpp CLOSED TREE
Backed out changeset 455ce831c73c (bug 1876575)
Backed out changeset 4fa3fbf3a3ae (bug 1876575)
Backed out changeset ac4c41cb3b67 (bug 1876575)
Backed out changeset 15e06d10788e (bug 1876575)
Backed out changeset dcd6bbea816a (bug 1876575)
Backed out changeset cc547125fda9 (bug 1876574)
2024-03-29 16:29:47 +02:00
Benjamin VanderSloot
5538e1f9d7 Bug 1876575, part 2 - Make Workers use ancestor chain for third-partiness check - r=anti-tracking-reviewers,timhuang,asuth
Differential Revision: https://phabricator.services.mozilla.com/D203289
2024-03-29 13:11:27 +00:00
Tooru Fujisawa
5f7c671736 Bug 1881564 - Initialize module loader also for ServiceWorker to allow ChromeUtils.importESModule in DevTools ServiceWorker debugger global. r=yulia
Dynamic import is prevented by IsDynamicImportSupported, and now it now throws
TypeError instead of Error, and related wpt passes with it.

Differential Revision: https://phabricator.services.mozilla.com/D202494
2024-03-20 11:22:45 +00:00
Cristian Tuns
ae4f962305 Backed out changeset 7f07a1c73ff7 (bug 1881564) for causing wpt failures in serviceworker.any.serviceworker.html CLOSED TREE 2024-02-27 04:14:43 -05:00
Tooru Fujisawa
54d5568eca Bug 1881564 - Initialize module loader also for ServiceWorker to allow ChromeUtils.importESModule in DevTools ServiceWorker debugger global. r=yulia
Dynamic import is still disabled for service worker by WorkerModuleLoader::CreateDynamicImport.

Differential Revision: https://phabricator.services.mozilla.com/D202494
2024-02-27 05:45:58 +00:00
Jens Stutte
a242ac1c0f Bug 1880235 - Add names to WorkerSyncRunnable derived runnables. r=dom-worker-reviewers,asuth
Differential Revision: https://phabricator.services.mozilla.com/D201813
2024-02-14 16:13:47 +00:00
Tooru Fujisawa
73c36f0f8f Bug 1878817 - Remove unused ModuleLoaderBase::mEventTarget member. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D200753
2024-02-06 10:15:29 +00:00
Tooru Fujisawa
d8c07cffa3 Bug 1800641 - Part 11: Allocate script in ScriptLoadRequest::NoCacheEntryFound. r=nbp
Depends on D197848

Differential Revision: https://phabricator.services.mozilla.com/D197849
2024-01-08 14:57:40 +00:00
Tooru Fujisawa
17c5cde210 Bug 1800641 - Part 10: Add ScriptLoadRequest::mLoadedScript. r=nbp
Depends on D197847

Differential Revision: https://phabricator.services.mozilla.com/D197848
2024-01-08 14:57:39 +00:00
Tooru Fujisawa
bdc574a37f Bug 1800641 - Part 9: Add LoadedScript::mURI and call SetBaseURL separately. r=nbp
Depends on D197846

Differential Revision: https://phabricator.services.mozilla.com/D197847
2024-01-08 14:57:39 +00:00
Tooru Fujisawa
976c794ad0 Bug 1800641 - Part 8: Add LoadContextBase* parameter to ScriptLoadRequest methods which is going to be moved to LoadedScriptDelegate. r=nbp
Depends on D197845

Differential Revision: https://phabricator.services.mozilla.com/D197846
2024-01-08 14:57:38 +00:00
Tooru Fujisawa
f135bad3aa Bug 1800641 - Part 7: Add ScriptLoadRequest::State::{CheckingCache,PendingFetchingError}. r=nbp
Depends on D197844

Differential Revision: https://phabricator.services.mozilla.com/D197845
2024-01-08 14:57:38 +00:00
Noemi Erli
7fd755cbb5 Backed out changeset 4d6294424819 (bug 1800641) for causing Bug 1872347 2023-12-29 16:23:18 +02:00
Nicolas B. Pierron
8a851d2266 Bug 1800641 - Move some ScriptLoadRequest fields into LoadedScript. r=yulia
We are looking into caching loaded script in memory. To do so we need something
to cache.

At the moment, the `ScriptLoadRequest` structure hold all the fields which are
loaded, and used before executing JavaScript code. Then, the `ScriptLoadRequest`
is not guaranteed to out-live the first execution.

Therefore, we have to move fields out of the `ScriptLoadRequest` such that they
can later be used by any caching mechanism. The `LoadedScript` is the closest
existing structure which exists which fit the description.

This patch moves fields out of the ScriptLoadRequest into the `LoadedScript`,
which already has a `LoadedScript` field.

The `LoadedScript` field is initialized sooner, when the `ScriptLoadRequest` is
created, to be subsituted later by a real cache implementation. At the moment
the function `ScriptLoadRequest::NoCacheEntryFound` is used as a placeholder to
change the state of the `ScriptLoadRequest` from `CheckingCache` to `Fetching`.
Existing initializations are replaced by assertions to fail in debug build if
the current patch does not reproduce the expected state properly.

The `LoadedScript` get fields such as the source text, the text length, the
bytecode buffer (which also contains SRI), and the offset at which the bytecode
starts within the bytecode buffer. As these fields are no longer reachable by
name, multiple accessors are added to work-around the issue. Using this as an
opportunity to add extra assertions as part of these accessors.

A new class named `LoadedScriptDelegate` is added to re-add, by inheritance, all
the accessors which used to be part of `ScriptLoadRequest` as methods which are
delegating to the field which is holding the `LoadedScript`. This class is using
templates to avoid virtual inheritance which might hinder inlining, especially
since `ScriptLoadRequest` cannot be made final, as `ModuleLoadRequest` extends
it.

The `ScriptFetchOptions` structure is moved to its own file to solve C++ include
issues.

Differential Revision: https://phabricator.services.mozilla.com/D163615
2023-12-25 09:46:54 +00:00
Cosmin Sabou
a9cb718ef1 Backed out changeset f69f493b2f3c (bug 1800641) for causing non-unified build bustages on LoadedScript.cpp. CLOSED TREE 2023-12-25 08:38:51 +02:00
Nicolas B. Pierron
7b23c511de Bug 1800641 - Move some ScriptLoadRequest fields into LoadedScript. r=yulia
We are looking into caching loaded script in memory. To do so we need something
to cache.

At the moment, the `ScriptLoadRequest` structure hold all the fields which are
loaded, and used before executing JavaScript code. Then, the `ScriptLoadRequest`
is not guaranteed to out-live the first execution.

Therefore, we have to move fields out of the `ScriptLoadRequest` such that they
can later be used by any caching mechanism. The `LoadedScript` is the closest
existing structure which exists which fit the description.

This patch moves fields out of the ScriptLoadRequest into the `LoadedScript`,
which already has a `LoadedScript` field.

The `LoadedScript` field is initialized sooner, when the `ScriptLoadRequest` is
created, to be subsituted later by a real cache implementation. At the moment
the function `ScriptLoadRequest::NoCacheEntryFound` is used as a placeholder to
change the state of the `ScriptLoadRequest` from `CheckingCache` to `Fetching`.
Existing initializations are replaced by assertions to fail in debug build if
the current patch does not reproduce the expected state properly.

The `LoadedScript` get fields such as the source text, the text length, the
bytecode buffer (which also contains SRI), and the offset at which the bytecode
starts within the bytecode buffer. As these fields are no longer reachable by
name, multiple accessors are added to work-around the issue. Using this as an
opportunity to add extra assertions as part of these accessors.

A new class named `LoadedScriptDelegate` is added to re-add, by inheritance, all
the accessors which used to be part of `ScriptLoadRequest` as methods which are
delegating to the field which is holding the `LoadedScript`. This class is using
templates to avoid virtual inheritance which might hinder inlining, especially
since `ScriptLoadRequest` cannot be made final, as `ModuleLoadRequest` extends
it.

The `ScriptFetchOptions` structure is moved to its own file to solve C++ include
issues.

Differential Revision: https://phabricator.services.mozilla.com/D163615
2023-12-25 05:50:53 +00:00
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
Andrew Sutherland
49058aa9d5 Bug 1856090 - Improve ServiceWorker state propagation. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D190245
2023-10-24 20:34:25 +00:00
Artur Iunusov
3beddab32f Bug 1831583: Fix secFlags when fetching a module script, r=dom-worker-reviewers,smaug
https://html.spec.whatwg.org/#fetch-a-single-module-script
Step 8. Let request be a new request whose URL is url,
destination is destination, mode is "cors",
referrer is referrer, and client is fetchClient.

Differential Revision: https://phabricator.services.mozilla.com/D181065
2023-09-25 14:37:00 +00:00
Yoshi Cheng-Hao Huang
cd69bc3c65 Bug 1841859 - Part 1: Move ReferrerPolicy to ScriptLoadRequest and LoadedScript. r=jonco,smaug
Suggested by jonco during review,
https://phabricator.services.mozilla.com/D186944#inline-1036982

Differential Revision: https://phabricator.services.mozilla.com/D187385
2023-09-20 17:32:15 +00:00
Mirko Brodesser
2966a909e7 Bug 1839316: part 4) Add RequestPriority to ScriptFetchOptions and ScriptLoadRequest. r=smaug
The request priority isn't propagated from `ScriptFetchOptions`, so
setting it has no effect for end-users. That will be implemented in a
following part.

Differential Revision: https://phabricator.services.mozilla.com/D183483
2023-08-28 11:56:34 +00:00
Yoshi Cheng-Hao Huang
af590ba000 Bug 1831324 - Part 2: Check if classic worker script can be compiled. r=dom-worker-reviewers,smaug
According to the spec,
https://html.spec.whatwg.org/#run-a-worker

14. In both cases, let onComplete given script be the following steps:
  1. If script is null or if script's error to rethrow is non-null, then:
    1. Queue a global task on the DOM manipulation task source given worker's relevant global object to fire an event named error at worker.
    2. Run the environment discarding steps for inside settings.
    3. Abort these steps.

Split EvaluateSourceBuffer into JS::Compile and JS_ExecuteScript.
So if we found the script cannot be compiled and it is a top-level script,
we assign a non-JS-Exception error code to it.

If the script cannot be compiled and it's not a top-level script, this
means it's a script which is loaded by importScripts(), according to the
spec, https://html.spec.whatwg.org/#import-scripts-into-worker-global-scope
the exception will be rethrown.

Differential Revision: https://phabricator.services.mozilla.com/D185532
2023-08-15 16:26:51 +00:00
Yoshi Cheng-Hao Huang
8570bf9c5d Bug 1831324 - Part 1: Check if the module worker script has a parse error or an error to rethrow. r=jonco,dom-worker-reviewers,smaug
According to the spec,
https://html.spec.whatwg.org/#run-a-worker

14. In both cases, let onComplete given script be the following steps:
  1. If script is null or if script's error to rethrow is non-null, then:
    1. Queue a global task on the DOM manipulation task source given worker's relevant global object to fire an event named error at worker.
    2. Run the environment discarding steps for inside settings.
    3. Abort these steps.

Check if the module worker script has a parse error or an error to
rethrow. If it has, assign an error code to mRv and return false.

The error will be reported in CompileScriptRunnable
https://searchfox.org/mozilla-central/rev/892475f3ba2b959aeaef19d1d8602494e3f2ae32/dom/workers/WorkerPrivate.cpp#417

Differential Revision: https://phabricator.services.mozilla.com/D185531
2023-08-15 16:26:51 +00:00
Yoshi Cheng-Hao Huang
e2668be1a6 Bug 1847548 - Part 1: Use nsIContentPolicy::TYPE_INTERNAL_MODULE for worker's dynamic import scripts. r=dom-worker-reviewers,smaug,evilpie
Differential Revision: https://phabricator.services.mozilla.com/D185563
2023-08-15 07:54:55 +00:00
Cosmin Sabou
c406bcf318 Backed out 5 changesets (bug 1839316) for causing bustages on ScriptLoader.cpp. CLOSED TREE
Backed out changeset 85f107e082ee (bug 1839316)
Backed out changeset 8c1e22518c3a (bug 1839316)
Backed out changeset a4c3dec0f34c (bug 1839316)
Backed out changeset 313ff15742dd (bug 1839316)
Backed out changeset fa200e26bbb1 (bug 1839316)
2023-08-09 20:16:06 +03:00
Mirko Brodesser
5cade38f47 Bug 1839316: part 4) Add RequestPriority to ScriptFetchOptions and ScriptLoadRequest. r=smaug
The request priority isn't propagated from `ScriptFetchOptions`, so
setting it has no effect for end-users. That will be implemented in a
following part.

Differential Revision: https://phabricator.services.mozilla.com/D183483
2023-08-09 13:50:28 +00:00
Cosmin Sabou
0058dbdd1c Backed out 5 changesets (bug 1839316) for causing leaks. CLOSED TREE
Backed out changeset 75edff380fee (bug 1839316)
Backed out changeset 6a622fd5cd91 (bug 1839316)
Backed out changeset 60908cc7c586 (bug 1839316)
Backed out changeset 7b9dd8875a9e (bug 1839316)
Backed out changeset b586915187c2 (bug 1839316)
2023-08-07 16:43:03 +03:00
Mirko Brodesser
5d091f10d0 Bug 1839316: part 4) Add RequestPriority to ScriptFetchOptions and ScriptLoadRequest. r=smaug
The request priority isn't propagated from `ScriptFetchOptions`, so
setting it has no effect for end-users. That will be implemented in a
following part.

Differential Revision: https://phabricator.services.mozilla.com/D183483
2023-08-07 11:46:19 +00:00
Jon Coppeard
80cac6bbb5 Bug 1843838 - Rename ScriptLoadRequest::IsReadyToRun to IsFinished since this returns true for cancelled requests r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D183740
2023-08-04 09:40:40 +00:00
Jon Coppeard
85b88021df Bug 1842798 - Part 2: Remove use of MozPromise to wait for module imports to load r=smaug
This replaces the use of a promise to wait for all imports of a module to load
with a counter of reminaing imports in the parent and a pointer to the parent
that is waiting in the child. The parent request is updated immediately rather
than by dispatching a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183273
2023-08-03 08:15:29 +00:00
Narcis Beleuzu
cf92578c03 Backed out 4 changesets (bug 1842798) for wpt failures on module-tla-import.html . CLOSED TREE
Backed out changeset 879154594bb1 (bug 1842798)
Backed out changeset 2a6b3ff79a01 (bug 1842798)
Backed out changeset 507da9d36f91 (bug 1842798)
Backed out changeset 3528d70acb5f (bug 1842798)
2023-08-02 20:48:53 +03:00
Jon Coppeard
afcabcef11 Bug 1842798 - Part 2: Remove use of MozPromise to wait for module imports to load r=smaug
This replaces the use of a promise to wait for all imports of a module to load
with a counter of reminaing imports in the parent and a pointer to the parent
that is waiting in the child. The parent request is updated immediately rather
than by dispatching a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183273
2023-08-02 14:39:33 +00:00
Sandor Molnar
9de1620f3b Backed out 4 changesets (bug 1842798) for causing wpt failures in /html/webappapis/dynamic-markup-insertion/document-write/module-dynamic-import.html CLOSED TREE
Backed out changeset b153ebf104ef (bug 1842798)
Backed out changeset 05bcaff61b68 (bug 1842798)
Backed out changeset 0864a23409e6 (bug 1842798)
Backed out changeset 98a1aa86513d (bug 1842798)
2023-08-02 14:58:13 +03:00
Jon Coppeard
7378829120 Bug 1842798 - Part 2: Remove use of MozPromise to wait for module imports to load r=smaug
This replaces the use of a promise to wait for all imports of a module to load
with a counter of reminaing imports in the parent and a pointer to the parent
that is waiting in the child. The parent request is updated immediately rather
than by dispatching a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183273
2023-08-02 09:34:39 +00:00
Tom Schuster
ecff00a7ba Bug 1843002 - Add parser-metadata to ScriptFetchOptions. r=allstarschh,smaug
Differential Revision: https://phabricator.services.mozilla.com/D183366
2023-07-21 17:28:02 +00:00
Tom Schuster
936032fed3 Bug 1843002 - Add nonce to ScriptFetchOptions. r=allstarschh,smaug
Differential Revision: https://phabricator.services.mozilla.com/D183365
2023-07-21 17:28:02 +00:00
Stanca Serban
70ab9b117e Backed out 6 changesets (bug 1313937, bug 1843066, bug 1843002) for causing build bustages in ScriptLoadRequest.h. CLOSED TREE
Backed out changeset 84c2d1c04aa2 (bug 1313937)
Backed out changeset 7cab9a1ea25f (bug 1313937)
Backed out changeset affc7d1f130d (bug 1313937)
Backed out changeset e13aacfe7944 (bug 1843066)
Backed out changeset 21a9bee8f772 (bug 1843002)
Backed out changeset d381b6365111 (bug 1843002)
2023-07-21 17:41:04 +03:00
Tom Schuster
593c5e731b Bug 1843002 - Add parser-metadata to ScriptFetchOptions. r=allstarschh,smaug
Differential Revision: https://phabricator.services.mozilla.com/D183366
2023-07-21 12:31:23 +00:00
Tom Schuster
9df91ffb4d Bug 1843002 - Add nonce to ScriptFetchOptions. r=allstarschh,smaug
Differential Revision: https://phabricator.services.mozilla.com/D183365
2023-07-21 12:31:22 +00:00
Natalia Csoregi
87dee095ca Backed out 6 changesets (bug 1842798) for causing failures on js/src/tests/test262/language/*. CLOSED TREE
Backed out changeset 38669a2ddad9 (bug 1842798)
Backed out changeset 5dad4aeacd53 (bug 1842798)
Backed out changeset 23d10eb8f853 (bug 1842798)
Backed out changeset 946e4dfe5452 (bug 1842798)
Backed out changeset 1b89736a463f (bug 1842798)
Backed out changeset b2e6bdd781ac (bug 1842798)
2023-07-17 20:52:18 +03:00
Jon Coppeard
3aab0ac6ba Bug 1842798 - Part 3: Remove unused event target from ModuleLoaderBase r=smaug
This was previously used by MozPromise but is no longer required.

Differential Revision: https://phabricator.services.mozilla.com/D183586
2023-07-17 12:44:19 +00:00
Jon Coppeard
3d87996a4b Bug 1842798 - Part 2: Remove use of MozPromise to wait for module imports to load r=smaug
This replaces the use of a promise to wait for all imports of a module to load
with a counter of reminaing imports in the parent and a pointer to the parent
that is waiting in the child. The parent request is updated immediately rather
than by dispatching a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183273
2023-07-17 12:44:18 +00:00
Yoshi Cheng-Hao Huang
77132d9570 Bug 1833503 - Add ref to ScriptLoaderRunnable. r=dom-worker-reviewers,smaug
Differential Revision: https://phabricator.services.mozilla.com/D181214
2023-06-19 20:26:52 +00:00