From 07f63ad409f04dffa09809833c5caad5f48718a5 Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Mon, 25 May 2020 18:39:11 +0000 Subject: [PATCH] Bug 1637039 - Notify script preload when the loading channel synchronously fails to open, remove a used script preload from Document, r=hsivonen Differential Revision: https://phabricator.services.mozilla.com/D76364 --- dom/script/ScriptLoader.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index ba42c04d6987..6a8ce3a55e2e 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1497,15 +1497,23 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) { rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler); NS_ENSURE_SUCCESS(rv, rv); - rv = channel->AsyncOpen(loader); - NS_ENSURE_SUCCESS(rv, rv); - auto key = PreloadHashKey::CreateAsScript( aRequest->mURI, aRequest->CORSMode(), aRequest->mKind, aRequest->ReferrerPolicy()); aRequest->NotifyOpen(&key, channel, mDocument, aRequest->IsLinkPreloadScript()); + rv = channel->AsyncOpen(loader); + + if (NS_FAILED(rv)) { + // Make sure to inform any tags about failure to load the + // resource. + aRequest->NotifyStart(channel); + aRequest->NotifyStop(rv); + } + + NS_ENSURE_SUCCESS(rv, rv); + if (aRequest->IsModuleRequest()) { // We successfully started fetching a module so put its URL in the module // map and mark it as fetching. @@ -1966,6 +1974,10 @@ ScriptLoadRequest* ScriptLoader::LookupPreloadRequest( // This makes sure the pending preload (if exists) for this resource is // properly marked as used and thus not notified in the console as unused. request->NotifyUsage(); + // A used preload must no longer be found in the Document's hash table. Any + // tag after the