Bug 1956163 - ScriptLoader now reports child module load failures as coming from the parent module. r=arai

When a child module fails to load, the parent module that requested it is now used as the source location for the error message.

Differential Revision: https://phabricator.services.mozilla.com/D242884
This commit is contained in:
DavidJCobb
2025-03-26 10:20:14 +00:00
parent e0c011f7e4
commit 6022e96f95
7 changed files with 109 additions and 10 deletions

View File

@@ -4027,11 +4027,25 @@ void ScriptLoader::ReportErrorToConsole(ScriptLoadRequest* aRequest,
JS::ColumnNumberOneOrigin columnNo =
aRequest->GetScriptLoadContext()->GetScriptColumnNumber();
SourceLocation loc{mDocument->GetDocumentURI(), lineNo,
columnNo.oneOriginValue()};
// If this is a failed module load, and we know the parent module, then
// attribute the failure to the parent module, not the overall document.
if (aRequest->IsModuleRequest()) {
ModuleLoadRequest* modRequest = aRequest->AsModuleRequest();
if (!modRequest->IsTopLevel()) {
ModuleLoadRequest* parent = modRequest->mWaitingParentRequest;
if (parent) {
nsCString parentURL = parent->mURL;
loc = SourceLocation(std::move(parentURL));
}
}
}
nsContentUtils::ReportToConsole(
nsIScriptError::warningFlag, "Script Loader"_ns, mDocument,
nsContentUtils::eDOM_PROPERTIES, message, params,
SourceLocation{mDocument->GetDocumentURI(), lineNo,
columnNo.oneOriginValue()});
nsContentUtils::eDOM_PROPERTIES, message, params, loc);
}
void ScriptLoader::ReportWarningToConsole(