From 834ecdc59a084d0ccafa17ccc0e4801115935295 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Sat, 22 Aug 2020 10:13:37 +0000 Subject: Issue #618 - Handle errors for inline module scripts and ensure we update the module map after fetch errors. --- dom/script/ScriptLoader.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'dom/script/ScriptLoader.cpp') diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index c94966169..1ee50ccfc 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -486,8 +486,6 @@ ScriptLoader::ProcessFetchedModuleSource(ModuleLoadRequest* aRequest) nsresult rv = CreateModuleScript(aRequest); MOZ_ASSERT(NS_FAILED(rv) == !aRequest->mModuleScript); - SetModuleFetchFinishedAndResumeWaitingRequests(aRequest, rv); - free(aRequest->mScriptTextBuf); aRequest->mScriptTextBuf = nullptr; aRequest->mScriptTextLength = 0; @@ -497,6 +495,10 @@ ScriptLoader::ProcessFetchedModuleSource(ModuleLoadRequest* aRequest) return rv; } + if (!aRequest->mIsInline) { + SetModuleFetchFinishedAndResumeWaitingRequests(aRequest, rv); + } + if (!aRequest->mModuleScript->HasParseError()) { StartFetchingModuleDependencies(aRequest); } @@ -1457,20 +1459,19 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) if (request->IsModuleRequest()) { ModuleLoadRequest* modReq = request->AsModuleRequest(); modReq->mBaseURL = mDocument->GetDocBaseURI(); - rv = CreateModuleScript(modReq); - MOZ_ASSERT(NS_FAILED(rv) == !modReq->mModuleScript); - if (NS_FAILED(rv)) { - modReq->LoadFailed(); - return false; - } + if (aElement->GetScriptAsync()) { - mLoadingAsyncRequests.AppendElement(request); + modReq->mIsAsync = true; + mLoadingAsyncRequests.AppendElement(modReq); } else { - AddDeferRequest(request); + AddDeferRequest(modReq); } - if (!modReq->mModuleScript->HasParseError()) { - StartFetchingModuleDependencies(modReq); + + nsresult rv = ProcessFetchedModuleSource(modReq); + if (NS_FAILED(rv)) { + HandleLoadError(modReq, rv); } + return false; } request->mProgress = ScriptLoadRequest::Progress::Ready; @@ -2324,6 +2325,11 @@ ScriptLoader::HandleLoadError(ScriptLoadRequest *aRequest, nsresult aResult) { mDocument->AddBlockedTrackingNode(cont); } + if (aRequest->IsModuleRequest() && !aRequest->mIsInline) { + auto request = aRequest->AsModuleRequest(); + SetModuleFetchFinishedAndResumeWaitingRequests(request, aResult); + } + if (aRequest->mIsDefer) { MOZ_ASSERT_IF(aRequest->IsModuleRequest(), aRequest->AsModuleRequest()->IsTopLevel()); -- cgit v1.2.3