summaryrefslogtreecommitdiffstats
path: root/dom/script/ScriptLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/script/ScriptLoader.cpp')
-rw-r--r--dom/script/ScriptLoader.cpp57
1 files changed, 24 insertions, 33 deletions
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;
}