Bug 1958495: Add CancelFetchingModules for BETA. a=RyanVM

Apply the fix in https://phabricator.services.mozilla.com/D257677 to
BETA.

Original Revision: https://phabricator.services.mozilla.com/D260293

Differential Revision: https://phabricator.services.mozilla.com/D260572
This commit is contained in:
Yoshi Cheng-Hao Huang
2025-08-09 22:02:48 +00:00
committed by rvandermeulen@mozilla.com
parent 2ea89a3cf2
commit 2925957e93
3 changed files with 18 additions and 1 deletions

View File

@@ -1816,6 +1816,7 @@ void ScriptLoader::CancelAndClearScriptLoadRequests() {
mOffThreadCompilingRequests.CancelRequestsAndClear();
if (mModuleLoader) {
mModuleLoader->CancelFetchingModules();
mModuleLoader->CancelAndClearDynamicImports();
}

View File

@@ -683,7 +683,7 @@ nsresult ModuleLoaderBase::OnFetchComplete(ModuleLoadRequest* aRequest,
MOZ_ASSERT(NS_SUCCEEDED(rv) == bool(aRequest->mModuleScript));
SetModuleFetchFinishedAndResumeWaitingRequests(aRequest, rv);
if (!aRequest->IsErrored()) {
if (!aRequest->IsErrored() && !aRequest->IsCanceled()) {
StartFetchingModuleDependencies(aRequest);
}
@@ -1180,6 +1180,20 @@ ModuleLoaderBase::~ModuleLoaderBase() {
LOG(("ModuleLoaderBase::~ModuleLoaderBase %p", this));
}
void ModuleLoaderBase::CancelFetchingModules() {
for (const auto& entry : mFetchingModules) {
RefPtr<LoadingRequest> loadingRequest = entry.GetData();
loadingRequest->mRequest->Cancel();
for (const auto& request : loadingRequest->mWaiting) {
request->Cancel();
}
}
// We don't clear mFetchingModules here, as the fetching requests might arrive
// after the global is still shutting down.
}
void ModuleLoaderBase::Shutdown() {
CancelAndClearDynamicImports();

View File

@@ -290,6 +290,8 @@ class ModuleLoaderBase : public nsISupports {
explicit ModuleLoaderBase(ScriptLoaderInterface* aLoader,
nsIGlobalObject* aGlobalObject);
void CancelFetchingModules();
// Called to break cycles during shutdown to prevent memory leaks.
void Shutdown();