Commit Graph
275 Commits
Author SHA1 Message Date
Jon Coppeard 84fafeaa92 Bug 1968870 - Part 1: Pass referrer as script rather than object r=allstarschh
Previously we passed the module object for modules and nullptr for other cases.
This patch makes it so we pass the script for both module and classic script
referrers, and nullptr for the realm case.

Differential Revision: https://phabricator.services.mozilla.com/D260942
2025-08-14 06:35:28 +00:00
Jon Coppeard d7ab3e3d21 Bug 1982328 - Part 14: Remove ModuleLoadRequest::mDynamicPromise and use mPayload for this r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D260677
2025-08-13 14:17:18 +00:00
Jon Coppeard a6a27c7090 Bug 1982328 - Part 12: Rename ModuleLoadRequest::mStatePrivate to mPayload r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D260675
2025-08-13 14:17:10 +00:00
Jon Coppeard 5f0809ace8 Bug 1982328 - Part 11: Remove use of unnecessary JS namespace prefix in the module loader r=allstarschh
We're already in the JS namespace here so this is not necessary.

Differential Revision: https://phabricator.services.mozilla.com/D260674
2025-08-13 14:17:06 +00:00
Jon Coppeard e9414cdb53 Bug 1982328 - Part 10: Pass host defined value to HostLoadImportedModule r=allstarschh
Per the spec we should pass this to the module load hook. This means we can
remove JS::GetLoadingModuleHostDefinedValue.

Differential Revision: https://phabricator.services.mozilla.com/D260673
2025-08-13 14:17:02 +00:00
Jon Coppeard ac8506c5a8 Bug 1982328 - Part 9: Remove unused function in ModuleLoaderBase.cpp r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D260672
2025-08-13 14:16:58 +00:00
Jon Coppeard 2385d5c579 Bug 1982328 - Part 7: Tidy error handling for HostLoadImportedModule r=allstarschh
This makes it the responsibility of the JS engine to deal with failure if the
module load hook fails. It's more convenient for the embedding to have this
handled for you.

Differential Revision: https://phabricator.services.mozilla.com/D260670
2025-08-13 14:16:51 +00:00
Jon Coppeard 428c560074 Bug 1980126 - Part 10: Pass a single payload argument to HostLoadImportedModule callback r=allstarschh
Previously this passed separate statePrivate and promise arguments, only one of
which was used at a time.

Differential Revision: https://phabricator.services.mozilla.com/D259615
2025-08-05 09:02:44 +00:00
Jon Coppeard 6094f777fb Bug 1980126 - Part 7: Combine internal FinishLoadingImportedModule failure paths r=allstarschh
This makes it so FinishLoadingImportedModuleFailedWithPendingException gets the
current exception and calls FinishLoadingImportedModuleFailed.

Differential Revision: https://phabricator.services.mozilla.com/D259612
2025-08-05 09:02:33 +00:00
Jon Coppeard 484bfe7dbc Bug 1980126 - Part 6: Refactor error handling in module load hook implementation r=allstarschh
We use ScopeExit here to ensure we call FinishLoadingImportedModuleFailed on
error. However sometimes we call this directly and then exit without releasing
the guard and so call it again.

The patch cleans this up and makes the guard report the pending exception if
set but still report an exception otherwise. (In future we might think about
insisting that an exception is set if we leave early.)

Differential Revision: https://phabricator.services.mozilla.com/D259611
2025-08-05 09:02:30 +00:00
Jon Coppeard b1a2c70f85 Bug 1980126 - Part 5: Unify JS::FinishLoadingImportedModuleFailed APIs r=allstarschh
Similar to the previous patch, this makes the FinishLoadingImportedModuleFailed and
FinishLoadingImportedModuleFailedWithPendingException APIs take a single
payload argument.

Differential Revision: https://phabricator.services.mozilla.com/D259610
2025-08-05 09:02:26 +00:00
Jon Coppeard 3f057094f7 Bug 1980126 - Part 4: Unify JS::FinishLoadingImportedModule API r=allstarschh
This merges the two versions of FinishLoadingImportedModule so there's a single
API that takes a payload rather than separate ones for promise/statePrivate.

Differential Revision: https://phabricator.services.mozilla.com/D259609
2025-08-05 09:02:23 +00:00
Jon Coppeard 07264939b1 Bug 1980126 - Part 1: Make LoadModuleResolved/RejectedCallbacks into function pointers r=allstarschh
We usually use function pointers for callbacks into the JS engine.
These are simpler to deal with and also std::function can alocate memory in
some situations which is undesirable.

The patch converts these to function pointers and also refactors
ModuleLoaderBase.cpp where these are defined for the main module loader.

Differential Revision: https://phabricator.services.mozilla.com/D259606
2025-08-05 09:02:12 +00:00
Cristina Horotan 2270145ce0 Revert "Bug 1980126: apply code formatting via Lando" for causing wpt failures on before-prepare-iframe-success-external-module.html
This reverts commit 3e05c64268.

Revert "Bug 1980126 - Part 12: Tidy error handling in StartDynamicModuleImport r=allstarschh"

This reverts commit 8a67a2ece6.

Revert "Bug 1980126 - Part 11: Remove unused data from dynamic import context r=allstarschh"

This reverts commit e9878305e6.

Revert "Bug 1980126 - Part 10: Pass a single payload argument to HostLoadImportedModule callback r=allstarschh"

This reverts commit d90f9d6674.

Revert "Bug 1980126 - Part 9: Update test expectations r=allstarschh"

This reverts commit eee20ec5f4.

Revert "Bug 1980126 - Part 8: Add missing steps for FinishLoadingImportedModule for dynamic import r=allstarschh"

This reverts commit a904cdf9b8.

Revert "Bug 1980126 - Part 7: Combine internal FinishLoadingImportedModule failure paths r=allstarschh"

This reverts commit 1a80705381.

Revert "Bug 1980126 - Part 6: Refactor error handling in module load hook implementation r=allstarschh"

This reverts commit 47cd46fb6b.

Revert "Bug 1980126 - Part 5: Unify JS::FinishLoadingImportedModuleFailed APIs r=allstarschh"

This reverts commit dff70a55ad.

Revert "Bug 1980126 - Part 4: Unify JS::FinishLoadingImportedModule API r=allstarschh"

This reverts commit 8de76d7f72.

Revert "Bug 1980126 - Part 3: Move dynamic module code to vm/Modules.cpp from builtin/ModuleObject.cpp r=allstarschh"

This reverts commit e7d409880f.

Revert "Bug 1980126 - Part 2: Make GraphLoadingStateRecordObject background finalized and refactor r=allstarschh"

This reverts commit bec492ffcd.

Revert "Bug 1980126 - Part 1: Make LoadModuleResolved/RejectedCallbacks into function pointers r=allstarschh"

This reverts commit 20ca6df255.
2025-08-05 03:43:36 +00:00
Jon Coppeard d90f9d6674 Bug 1980126 - Part 10: Pass a single payload argument to HostLoadImportedModule callback r=allstarschh
Previously this passed separate statePrivate and promise arguments, only one of
which was used at a time.

Differential Revision: https://phabricator.services.mozilla.com/D259615
2025-08-04 07:27:56 +00:00
Jon Coppeard 1a80705381 Bug 1980126 - Part 7: Combine internal FinishLoadingImportedModule failure paths r=allstarschh
This makes it so FinishLoadingImportedModuleFailedWithPendingException gets the
current exception and calls FinishLoadingImportedModuleFailed.

Differential Revision: https://phabricator.services.mozilla.com/D259612
2025-08-04 07:27:46 +00:00
Jon Coppeard 47cd46fb6b Bug 1980126 - Part 6: Refactor error handling in module load hook implementation r=allstarschh
We use ScopeExit here to ensure we call FinishLoadingImportedModuleFailed on
error. However sometimes we call this directly and then exit without releasing
the guard and so call it again.

The patch cleans this up and makes the guard report the pending exception if
set but still report an exception otherwise. (In future we might think about
insisting that an exception is set if we leave early.)

Differential Revision: https://phabricator.services.mozilla.com/D259611
2025-08-04 07:27:42 +00:00
Jon Coppeard dff70a55ad Bug 1980126 - Part 5: Unify JS::FinishLoadingImportedModuleFailed APIs r=allstarschh
Similar to the previous patch, this makes the FinishLoadingImportedModuleFailed and
FinishLoadingImportedModuleFailedWithPendingException APIs take a single
payload argument.

Differential Revision: https://phabricator.services.mozilla.com/D259610
2025-08-04 07:27:39 +00:00
Jon Coppeard 8de76d7f72 Bug 1980126 - Part 4: Unify JS::FinishLoadingImportedModule API r=allstarschh
This merges the two versions of FinishLoadingImportedModule so there's a single
API that takes a payload rather than separate ones for promise/statePrivate.

Differential Revision: https://phabricator.services.mozilla.com/D259609
2025-08-04 07:27:35 +00:00
Jon Coppeard 20ca6df255 Bug 1980126 - Part 1: Make LoadModuleResolved/RejectedCallbacks into function pointers r=allstarschh
We usually use function pointers for callbacks into the JS engine.
These are simpler to deal with and also std::function can alocate memory in
some situations which is undesirable.

The patch converts these to function pointers and also refactors
ModuleLoaderBase.cpp where these are defined for the main module loader.

Differential Revision: https://phabricator.services.mozilla.com/D259606
2025-08-04 07:27:25 +00:00
Yoshi Cheng-Hao Huang a61af56c37 Bug 1820594 - Part 36: Add CancelFetchingModules. r=jonco
In mochitest-browser tests, it's possible for the about:neterror page to
load. This triggers aboutNetError.html, which in turn loads
aboutNetError.mjs, eventually importing pkijs.js. The pkijs.js module is
compiled off-thread.

However, when the test framework proceeds to the next test, the
associated document may be detached before the off-thread compilation of
pkijs.js completes. If this happens while TaskController is shutting
down, the compilation task may never finish.

Currently, ScriptLoader only tracks top-level off-thread compilation
requests, not submodules involved in those tasks. To address this, we
now call CancelFetchingModules when ScriptLoader cancels ongoing
requests, ensuring submodule fetches are also properly aborted.

Differential Revision: https://phabricator.services.mozilla.com/D257677
2025-07-22 18:30:00 +00:00
Yoshi Cheng-Hao Huang 264c8307be Bug 1820594 - Part 27: Remove redundant module graph data structures from host layer. r=jonco
Since the module graph is now traversed within the JS engine itself, the
related data structures in the host layer are no longer necessary.

Differential Revision: https://phabricator.services.mozilla.com/D255129
2025-07-22 18:29:34 +00:00
Yoshi Cheng-Hao Huang 4f92fa4f2d Bug 1820594 - Part 26: Remove FindFirstParseError and check for parse error. r=jonco
The changes in [whatwg/html#8253](https://github.com/whatwg/html/pull/8253)
remove the "Find the first parse error" part.

Differential Revision: https://phabricator.services.mozilla.com/D214579
2025-07-22 18:29:31 +00:00
Yoshi Cheng-Hao Huang 2464b45fe0 Bug 1820594 - Part 25: Call FinishLoadingImportedModule for dynamic import. r=jonco
From the specification, ContinueDynamicImport is done inside the engine.
https://tc39.es/ecma262/#sec-ContinueDynamicImport

However, our implementation for EvaluateModuleInContext() has bytecode
encoding related stuff, so for now I implement the ContinueDynamicImport
in the host layer.

Also, the updated spec has a slightly different error handling behavior when
module.Link() fails. I list them below:

Before HTML PR 8253 [https://github.com/whatwg/html/pull/8253]

fetch the descendants of and link a module script
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#fetch-the-descendants-of-and-link-a-module-script

onFetchDescendantsComplete
Step 3.2. Perform record.Link().
          If this throws an exception, set result's error to rethrow to that exception.

HostImportModuleDynamically
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)
Step 6.3 Otherwise, set promise to the result of running a module script given result and true.

run a module script
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#run-a-module-script
Step 5. If script's error to rethrow is not null, then set evaluationPromise to a promise rejected with script's error to rethrow.

--------------------------------------------------------
After ECMA262 PR 2905 [https://github.com/tc39/ecma262/pull/2905]
ContinueDynamicImport
Step 6.a Let link be Completion(module.Link()).
Step 6.b If link is an abrupt completion, then
  Step 6.b.i. Perform ! Call(promiseCapability.[[Reject]], undefined, « link.[[Value]] »).
  Step 6.b.ii. Return unused.

In short,
  * The old behavior:
    It catched the exception thrown during module.Link(), and set
    the module script's error to rethrow to the exception. Later in
    Evaluate(), if the module script's error to rethrow is not null,
    reject the evaluation promise with the error to rethrow.

  * The new behavior:
    It simply rejects the evaluation promise with the exception thrown
    during module.Link().

Differential Revision: https://phabricator.services.mozilla.com/D214577
2025-07-22 18:29:28 +00:00
Yoshi Cheng-Hao Huang 2d3841c2a0 Bug 1820594 - Part 24: Add ModuleErroredRunnable to dispatch ModuleErrored. r=jonco
When there's a ParseError, the error should be dispatched asynchronously.
However, workers can't handle the micro task, therefore we still call
ModuleErrored synchronously.

WPT test: /html/semantics/scripting-1/the-script-element/module/inline-async-inserted-execorder.html

Differential Revision: https://phabricator.services.mozilla.com/D255128
2025-07-22 18:29:25 +00:00
Yoshi Cheng-Hao Huang 33d4e771ca Bug 1820594 - Part 23: Error handling when module fetching failed. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228860
2025-07-22 18:29:22 +00:00
Yoshi Cheng-Hao Huang b4418fa96d Bug 1820594 - Part 22: Throw TypeError if the module type is unsupported. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D241812
2025-07-22 18:29:19 +00:00
Yoshi Cheng-Hao Huang 14ef8f5fdb Bug 1820594 - Part 21: Implement HostLoadImportedModule and FinishLoadingImportedModule in ModuleLoaderBase. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228856
2025-07-22 18:29:16 +00:00
Yoshi Cheng-Hao Huang cfaa6e7c06 Bug 1820594 - Part 20: Update module script's referrer policy. r=jonco
- Move UpdateReferrerPolicy from ScriptLoadRequest to ModuleLoadRequest,
  as this can only happend for a module load.

- Add UpdateReferrerPolicy method to ModuleScript.
  Introduces a new UpdateReferrerPolicy method for ModuleScript,
  allowing the referrer policy to be updated based on the associated
  ModuleLoadRequest.

Differential Revision: https://phabricator.services.mozilla.com/D255127
2025-07-22 18:29:13 +00:00
Yoshi Cheng-Hao Huang 745139e2c8 Bug 1820594 - Part 19: Refactor CreateStaticImport. r=jonco
Pass LoadContextBase to CreateStaticImport

Differential Revision: https://phabricator.services.mozilla.com/D255126
2025-07-22 18:29:10 +00:00
Yoshi Cheng-Hao Huang 2f395ffaf7 Bug 1820594 - Part 18: Add mReferrerObj, mModuleRequestObj, mReferencingPrivate, mStatePrivate in ModuleLoadRequest r=jonco
Add data structures to pass those information to
FinishLoadingImportedModule.

Differential Revision: https://phabricator.services.mozilla.com/D228852
2025-07-22 18:29:07 +00:00
Yoshi Cheng-Hao Huang 2a6b58d511 Bug 1820594 - Part 17: Add OnFetchSucceeded r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228853
2025-07-22 18:29:04 +00:00
Yoshi Cheng-Hao Huang a48f69ed79 Bug 1820594 - Part 16-1 : Use sync version of LoadRequestedModules for chrome pages. r=jonco
In mochitest-browser tests, it's possible for the about:neterror page to
load. This triggers aboutNetError.html, which in turn loads aboutNetError.mjs.
(The same situation also happens in devtools test when loading
json-viewer.mjs)

Occasionally, the load promise from LoadRequestedModules is never resolved
because the PromiseJobRunnable is not executed if the global is in the process
of shutting down.

To avoid this issue, we now use the synchronous version of
LoadRequestedModules when loading chrome resources.

Differential Revision: https://phabricator.services.mozilla.com/D257676
2025-07-22 18:29:01 +00:00
Yoshi Cheng-Hao Huang 5c786aae1f Bug 1820594 - Part 16: Call LoadRequestedModules in StartFetchingModuleDependencies. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D251142
2025-07-22 18:28:58 +00:00
Yoshi Cheng-Hao Huang a2b6839691 Bug 1820594 - Part 15: Remove HostResolveImportedModule and HostImportModuleDynamically r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228851
2025-07-22 18:28:55 +00:00
Yoshi Cheng-Hao Huang 00a8ab1fce Bug 1820594 - Part 14: Remove VisitedURLSet. r=jonco
Visited set has been removed from the spec.
See https://whatpr.org/html/8253/085d4d1...75e7bf0/webappapis.html

Differential Revision: https://phabricator.services.mozilla.com/D228850
2025-07-22 18:28:52 +00:00
Yoshi Cheng-Hao Huang e10ced86e9 Bug 1820594 - Part 13: Resume waiting requests after fetching dependencies. r=jonco
Process the ModuleLoadRequest itself first when it's fetched, then process the
waiting requests.

Differential Revision: https://phabricator.services.mozilla.com/D228849
2025-07-22 18:28:49 +00:00
Yoshi Cheng-Hao Huang 2662812a51 Bug 1820594 - Part 12: Implement ContinueDynamicImport. r=jonco
Implement https://tc39.es/ecma262/#sec-ContinueDynamicImport.

Differential Revision: https://phabricator.services.mozilla.com/D241811
2025-07-22 18:28:46 +00:00
Yoshi Cheng-Hao Huang a9c5e54942 Bug 1820594 - Part 5: Update Module Hook. r=jonco
Replace resolve hook and dynamic import hook with load hook.

Differential Revision: https://phabricator.services.mozilla.com/D214569
2025-07-22 18:28:25 +00:00
Atila Butkovits f46ece6f70 Revert "Bug 1820594 - Part 36: Add CancelFetchingModules. r=jonco" for causing failures at mochitest.toml.
This reverts commit bb9106dfec.

Revert "Bug 1820594 - Part 35: Disable testSyncImportWhileAsyncImportTLA. r=arai"

This reverts commit bd7ac6c6da.

Revert "Bug 1820594 - Part 34: Update wpt ini for dynamic import. r=jonco"

This reverts commit 6dc30859a2.

Revert "Bug 1820594 - Part 33: Update choice-of-error-1.html.ini and error-type-1.html.ini failed as expected. r=jonco"

This reverts commit 696d4051b2.

Revert "Bug 1820594 - Part 32: Remove js/src/jit-test/tests/modules/bug-1287410.js. r=jonco"

This reverts commit 6a47bd9a7c.

Revert "Bug 1820594 - Part 31: Test the child requests accross multiple module graphs. r=jonco"

This reverts commit fc403c5ea9.

Revert "Bug 1820594 - Part 30: Update JS Shell implementation for HostLoadImportedModule. r=jonco"

This reverts commit 5a2f281ba7.

Revert "Bug 1820594 - Part 29: Remove ModuleLoader::ResolveImportedModule and ModuleLoader::ImportModuleDynamically in JS Shell r=jonco"

This reverts commit aa686310fc.

Revert "Bug 1820594 - Part 28: DOM, Worker, Worklet ScriptLoader, mozJSModuleLoader update r=jonco"

This reverts commit 86aea74da6.

Revert "Bug 1820594 - Part 27: Remove redundant module graph data structures from host layer. r=jonco"

This reverts commit 81673cfb4e.

Revert "Bug 1820594 - Part 26: Remove FindFirstParseError and check for parse error. r=jonco"

This reverts commit 665970f847.

Revert "Bug 1820594 - Part 25: Call FinishLoadingImportedModule for dynamic import. r=jonco"

This reverts commit 9037595d27.

Revert "Bug 1820594 - Part 24: Add ModuleErroredRunnable to dispatch ModuleErrored. r=jonco"

This reverts commit aa0e96e6c1.

Revert "Bug 1820594 - Part 23: Error handling when module fetching failed. r=jonco"

This reverts commit 8054f6d6b3.

Revert "Bug 1820594 - Part 22: Throw TypeError if the module type is unsupported. r=jonco"

This reverts commit f793f2b086.

Revert "Bug 1820594 - Part 21: Implement HostLoadImportedModule and FinishLoadingImportedModule in ModuleLoaderBase. r=jonco"

This reverts commit 2c2abeb8a3.

Revert "Bug 1820594 - Part 20: Update module script's referrer policy. r=jonco"

This reverts commit e92cdaa129.

Revert "Bug 1820594 - Part 19: Refactor CreateStaticImport. r=jonco"

This reverts commit e7cc5dcf27.

Revert "Bug 1820594 - Part 18: Add mReferrerObj, mModuleRequestObj, mReferencingPrivate, mStatePrivate in ModuleLoadRequest r=jonco"

This reverts commit 96b553c522.

Revert "Bug 1820594 - Part 17: Add OnFetchSucceeded r=jonco"

This reverts commit 4b60b4037a.

Revert "Bug 1820594 - Part 16-1 : Use sync version of LoadRequestedModules for chrome pages. r=jonco"

This reverts commit a75c3d1989.

Revert "Bug 1820594 - Part 16: Call LoadRequestedModules in StartFetchingModuleDependencies. r=jonco"

This reverts commit cf9a4a886d.

Revert "Bug 1820594 - Part 15: Remove HostResolveImportedModule and HostImportModuleDynamically r=jonco"

This reverts commit 8c45c3380e.

Revert "Bug 1820594 - Part 14: Remove VisitedURLSet. r=jonco"

This reverts commit 09f1ea1a1a.

Revert "Bug 1820594 - Part 13: Resume waiting requests after fetching dependencies. r=jonco"

This reverts commit a5edee9705.

Revert "Bug 1820594 - Part 12: Implement ContinueDynamicImport. r=jonco"

This reverts commit b487d8ffec.

Revert "Bug 1820594 - Part 11: Implement LoadRequestedModules. r=jonco"

This reverts commit 0049bf82d1.

Revert "Bug 1820594 - Part 10: Implement ImportAttributes in InnerModuleLoading. r=jonco"

This reverts commit 3115d8a191.

Revert "Bug 1820594 - Part 9: Implement FinishLoadingImportedModule, ContinueModuleLoading. r=jonco"

This reverts commit 85bcdccef3.

Revert "Bug 1820594 - Part 8: Update js::FinishDynamicModuleImport. r=jonco"

This reverts commit f5546f06d2.

Revert "Bug 1820594 - Part 7: Remove JS::FinishDynamicModuleImport. r=jonco"

This reverts commit 1e6d8581b9.

Revert "Bug 1820594 - Part 6: Implement InnerModuleLoading. r=jonco"

This reverts commit ef4d03deaf.

Revert "Bug 1820594 - Part 5: Update Module Hook. r=jonco"

This reverts commit 4f00fb82af.

Revert "Bug 1820594 - Part 4: Implement GetImportedModule. r=jonco"

This reverts commit 19507524a2.

Revert "Bug 1820594 - Part 3: Implement LoadedModules in ModuleObject. r=jonco"

This reverts commit f639c7eb96.

Revert "Bug 1820594 - Part 2: Implement GraphLoadingStateRecord. r=jonco"

This reverts commit 05a2b76d9c.

Revert "Bug 1820594 - Part 1: Add ModuleStatus::New. r=jonco"

This reverts commit bfd2615ef1.
2025-07-22 01:03:15 +00:00
Yoshi Cheng-Hao Huang bb9106dfec Bug 1820594 - Part 36: Add CancelFetchingModules. r=jonco
In mochitest-browser tests, it's possible for the about:neterror page to
load. This triggers aboutNetError.html, which in turn loads
aboutNetError.mjs, eventually importing pkijs.js. The pkijs.js module is
compiled off-thread.

However, when the test framework proceeds to the next test, the
associated document may be detached before the off-thread compilation of
pkijs.js completes. If this happens while TaskController is shutting
down, the compilation task may never finish.

Currently, ScriptLoader only tracks top-level off-thread compilation
requests, not submodules involved in those tasks. To address this, we
now call CancelFetchingModules when ScriptLoader cancels ongoing
requests, ensuring submodule fetches are also properly aborted.

Differential Revision: https://phabricator.services.mozilla.com/D257677
2025-07-21 23:10:08 +00:00
Yoshi Cheng-Hao Huang 81673cfb4e Bug 1820594 - Part 27: Remove redundant module graph data structures from host layer. r=jonco
Since the module graph is now traversed within the JS engine itself, the
related data structures in the host layer are no longer necessary.

Differential Revision: https://phabricator.services.mozilla.com/D255129
2025-07-21 23:09:41 +00:00
Yoshi Cheng-Hao Huang 665970f847 Bug 1820594 - Part 26: Remove FindFirstParseError and check for parse error. r=jonco
The changes in [whatwg/html#8253](https://github.com/whatwg/html/pull/8253)
remove the "Find the first parse error" part.

Differential Revision: https://phabricator.services.mozilla.com/D214579
2025-07-21 23:09:38 +00:00
Yoshi Cheng-Hao Huang 9037595d27 Bug 1820594 - Part 25: Call FinishLoadingImportedModule for dynamic import. r=jonco
From the specification, ContinueDynamicImport is done inside the engine.
https://tc39.es/ecma262/#sec-ContinueDynamicImport

However, our implementation for EvaluateModuleInContext() has bytecode
encoding related stuff, so for now I implement the ContinueDynamicImport
in the host layer.

Also, the updated spec has a slightly different error handling behavior when
module.Link() fails. I list them below:

Before HTML PR 8253 [https://github.com/whatwg/html/pull/8253]

fetch the descendants of and link a module script
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#fetch-the-descendants-of-and-link-a-module-script

onFetchDescendantsComplete
Step 3.2. Perform record.Link().
          If this throws an exception, set result's error to rethrow to that exception.

HostImportModuleDynamically
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)
Step 6.3 Otherwise, set promise to the result of running a module script given result and true.

run a module script
https://web.archive.org/web/20221130023614/https://html.spec.whatwg.org/#run-a-module-script
Step 5. If script's error to rethrow is not null, then set evaluationPromise to a promise rejected with script's error to rethrow.

--------------------------------------------------------
After ECMA262 PR 2905 [https://github.com/tc39/ecma262/pull/2905]
ContinueDynamicImport
Step 6.a Let link be Completion(module.Link()).
Step 6.b If link is an abrupt completion, then
  Step 6.b.i. Perform ! Call(promiseCapability.[[Reject]], undefined, « link.[[Value]] »).
  Step 6.b.ii. Return unused.

In short,
  * The old behavior:
    It catched the exception thrown during module.Link(), and set
    the module script's error to rethrow to the exception. Later in
    Evaluate(), if the module script's error to rethrow is not null,
    reject the evaluation promise with the error to rethrow.

  * The new behavior:
    It simply rejects the evaluation promise with the exception thrown
    during module.Link().

Differential Revision: https://phabricator.services.mozilla.com/D214577
2025-07-21 23:09:35 +00:00
Yoshi Cheng-Hao Huang aa0e96e6c1 Bug 1820594 - Part 24: Add ModuleErroredRunnable to dispatch ModuleErrored. r=jonco
When there's a ParseError, the error should be dispatched asynchronously.
However, workers can't handle the micro task, therefore we still call
ModuleErrored synchronously.

WPT test: /html/semantics/scripting-1/the-script-element/module/inline-async-inserted-execorder.html

Differential Revision: https://phabricator.services.mozilla.com/D255128
2025-07-21 23:09:32 +00:00
Yoshi Cheng-Hao Huang 8054f6d6b3 Bug 1820594 - Part 23: Error handling when module fetching failed. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228860
2025-07-21 23:09:29 +00:00
Yoshi Cheng-Hao Huang f793f2b086 Bug 1820594 - Part 22: Throw TypeError if the module type is unsupported. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D241812
2025-07-21 23:09:26 +00:00
Yoshi Cheng-Hao Huang 2c2abeb8a3 Bug 1820594 - Part 21: Implement HostLoadImportedModule and FinishLoadingImportedModule in ModuleLoaderBase. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D228856
2025-07-21 23:09:23 +00:00
Yoshi Cheng-Hao Huang e92cdaa129 Bug 1820594 - Part 20: Update module script's referrer policy. r=jonco
- Move UpdateReferrerPolicy from ScriptLoadRequest to ModuleLoadRequest,
  as this can only happend for a module load.

- Add UpdateReferrerPolicy method to ModuleScript.
  Introduces a new UpdateReferrerPolicy method for ModuleScript,
  allowing the referrer policy to be updated based on the associated
  ModuleLoadRequest.

Differential Revision: https://phabricator.services.mozilla.com/D255127
2025-07-21 23:09:20 +00:00
Yoshi Cheng-Hao Huang e7cc5dcf27 Bug 1820594 - Part 19: Refactor CreateStaticImport. r=jonco
Pass LoadContextBase to CreateStaticImport

Differential Revision: https://phabricator.services.mozilla.com/D255126
2025-07-21 23:09:17 +00:00