tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 8714caa9e3eb91b49a47fb3b5d383b8b0b442a8e
parent 1e5ddf19cf0db6b398dee93fb260d31ba821e373
Author: Yoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Date:   Fri,  3 Oct 2025 20:53:29 +0000

Bug 1968890 - Part 6: ScriptLoaders update. r=jonco,dom-worker-reviewers,edenchuang

OnFetchComplete will do the error handling and update the state, so we
don't need to call Cancel nor LoadFailed.

Also, ModuleErrored() will call ModuleLoader::OnModuleLoadComplete,
which will move the request to Loaded requests, so we also need to
update HandLoadError as well.

Differential Revision: https://phabricator.services.mozilla.com/D264808

Diffstat:
Mdom/script/ScriptLoader.cpp | 40++++++++++++++++++----------------------
Mdom/workers/ScriptLoader.cpp | 10+---------
Mdom/worklet/WorkletFetchHandler.cpp | 9---------
3 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -4241,26 +4241,35 @@ void ScriptLoader::HandleLoadError(ScriptLoadRequest* aRequest, mDocument->AddBlockedNodeByClassifier(cont); } + bool wasHandled = false; + + // A ModuleLoadRequest will be stored either in mDeferRequests or + // mLoadingAsyncRequests, but the onerror handler should be triggered later in + // ProcessRequests, so we handle ModuleLoadRequest before mDeferRequestrs and + // mLoadingAsyncRequests. if (aRequest->IsModuleRequest()) { MOZ_ASSERT(!aRequest->GetScriptLoadContext()->mIsInline); - aRequest->AsModuleRequest()->OnFetchComplete(aResult); - } + wasHandled = true; + + ModuleLoadRequest* modReq = aRequest->AsModuleRequest(); + modReq->OnFetchComplete(aResult); - if (aRequest->GetScriptLoadContext()->mInDeferList) { - MOZ_ASSERT_IF(aRequest->IsModuleRequest(), - aRequest->AsModuleRequest()->IsTopLevel()); + MOZ_ASSERT(modReq->IsErrored()); + } else if (aRequest->GetScriptLoadContext()->mInDeferList) { + wasHandled = true; if (aRequest->isInList()) { RefPtr<ScriptLoadRequest> req = mDeferRequests.Steal(aRequest); FireScriptAvailable(aResult, req); } } else if (aRequest->GetScriptLoadContext()->mInAsyncList) { - MOZ_ASSERT_IF(aRequest->IsModuleRequest(), - aRequest->AsModuleRequest()->IsTopLevel()); + wasHandled = true; if (aRequest->isInList()) { RefPtr<ScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest); FireScriptAvailable(aResult, req); } - } else if (aRequest->GetScriptLoadContext()->mIsNonAsyncScriptInserted) { + } + + if (aRequest->GetScriptLoadContext()->mIsNonAsyncScriptInserted) { if (aRequest->isInList()) { RefPtr<ScriptLoadRequest> req = mNonAsyncExternalScriptInsertedRequests.Steal(aRequest); @@ -4272,25 +4281,12 @@ void ScriptLoader::HandleLoadError(ScriptLoadRequest* aRequest, FireScriptAvailable(aResult, req); } } else if (aRequest->GetScriptLoadContext()->IsPreload()) { - if (aRequest->IsModuleRequest()) { - aRequest->Cancel(); - } if (aRequest->IsTopLevel()) { // Request may already have been removed by // CancelAndClearScriptLoadRequests. mPreloads.RemoveElement(aRequest, PreloadRequestComparator()); } MOZ_ASSERT(!aRequest->isInList()); - } else if (aRequest->IsModuleRequest()) { - ModuleLoadRequest* modReq = aRequest->AsModuleRequest(); - if (modReq->IsDynamicImport()) { - if (aRequest->isInList()) { - modReq->CancelDynamicImport(aResult); - } - } else { - MOZ_ASSERT(!modReq->isInList()); - modReq->Cancel(); - } } else if (mParserBlockingRequest == aRequest) { MOZ_ASSERT(!aRequest->isInList()); mParserBlockingRequest = nullptr; @@ -4307,7 +4303,7 @@ void ScriptLoader::HandleLoadError(ScriptLoadRequest* aRequest, FireScriptAvailable(aResult, aRequest); ContinueParserAsync(aRequest); mCurrentParserInsertedScript = oldParserInsertedScript; - } else { + } else if (!wasHandled) { // This happens for blocking requests cancelled by ParsingComplete(). // Ignore cancellation status for link-preload requests, as cancellation can // be omitted for them when SRI is stronger on consumer tags. diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp @@ -1730,16 +1730,8 @@ bool ScriptExecutorRunnable::ProcessModuleScript( moduleRequest->OnFetchComplete(loadContext->mLoadResult); if (NS_FAILED(loadContext->mLoadResult)) { - if (moduleRequest->IsDynamicImport()) { - if (request->isInList()) { - moduleRequest->CancelDynamicImport(loadContext->mLoadResult); - mScriptLoader->TryShutdown(); - } - } else if (!moduleRequest->IsTopLevel()) { - moduleRequest->Cancel(); + if (moduleRequest->IsDynamicImport() || !moduleRequest->IsTopLevel()) { mScriptLoader->TryShutdown(); - } else { - moduleRequest->LoadFailed(); } } return true; diff --git a/dom/worklet/WorkletFetchHandler.cpp b/dom/worklet/WorkletFetchHandler.cpp @@ -220,15 +220,6 @@ NS_IMETHODIMP FetchCompleteRunnable::RunOnWorkletThread() { request->mBaseURL = mURI; request->OnFetchComplete(mResult); - - if (NS_FAILED(mResult)) { - if (request->IsTopLevel()) { - request->LoadFailed(); - } else { - request->Cancel(); - } - } - moduleLoader->RemoveRequest(mURI); return NS_OK; }