Commit graph

110 commits

Author SHA1 Message Date
Yoshi Cheng-Hao Huang
803c459eb4 Bug 1893164 - Make CancelImport() won't cancel a request if the URI is been waiting by other requests. r=jonco
In the following module graph:

0.html
  +---- 1.mjs
    +---- non_existing.mjs
    +---- 3.mjs
  +----- 2.mjs
    +---- 3.mjs

Both 1.mjs and 2.mjs have a common submodule called 3.mjs
But 1.mjs also has a non-existing submodule, so we can't instantiate the
module graph of 1.mjs. which in turn will cancel 3.mjs

But 3.mjs is also a sub-module of 2.mjs, so in order to instantiate the
module graph of 2.mjs, we skip canceling 3.mjs when we processed 1.mjs

Differential Revision: https://phabricator.services.mozilla.com/D209210
2024-05-07 16:03:20 +00:00
Jonatan Klemets
0c574f538b Bug 1889319 - Remove unused ModuleLoaderBase::RemoveFetchedModule declaration r=spidermonkey-reviewers,jonco
Differential Revision: https://phabricator.services.mozilla.com/D206462
2024-04-03 12:09:22 +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
Jon Coppeard
3e83b7268e Bug 1877703 - Part 2: Track request for currently fetching module in the module map r=smaug
Currently we record the URI of each fetching modules and any addtional requests
that are blocked waiting on that fetch. This adds the fetching module request
itself.

This is needed by the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D204201
2024-03-19 10:07:34 +00:00
Norisz Fay
66f73c547b Backed out 4 changesets (bug 1877703) as requested by dev for causing Bug 1885443
Backed out changeset 5eb60e36ef79 (bug 1877703)
Backed out changeset 5921d1fb831e (bug 1877703)
Backed out changeset 64281b11237e (bug 1877703)
Backed out changeset 7ee0827809fb (bug 1877703)
2024-03-15 13:28:07 +02:00
Jon Coppeard
e5f17b703c Bug 1877703 - Part 2: Track request for currently fetching module in the module map r=smaug
Currently we record the URI of each fetching modules and any addtional requests
that are blocked waiting on that fetch. This adds the fetching module request
itself.

This is needed by the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D204201
2024-03-13 13:25:29 +00:00
Norisz Fay
2700ed8b59 Backed out 4 changesets (bug 1877703) for causing ScriptLoader related wpt failures
Backed out changeset 6b99c1c567b4 (bug 1877703)
Backed out changeset bc9c70289244 (bug 1877703)
Backed out changeset 1e17b87ab7f8 (bug 1877703)
Backed out changeset 591b5483bcd8 (bug 1877703)
2024-03-12 23:43:16 +02:00
Jon Coppeard
7a84df2611 Bug 1877703 - Part 2: Track request for currently fetching module in the module map r=smaug
Currently we record the URI of each fetching modules and any addtional requests
that are blocked waiting on that fetch. This adds the fetching module request
itself.

This is needed by the next patch.

Differential Revision: https://phabricator.services.mozilla.com/D204201
2024-03-12 16:43:48 +00:00
Tooru Fujisawa
e379bd0e94 Bug 1803810 - Part 4: Add mozJSModuleLoader for non-shared global. r=jonco
On the main thread, single mozJSModuleLoader instance is shared across all
loads in non-shared global, with resetting the internal state after importing
a module graph.

NonSharedGlobalSyncModuleLoaderScope manages the lifetime of each usage.
Import into the same non-shared global can be nested, but import into the
different non-shared gloobal is not allowed while other import for non-shared
global is ongoing.

Differential Revision: https://phabricator.services.mozilla.com/D199456
2024-02-14 02:01:37 +00:00
Tooru Fujisawa
a380811687 Bug 1803810 - Part 3: Add methods to copy and move imported modules. r=jonco
In non-shared global, the sync load is performed by separate SyncModuleLoader,
with the following algorithm:
  1. copy all loaded modules from async module loader, so that they can be
     used in the module graph in SyncModuleLoader
  2. import a module graph
  3. move all modules to async module loader

ModuleLoaderBase::CopyModulesTo is for step 1, and
ModuleLoaderBase::MoveModulesTo is for step 3.

The consumer should assert that there's no fetching modules.

Differential Revision: https://phabricator.services.mozilla.com/D199455
2024-02-14 02:01:37 +00:00
Tooru Fujisawa
5ae702d96e Bug 1803810 - Part 2: Make module loader overridable. r=jonco
In order to perform sync load in arbitrary global, add
ModuleLoaderBase::mOverriddenBy field, and let
ModuleLoaderBase::GetCurrentModuleLoader return the overridden loader,
so that the module loading can be overridden by SyncModuleLoader.

AutoOverrideModuleLoader manages the lifetime of the override.

Differential Revision: https://phabricator.services.mozilla.com/D199454
2024-02-14 02:01:36 +00:00
Cosmin Sabou
e4edda3c7e Backed out 10 changesets (bug 1803810) for xpcshell failures on test_import_global. CLOSED TREE
Backed out changeset d5df64b38425 (bug 1803810)
Backed out changeset b8f45cbb5596 (bug 1803810)
Backed out changeset c02d879622bd (bug 1803810)
Backed out changeset 9593275c0195 (bug 1803810)
Backed out changeset 2e2f01296233 (bug 1803810)
Backed out changeset 9699c18e5bf7 (bug 1803810)
Backed out changeset 84cdfd738db6 (bug 1803810)
Backed out changeset 58160b9119ef (bug 1803810)
Backed out changeset 4aa6e036fe7a (bug 1803810)
Backed out changeset 656b61cbd15c (bug 1803810)
2024-02-13 17:41:01 +02:00
Tooru Fujisawa
fe5f5aa268 Bug 1803810 - Part 4: Add mozJSModuleLoader for non-shared global. r=jonco
On the main thread, single mozJSModuleLoader instance is shared across all
loads in non-shared global, with resetting the internal state after importing
a module graph.

NonSharedGlobalSyncModuleLoaderScope manages the lifetime of each usage.
Import into the same non-shared global can be nested, but import into the
different non-shared gloobal is not allowed while other import for non-shared
global is ongoing.

Differential Revision: https://phabricator.services.mozilla.com/D199456
2024-02-13 14:34:22 +00:00
Tooru Fujisawa
e4bebfd949 Bug 1803810 - Part 3: Add methods to copy and move imported modules. r=jonco
In non-shared global, the sync load is performed by separate SyncModuleLoader,
with the following algorithm:
  1. copy all loaded modules from async module loader, so that they can be
     used in the module graph in SyncModuleLoader
  2. import a module graph
  3. move all modules to async module loader

ModuleLoaderBase::CopyModulesTo is for step 1, and
ModuleLoaderBase::MoveModulesTo is for step 3.

The consumer should assert that there's no fetching modules.

Differential Revision: https://phabricator.services.mozilla.com/D199455
2024-02-13 14:34:21 +00:00
Tooru Fujisawa
8dc876f29b Bug 1803810 - Part 2: Make module loader overridable. r=jonco
In order to perform sync load in arbitrary global, add
ModuleLoaderBase::mOverriddenBy field, and let
ModuleLoaderBase::GetCurrentModuleLoader return the overridden loader,
so that the module loading can be overridden by SyncModuleLoader.

AutoOverrideModuleLoader manages the lifetime of the override.

Differential Revision: https://phabricator.services.mozilla.com/D199454
2024-02-13 14:34:21 +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
Natalia Csoregi
68afaea1df Backed out changeset 67f13af428e3 (bug 1877703) for causing crashes and assertion failures on ModuleLoaderBase.cpp. CLOSED TREE 2024-02-02 23:17:41 +02:00
Yoshi Cheng-Hao Huang
80236c4ec3 Bug 1877703 - Don't add the URI into mFetchedModules if it has a parse error and is preloaded. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D200431
2024-02-02 17:42:32 +00:00
Tooru Fujisawa
4be2bb52e4 Bug 1875836 - Part 2: Support dynamic import in ComponentModuleLoader. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D199279
2024-01-23 23:29:53 +00:00
Matthew Gaudet
02a257be41 Bug 1835669 - Remove host hook r=dminor
Depends on D194256

Differential Revision: https://phabricator.services.mozilla.com/D194257
2024-01-19 01:01:30 +00:00
Jon Coppeard
f9febfda89 Bug 1871075 - Part 1: Store referencing private as a pointer to the underlying LoadedScript r=yulia
In Gecko we use a LoadedScript pointer as the referencing private for dynamic
imports. This is passed through the JS engine as a private value, which doesn't
care what it means. Currently we store this in the module loader as a JS::Value,
but we could just as well unpack it since we know what it is. That lets use a
RefPtr which also keeps it alive and will let use remove some manual reference
counting.

We also don't need to pass it to the CreateDynamicImport method twice.

This change makes it the responsibility of the module loader for keeping the
referencing private alive until FinishDynamicModuleImport is called.

Differential Revision: https://phabricator.services.mozilla.com/D196974
2023-12-21 13:30:34 +00:00
Tooru Fujisawa
e1306f14b6 Bug 1861309 - Part 1: Use 1-origin column number in JS::GetRequestedModuleSourcePos and ModuleLoaderBase::HandleResolveFailure. r=jonco
Depends on D192781

Differential Revision: https://phabricator.services.mozilla.com/D192782
2023-11-08 02:01:37 +00:00
Tooru Fujisawa
41cb19fe2a Bug 1847469 - Part 6: Use column number types in Module API. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D185744
2023-08-16 17:31:37 +00:00
Cristian Tuns
4fe9ed8f30 Backed out 27 changesets (bug 1847469) for causing spidermonkey bustages in Script.cpp CLOSED TREE
Backed out changeset 9d6e2651a013 (bug 1847469)
Backed out changeset 9b72d668efd2 (bug 1847469)
Backed out changeset 86abf5cf0a22 (bug 1847469)
Backed out changeset 46833087f8ac (bug 1847469)
Backed out changeset f3e2207fdeec (bug 1847469)
Backed out changeset aed75776cfff (bug 1847469)
Backed out changeset 8292a38bd99f (bug 1847469)
Backed out changeset 1320f83fb8c7 (bug 1847469)
Backed out changeset df9f925f9837 (bug 1847469)
Backed out changeset 69f32cf1862a (bug 1847469)
Backed out changeset b2ddddec8818 (bug 1847469)
Backed out changeset 056eed7abc97 (bug 1847469)
Backed out changeset 5df4f43ac0bf (bug 1847469)
Backed out changeset cb57923f6532 (bug 1847469)
Backed out changeset a0993f2a2195 (bug 1847469)
Backed out changeset 782499fbedf2 (bug 1847469)
Backed out changeset cf84fb98c5e1 (bug 1847469)
Backed out changeset 1fa5ab59814b (bug 1847469)
Backed out changeset f5f78944df81 (bug 1847469)
Backed out changeset aa14337bf5c6 (bug 1847469)
Backed out changeset 6757db4575d7 (bug 1847469)
Backed out changeset 236ff135701e (bug 1847469)
Backed out changeset 9b4d5b435020 (bug 1847469)
Backed out changeset a0f789621bc8 (bug 1847469)
Backed out changeset c19b81f48055 (bug 1847469)
Backed out changeset b4521e546d7e (bug 1847469)
Backed out changeset f26a10289316 (bug 1847469)
2023-08-16 07:08:01 -04:00
Tooru Fujisawa
475220dbaa Bug 1847469 - Part 6: Use column number types in Module API. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D185744
2023-08-16 10:26:28 +00:00
Tooru Fujisawa
441e14104a Bug 1846913 - Part 1: Use 1-origin column number for compile errors, compile wanring, and error notes. r=iain,devtools-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D185370
2023-08-11 08:11:48 +00:00
Jon Coppeard
19409077f2 Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r=smaug
According to the spec this should happen as the result of resolving a promise
(see ContinueDynamicImport). If this happens synchronously it's possible for
the importing module to still be in the evaluating state when trying to
instantiate and evaluate the dynamically imported module which breaks the
module loader invariants.

Differential Revision: https://phabricator.services.mozilla.com/D183876
2023-08-03 08:15:29 +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
Jon Coppeard
baca1b8e1f Bug 1842798 - Part 1: Remove use of MozPromise to wait for module fetch r=smaug
This replaces the promise with a list of module requests that are waiting for a
resource to be fetched. When the fetch completes the waiting requests are
resumed appropriately. This now happens immediately rather tha via dispatching
a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183272
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
b74ed7afeb Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r=smaug
According to the spec this should happen as the result of resolving a promise
(see ContinueDynamicImport). If this happens synchronously it's possible for
the importing module to still be in the evaluating state when trying to
instantiate and evaluate the dynamically imported module which breaks the
module loader invariants.

Differential Revision: https://phabricator.services.mozilla.com/D183876
2023-08-02 14:39:33 +00: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
Jon Coppeard
07468c5fe3 Bug 1842798 - Part 1: Remove use of MozPromise to wait for module fetch r=smaug
This replaces the promise with a list of module requests that are waiting for a
resource to be fetched. When the fetch completes the waiting requests are
resumed appropriately. This now happens immediately rather tha via dispatching
a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183272
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
dc4791f4d9 Bug 1842798 - Part 3: Complete dynamic imports asynchronously with a microtask r=smaug
According to the spec this should happen as the result of resolving a promise
(see ContinueDynamicImport). If this happens synchronously it's possible for
the importing module to still be in the evaluating state when trying to
instantiate and evaluate the dynamically imported module which breaks the
module loader invariants.

Differential Revision: https://phabricator.services.mozilla.com/D183876
2023-08-02 09:34:39 +00: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
Jon Coppeard
a71d4dc77c Bug 1842798 - Part 1: Remove use of MozPromise to wait for module fetch r=smaug
This replaces the promise with a list of module requests that are waiting for a
resource to be fetched. When the fetch completes the waiting requests are
resumed appropriately. This now happens immediately rather tha via dispatching
a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183272
2023-08-02 09:34:39 +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
Otto Länd
800336a01b Bug 1842798: apply code formatting via Lando
# ignore-this-changeset
2023-07-17 12:51:31 +00: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
Jon Coppeard
9a911aa85b Bug 1842798 - Part 1: Remove use of MozPromise to wait for module fetch r=smaug
This replaces the promise with a list of module requests that are waiting for a
resource to be fetched. When the fetch completes the waiting requests are
resumed appropriately. This now happens immediately rather tha via dispatching
a runnable.

Differential Revision: https://phabricator.services.mozilla.com/D183272
2023-07-17 12:44:18 +00:00
Jon Coppeard
71cd073308 Bug 1803984 - Part 2: 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-06-28 08:43:43 +00:00
Yoshi Cheng-Hao Huang
53e105ef77 Bug 1803984 - Part 1: Don't use the preloaded module request if there's an import map. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D178298
2023-06-28 08:43:42 +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
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
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