diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /dom/script | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/script')
-rw-r--r-- | dom/script/ScriptLoadContext.h | 2 | ||||
-rw-r--r-- | dom/script/ScriptLoader.cpp | 57 | ||||
-rw-r--r-- | dom/script/ScriptLoader.h | 3 |
3 files changed, 26 insertions, 36 deletions
diff --git a/dom/script/ScriptLoadContext.h b/dom/script/ScriptLoadContext.h index 74f7c6fe4f..d32553c4d4 100644 --- a/dom/script/ScriptLoadContext.h +++ b/dom/script/ScriptLoadContext.h @@ -147,7 +147,7 @@ class ScriptLoadContext : public JS::loader::LoadContextBase, static void PrioritizeAsPreload(nsIChannel* aChannel); - bool IsPreload() const; + bool IsPreload() const override; bool CompileStarted() const; diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 4fa08e074d..5297a11f4a 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1097,19 +1097,6 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, return false; } - if (request && request->IsModuleRequest() && - mModuleLoader->HasImportMapRegistered() && - request->mState > ScriptLoadRequest::State::Compiling) { - // We don't preload module scripts after seeing an import map but a script - // can dynamically insert an import map after preloading has happened. - // - // In the case of an import map is inserted after preloading has happened, - // We also check if the request has started loading imports, if not then we - // can reuse the preloaded request. - request->Cancel(); - request = nullptr; - } - if (request) { // Use the preload request. @@ -1399,6 +1386,16 @@ bool ScriptLoader::ProcessInlineScript(nsIScriptElement* aElement, return false; } + // Remove any module preloads. Module specifier resolution is invalidated by + // adding an import map, and incorrect dependencies may have been loaded. + mPreloads.RemoveElementsBy([](const PreloadInfo& info) { + if (info.mRequest->IsModuleRequest()) { + info.mRequest->Cancel(); + return true; + } + return false; + }); + // TODO: Bug 1781758: Move RegisterImportMap into EvaluateScriptElement. // // https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-element @@ -3297,21 +3294,7 @@ nsresult ScriptLoader::OnStreamComplete( // hash in case we are going to save the bytecode of this script in the // cache. if (aRequest->IsSource()) { - uint32_t sriLength = 0; - rv = SaveSRIHash(aRequest, aSRIDataVerifier, &sriLength); - JS::TranscodeBuffer& bytecode = aRequest->SRIAndBytecode(); - MOZ_ASSERT_IF(NS_SUCCEEDED(rv), bytecode.length() == sriLength); - - // TODO: (Bug 1800896) This code should be moved into SaveSRIHash, and the - // SRI out-param can be removed. - aRequest->SetSRILength(sriLength); - if (aRequest->GetSRILength() != sriLength) { - // The bytecode is aligned in the bytecode buffer, and space might be - // reserved for padding after the SRI hash. - if (!bytecode.resize(aRequest->GetSRILength())) { - return NS_ERROR_OUT_OF_MEMORY; - } - } + rv = SaveSRIHash(aRequest, aSRIDataVerifier); } if (NS_SUCCEEDED(rv)) { @@ -3373,14 +3356,13 @@ nsresult ScriptLoader::VerifySRI(ScriptLoadRequest* aRequest, return rv; } -nsresult ScriptLoader::SaveSRIHash(ScriptLoadRequest* aRequest, - SRICheckDataVerifier* aSRIDataVerifier, - uint32_t* sriLength) const { +nsresult ScriptLoader::SaveSRIHash( + ScriptLoadRequest* aRequest, SRICheckDataVerifier* aSRIDataVerifier) const { MOZ_ASSERT(aRequest->IsSource()); JS::TranscodeBuffer& bytecode = aRequest->SRIAndBytecode(); MOZ_ASSERT(bytecode.empty()); - uint32_t len; + uint32_t len = 0; // If the integrity metadata does not correspond to a valid hash function, // IsComplete would be false. @@ -3418,7 +3400,16 @@ nsresult ScriptLoader::SaveSRIHash(ScriptLoadRequest* aRequest, SRICheckDataVerifier::DataSummaryLength(len, bytecode.begin(), &srilen))); MOZ_ASSERT(srilen == len); - *sriLength = len; + MOZ_ASSERT(bytecode.length() == len); + aRequest->SetSRILength(len); + + if (aRequest->GetSRILength() != len) { + // The bytecode is aligned in the bytecode buffer, and space might be + // reserved for padding after the SRI hash. + if (!bytecode.resize(aRequest->GetSRILength())) { + return NS_ERROR_OUT_OF_MEMORY; + } + } return NS_OK; } diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h index bdfd64b024..2fa5721d8c 100644 --- a/dom/script/ScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -566,8 +566,7 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { SRICheckDataVerifier* aSRIDataVerifier) const; nsresult SaveSRIHash(ScriptLoadRequest* aRequest, - SRICheckDataVerifier* aSRIDataVerifier, - uint32_t* sriLength) const; + SRICheckDataVerifier* aSRIDataVerifier) const; void ReportErrorToConsole(ScriptLoadRequest* aRequest, nsresult aResult) const override; |