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
This commit is contained in:
@@ -478,6 +478,23 @@ void ModuleLoaderBase::SetModuleFetchStarted(ModuleLoadRequest* aRequest) {
|
||||
mFetchingModules.InsertOrUpdate(aRequest->mURI, nullptr);
|
||||
}
|
||||
|
||||
bool ModuleLoaderBase::IsScriptPreloadedAndHasParseError(
|
||||
ModuleLoadRequest* aRequest) {
|
||||
RefPtr<ModuleScript> moduleScript(aRequest->mModuleScript);
|
||||
|
||||
bool hasParseError = false;
|
||||
if (moduleScript) {
|
||||
hasParseError = moduleScript->HasParseError();
|
||||
}
|
||||
|
||||
bool isPreload = false;
|
||||
if (aRequest->HasScriptLoadContext()) {
|
||||
isPreload = aRequest->GetScriptLoadContext()->IsPreload();
|
||||
}
|
||||
|
||||
return hasParseError && isPreload;
|
||||
}
|
||||
|
||||
void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
||||
ModuleLoadRequest* aRequest, nsresult aResult) {
|
||||
// Update module map with the result of fetching a single module script.
|
||||
@@ -505,7 +522,14 @@ void ModuleLoaderBase::SetModuleFetchFinishedAndResumeWaitingRequests(
|
||||
RefPtr<ModuleScript> moduleScript(aRequest->mModuleScript);
|
||||
MOZ_ASSERT(NS_FAILED(aResult) == !moduleScript);
|
||||
|
||||
mFetchedModules.InsertOrUpdate(aRequest->mURI, RefPtr{moduleScript});
|
||||
// In the case an import map is inserted dynamically, the preloaded module
|
||||
// scripts might fail to resolve the import specifiers and hence get parse
|
||||
// errors. In that case, we don't put the URI of the preloaded module script
|
||||
// into mFetchedModules map, and ScriptLoader will fetch the module script
|
||||
// again.
|
||||
if (!IsScriptPreloadedAndHasParseError(aRequest)) {
|
||||
mFetchedModules.InsertOrUpdate(aRequest->mURI, RefPtr{moduleScript});
|
||||
}
|
||||
|
||||
if (waitingRequests) {
|
||||
LOG(("ScriptLoadRequest (%p): Resuming waiting requests", aRequest));
|
||||
|
||||
Reference in New Issue
Block a user