commit 1e5ddf19cf0db6b398dee93fb260d31ba821e373
parent 548979d573fa441933336de030904b2463bbe101
Author: Yoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Date: Fri, 3 Oct 2025 20:53:29 +0000
Bug 1968890 - Part 5: Add ModuleLoadRequest::SetErroredLoadingImports(). r=jonco
To indicate the loading error for a top-level of the module from the dynamic import
is successfully fetched and parsed, but one of its dependencies fails to fetch
or compile.
//Example
import("a.mjs");
// a.mjs
import "./404.mjs";
This patch allows the ModuleLoadRequest::IsErrored() for "a.mjs" returns
true.
Differential Revision: https://phabricator.services.mozilla.com/D264807
Diffstat:
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/js/loader/ModuleLoadRequest.cpp b/js/loader/ModuleLoadRequest.cpp
@@ -55,6 +55,7 @@ ModuleLoadRequest::ModuleLoadRequest(
aFetchOptions, aIntegrity, aReferrer, aContext),
mKind(aKind),
mModuleType(aModuleType),
+ mErroredLoadingImports(false),
mLoader(aLoader),
mRootModule(aRootModule) {
MOZ_ASSERT(mLoader);
@@ -73,7 +74,12 @@ nsIGlobalObject* ModuleLoadRequest::GetGlobalObject() {
}
bool ModuleLoadRequest::IsErrored() const {
- return !mModuleScript || mModuleScript->HasParseError();
+ if (!mModuleScript || mErroredLoadingImports) {
+ return true;
+ }
+
+ MOZ_ASSERT_IF(mModuleScript->HasErrorToRethrow(), !IsDynamicImport());
+ return mModuleScript->HasParseError() || mModuleScript->HasErrorToRethrow();
}
void ModuleLoadRequest::Cancel() {
@@ -144,13 +150,7 @@ void ModuleLoadRequest::ModuleErrored() {
}
MOZ_ASSERT(!IsFinished());
-
- mozilla::DebugOnly<bool> hasRethrow =
- mModuleScript && mModuleScript->HasErrorToRethrow();
-
- // When LoadRequestedModules fails, we will set error to rethrow to the module
- // script and call ModuleErrored().
- MOZ_ASSERT(IsErrored() || hasRethrow);
+ MOZ_ASSERT(IsErrored());
if (IsFinished()) {
// Cancelling an outstanding import will error this request.
diff --git a/js/loader/ModuleLoadRequest.h b/js/loader/ModuleLoadRequest.h
@@ -113,9 +113,19 @@ class ModuleLoadRequest final : public ScriptLoadRequest {
const Kind mKind;
+ void SetErroredLoadingImports() {
+ MOZ_ASSERT(IsDynamicImport());
+ MOZ_ASSERT(IsFetching());
+ mErroredLoadingImports = true;
+ }
+
// Type of module (JavaScript, JSON)
const ModuleType mModuleType;
+ // A flag (for dynamic import) that indicates the module script is
+ // successfully fetched and compiled, but its dependencies are failed to load.
+ bool mErroredLoadingImports;
+
// Pointer to the script loader, used to trigger actions when the module load
// finishes.
RefPtr<ModuleLoaderBase> mLoader;
diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp
@@ -1325,6 +1325,7 @@ bool ModuleLoaderBase::OnLoadRequestedModulesRejected(
JSMSG_DYNAMIC_IMPORT_FAILED, url.get());
FinishLoadingImportedModuleFailedWithPendingException(aCx, payload);
}
+ aRequest->SetErroredLoadingImports();
} else if (moduleScript && !error.isUndefined()) {
LOG(
("ScriptLoadRequest (%p): LoadRequestedModules rejected: set error to "