Commit Graph

167 Commits

Author SHA1 Message Date
Jon Coppeard
88dcd540b5 Bug 1835886 - Cancel outstanding load requests when a document is detached from a global r=smaug, a=dmeehan
Also cancel module load requests when cancelling requests generally.

What was happening here was that a previous load was completing and calling
into the wrong module loader, because the loader to use is determined via the
current global, and this was now associated with a different document / script
loader / module loader.

Differential Revision: https://phabricator.services.mozilla.com/D179787
2023-06-13 08:46:26 +00:00
Cristina Horotan
0c2945ad47 Backed out 3 changesets (bug 1803984)
Backed out changeset d6316cfb118d (bug 1803984)
Backed out changeset bcbcbdf4f449 (bug 1803984)
Backed out changeset 3bc8c30ecc25 (bug 1803984)
2023-05-29 12:36:25 +03:00
Jon Coppeard
c4161d1f6c Bug 1803984 - Add assertion that we only remove unlinked modules from the map r=allstarschh
It would not be correct to remove modules that were already linked or evaluated.



Depends on D178298

Differential Revision: https://phabricator.services.mozilla.com/D178787
2023-05-26 12:22:54 +00:00
Yoshi Cheng-Hao Huang
b32c496142 Bug 1803984 - Don't use the preloaded module request if there's an import map. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D178298
2023-05-26 12:22:54 +00:00
Yoshi Cheng-Hao Huang
a30459a36b Bug 1826110 - Add the module's URL into the error message. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D178627
2023-05-22 15:30:16 +00:00
Yulia
2e8899ceb2 Bug 1822452 - Reject any remaining requests; r=jonco
This patch allows us to reject any outstanding requests when terminating a worker. As this is
controlled by the module loader, the approach I took here was to reject the promises and allow the
moduleloader to
shutdown. I am open to alternatives however.

Differential Revision: https://phabricator.services.mozilla.com/D173290
2023-03-23 09:54:49 +00:00
Jon Coppeard
45f3eca05d Bug 1822717 - Relax assertion about module request state when an error occurs r=yulia
ModuleErrored() can be called when we are in the compiling state too, if we are
parsing the module off-thread.

Differential Revision: https://phabricator.services.mozilla.com/D173160
2023-03-21 15:40:22 +00:00
Yoshi Cheng-Hao Huang
19e0568f4d Bug 1820119 - import() should throw a TypeError in a worklet script. r=jonco,yulia
Differential Revision: https://phabricator.services.mozilla.com/D171563
2023-03-19 20:39:02 +00:00
Sandor Molnar
b1ca540f9f Backed out changeset d341f6827d75 (bug 1820119) for causing xpc failures in js/xpconnect/tests/unit/test_import_es6_modules.js CLOSED TREE 2023-03-16 19:18:45 +02:00
Yoshi Cheng-Hao Huang
d73f5a0402 Bug 1820119 - import() should throw a TypeError in a worklet script. r=jonco,yulia
Differential Revision: https://phabricator.services.mozilla.com/D171563
2023-03-16 14:27:48 +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
99088fb36f Bug 1540913 - Part 3: Exit early if worker module evaluation is aborted; r=jonco
This change addresses the second issue around worker shutdown with infinitely running dynamic
imports: As the event loop is prevented from running when the worker is dying, we do not want to
delegate to the event loop in this case. This case always has a failing promise. Since this is a
failure case related to the worker dying, we stop running code, rather
than waiting for a tick (that never comes) from the event loop.

Differential Revision: https://phabricator.services.mozilla.com/D171684
2023-03-14 18:16:31 +00:00
Yulia
5231b910c8 Bug 1540913 - Part 2: Clear and shutdown ModuleLoader at worker termination; r=asuth,jonco
When running an infinitely-looping dynamic import, it is possible for the module loader to still be
holding on to that module at shutdown. Shutdown on the worker means that we will no longer run the
event loop, which will execute the dynamic import promises necessary to clear the global. The result
is that the global is kept alive. By calling `Shutdown()` we prevent this partially. We additionally
need to address the failure in the module code (next patch).

Differential Revision: https://phabricator.services.mozilla.com/D171683
2023-03-14 18:16:31 +00:00
Yulia
4e6402f008 Bug 1540913 - Part 1: allow ModuleLoaders to return BaseURI without ScriptLoader;r=jonco
This is a required change for dynamic import on workers, as the ScriptLoader is not guaranteed to
live long enough. Once the initial script loading is finished, and the script has executed, the
scriptloader is cleared and the strong reference to the workerRef is cleared so that shutdown is
possible. The workerRef is required in order to access the worker private safely. In order to
address this, we move the GetBaseURI method to the module loader itself. In the future, we should
remove the script loader interface all together.

Differential Revision: https://phabricator.services.mozilla.com/D171682
2023-03-14 18:16:30 +00:00
Yoshi Cheng-Hao Huang
a582a668da Bug 1572644 - Part 11-2: Preload localized error msg and format it when resolving failed. r=jonco,yulia
Depends on D166549

Differential Revision: https://phabricator.services.mozilla.com/D170161
2023-03-13 22:59:41 +00:00
Yoshi Cheng-Hao Huang
c01828aba9 Bug 1572644 - Part 11-1: Add a virtual method GetResolveFailureMessage in ModuleLoaderBase. r=jonco,yulia
The virtual method will be overrided by WorkletModuleLoader in the next
patch.



Depends on D166548

Differential Revision: https://phabricator.services.mozilla.com/D166549
2023-03-13 22:59:41 +00:00
Yoshi Cheng-Hao Huang
becf8aade2 Bug 1572644 - Part 8: Compile fetched module. r=jonco,yulia
The compile options is from ExecutionRunnable::ParseAndLinkModule of the
previous patch, or could be found in
https://searchfox.org/mozilla-central/rev/fb9a504ca73529fa550efe488db2a012a4bf5169/dom/worklet/Worklet.cpp#386-389



Depends on D166545

Differential Revision: https://phabricator.services.mozilla.com/D166546
2023-03-13 22:59:39 +00:00
Yoshi Cheng-Hao Huang
7ae6a1f9c2 Bug 1572644 - Part 4: Add WorkletLoadContext and nsMainThreadPtrHandle to delegate WorkletFetchHandler on the worklet thread. r=jonco,yulia
Add nsMainThreadPtrHandle to delegate WorkletFetchHandler.
Add WorkletLoadContext to wrap nsMainThreadPtrHandle.



Depends on D166541

Differential Revision: https://phabricator.services.mozilla.com/D166542
2023-03-13 22:59:37 +00:00
Yulia
2e680f55e9 Bug 1821066 - Ensure that module error is correctly set when ResolveRequestedModules fails; r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D172243
2023-03-10 17:30:04 +00:00
Yoshi Cheng-Hao Huang
0f577f10c3 Bug 1815180 : Dump error message when import maps aren't allowed. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D169185
2023-02-08 12:22:04 +00:00
Jon Coppeard
f8267f1612 Bug 1813494 - Part 3: Add more cancellation checks and state assertions to module load requests r=smaug
We should check for previous cancellation on all path where a module load
request's state can be changed by an asynchronous action. Also add assertions
about the expected previous state where possible.

Differential Revision: https://phabricator.services.mozilla.com/D168233
2023-02-07 11:55:51 +00:00
Jon Coppeard
e205425545 Bug 1813494 - Part 2: Add IsErrored() predicate for module load request r=smaug
This condition is checked in a few places.

Differential Revision: https://phabricator.services.mozilla.com/D168232
2023-02-07 11:55:51 +00:00
Jon Coppeard
15081498f4 Bug 1811939 - Check whether module load request was already cancelled when a load fails r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D167927
2023-01-27 17:19:57 +00:00
Peter Van der Beken
1f731ae6fe Bug 1811238 - Correct QueryInterface implementation of LoadedScript and ModuleLoaderBase. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D167252
2023-01-24 09:55:27 +00:00
Yulia Startsev
87c8288cb8 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2023-01-18 13:46:32 +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
Jonatan Klemets
402679a7ad Bug 1810366 - Remove unused requestedModule variable in ModuleLoaderBase::ResolveRequestedModules r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D166879
2023-01-16 20:17:30 +00:00
Jon Coppeard
fd91a397f2 Bug 1809880 - Avoid cast to derived type in ScriptLoadRequest base class destructor r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D166809
2023-01-16 16:15:15 +00:00
Yoshi Cheng-Hao Huang
87d399b16d Bug 1808357: Add better error message for importmaps of invalid JSON format. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D166084
2023-01-06 13:34:17 +00:00
Jon Coppeard
addd297a0f Bug 1806725 - Avoid gray unmarking when unlinking module records r=mccr8,sfink
Original patch by mccr8.

At least for the cycle collector, the purpose of calling unmark gray when
accessing a JS field of a C++ object is to avoid creating references from a
black object to a gray object. However, this particular code is writing
undefined, so that should not be a danger.

This particular code is by its nature dealing with GC things that are gray and
may be about to be GCed, so calling unmark grey can waste a tremendous amount
of time. On a profile of collecting a JS-heavy page, I was seeing 20% of the
100ms CC being spent on it.

The patch uses unbarrieredGet in ModuleScript::UnlinkModuleRecord and adds a
new API to clear a module record's private value without checking whether
associated objects are gray.

Differential Revision: https://phabricator.services.mozilla.com/D165202
2023-01-04 09:40:05 +00:00
Peter Van der Beken
a20a1d18eb Bug 1806872 - Correct QueryInterface implementation of ScriptLoadRequest and LoadContextBase. r=mccr8
Differential Revision: https://phabricator.services.mozilla.com/D165313
2022-12-21 18:09:35 +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
ef3c7012f8 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2022-12-20 20:56:14 +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
Yulia Startsev
6952f8568d Bug 1805873 - Clean up HasWorkerLoadContext code related to non-cc'd load context;r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D165040
2022-12-19 15:34:10 +00:00
Jon Coppeard
50c149f6dc Bug 1806136 - Part 0: Change the API so that the supported assertions are set once on initialization r=arai
Not related to the rest of the bug. This is a simplification so that we set the
supported import assertions once rather than querying the host every time they
are needed.

Differential Revision: https://phabricator.services.mozilla.com/D164914
2022-12-19 11:56:34 +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
Andrew McCreight
ce28c41da0 Bug 1805931, part 2 - Automated removal of uses of ROOT and UNROOT CC macros. r=smaug
As of the prior patch, these are no longer needed. I removed
these with a script, then ran clang-format on the files, then
manually reverted a few unrelated changed from the formatter.

Differential Revision: https://phabricator.services.mozilla.com/D164829
2022-12-15 19:45:01 +00:00
Yulia Startsev
51d7d18a24 Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely
running script being forcibly terminated) we will be in a state where the EvaluateModule call will
finish _after_ the loader is destroyed. So, instead we track if there has been a forcible
cancelation, and exit early.

Depends on D155690

Differential Revision: https://phabricator.services.mozilla.com/D155568
2022-12-14 14:55:37 +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
Jon Coppeard
7856ea877c Bug 1804254 - Part 3: Replace RequestedModuleObject with native RequestedModule r=arai
This is more complicated because it needed a change to the public API now we're
not longer returning an array object. The new API is less error prone since
it's no longer possible for the caller to mutate the object returned.

Depends on D163948

Differential Revision: https://phabricator.services.mozilla.com/D163949
2022-12-07 11:28:28 +00:00
Jon Coppeard
f3248398d8 Bug 1774111 - Check for already-completed request in ModuleLoaderBase::FinishDynamicImport r=yulia
I've looked at this for a while and still don't know how this can happen but it
does seem reasonable to add a check here that we haven't already completed the
request.

Depends on D162386

Differential Revision: https://phabricator.services.mozilla.com/D162387
2022-11-18 13:25:47 +00:00
Jon Coppeard
71d7de8c4d Bug 1774111 - Initialize AutoJAPI from the native global in the module loader r=yulia
We're getting a bunch of crashes related to initializing AutoJSAPI from a
JSObject pointer that turns out to be null. That overload of Init() gets the
native global from the JSObject and since we already have a native global in
the module loader we can use the overload that takes that instead. This
overload does a null check so we will catch the case where the global is null
(although that should also not happen).

This might just move crashes elsewhere but it's a reasonable tidyup.

Differential Revision: https://phabricator.services.mozilla.com/D162386
2022-11-18 13:25:46 +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
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
Yulia Startsev
17fd034c7a Bug 1797327 - Introduce CC'd and non CC'd variants of LoadContextBase; r=jonco
In order to use the WorkerLoadContext as a handle for ScriptLoadRequests in the main thread portion
of worker loading, we need to make it thread safe. Which means, it cannot be CC'd, and we need to
manually break cycles. This patch does the first portion of this work, which is inroduce two new
loadContextBase classes, that are either cc'd or not cc'd. For the DOM and mozJSComponent loader, we
continue to use a CC'd LoadContextBase. Workers however now have a non-cc'd variant.

Differential Revision: https://phabricator.services.mozilla.com/D160333
2022-11-01 18:03:34 +00:00
Jon Coppeard
f64d585ec0 Bug 1797166 - Don't assume an exception is always set if module compilation fails r=yulia
It would be nice to assume this but CompileFetchedModule can potentially fail for reasons that
are not JS-related.

Also check for the exception being |undefined| which would cause
ModuleScript::HasParseError to return false. Such an exception should never be
thrown by parsing but check for it just in case.

Add a diagnostic assert to check module script state is as we expect to
hopefully catch related problems sooner.

Differential Revision: https://phabricator.services.mozilla.com/D160788
2022-10-31 14:26:48 +00:00
Jon Coppeard
a8344b1f34 Bug 1712762 - Check if module load requests have already been cancelled in ModuleLoaderBase::CancelDynamicImport r=yulia
I don't know whether this is the problem, but if we try and cancel a request
that has already been cancelled it would produce this crash.

Differential Revision: https://phabricator.services.mozilla.com/D159167
2022-10-12 16:26:20 +00:00
Yoshi Cheng-Hao Huang
ee07ecaeec Bug 1778289 - Part 12: Update spec links as the PR is merged. r=jonco,yulia
The PR has been merged.
See https://html.spec.whatwg.org/multipage/webappapis.html#import-maps

Differential Revision: https://phabricator.services.mozilla.com/D158828
2022-10-07 13:56:27 +00:00