Commit graph

166 commits

Author SHA1 Message Date
Tooru Fujisawa
7533056300 Bug 1880708 - Handle CC unlink when destroying ScriptLoader/ModuleLoader. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D202080
2024-02-19 15:09:00 +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
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
Gregory Pappas
e3f2c5ad80 Bug 1853547 - Remove dom.importMaps.enabled pref r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D197751
2024-01-06 01:53:19 +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
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
Jon Coppeard
9ec5953695 Bug 1865410 - Part 2: Removed unused module APIs following previous patch r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D194767
2023-12-02 08:49:59 +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
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
Tooru Fujisawa
ce72fea4a7 Bug 1846194 - Remove off-thread compilation and decode API. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D185125
2023-09-01 03:43:21 +00:00
Tooru Fujisawa
70c40a1658 Bug 1845638 - Part 1: Use JS::FrontendContext APIs and TaskController in compilation and decode in ScriptLoader. r=smaug,bthrall
Differential Revision: https://phabricator.services.mozilla.com/D184896
2023-08-29 12:07:18 +00:00
Tooru Fujisawa
b23c224e33 Bug 1847469 - Part 20: Use column number types in JSErrorBase. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D185758
2023-08-16 17:31:40 +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
ee81f946a2 Bug 1847469 - Part 20: Use column number types in JSErrorBase. r=iain
Differential Revision: https://phabricator.services.mozilla.com/D185758
2023-08-16 10:26:32 +00: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
970aa448a4 Bug 1847813 - Process loaded modules asynchronously in DOM module loader r=smaug
Based on the explanation on the bug, the solution would seem to be to call the
ModuleLoaderBase::OnModuleLoadComplete hook from a microtask. This causes a ton
of test failures.

Instead this patch changes the DOM script loader to implement this hook with a
runnable. This fixes the problem (verified manually) and all tests pass.

(Replacing the runnable with a microtask just in the DOM script loader also
does not work and results in many test failures. I'm still trying to understand
why.)

The changes to ContinueDynamicImport are removed because they are also on this
path and we don't need a microtask as well.

This takes us closer to the state before bug 1842798 landed when all the module
loader used MozPromise internally and completions like this happened via
runnables.

I was not able to immediately come up with a test for this.

Differential Revision: https://phabricator.services.mozilla.com/D185830
2023-08-09 22:49:46 +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
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
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