commit e47be3d3764b0242afca27539d758311c5d486d5
parent 793840c062418aea8105375bb9f7be4721d47d01
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Thu, 23 Oct 2025 04:16:55 +0000
Bug 1992341 - Part 2: Calculate the SRI hash only when the disk cache reference exists. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D269519
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -3975,6 +3975,9 @@ nsresult ScriptLoader::OnStreamComplete(
nsresult rv = VerifySRI(aRequest, aLoader, aSRIStatus, aSRIDataVerifier);
if (NS_SUCCEEDED(rv)) {
+ // If we are loading from source, store the cache info channel and
+ // save the computed SRI hash or a dummy SRI hash in case we are going to
+ // save the bytecode of this script in the cache.
if (aRequest->IsSource() &&
StaticPrefs::dom_script_loader_bytecode_cache_enabled()) {
nsCOMPtr<nsIRequest> channelRequest;
@@ -3984,13 +3987,11 @@ nsresult ScriptLoader::OnStreamComplete(
do_QueryInterface(channelRequest);
LOG(("ScriptLoadRequest (%p): nsICacheInfoChannel = %p", aRequest,
aRequest->getLoadedScript()->mCacheInfo.get()));
- }
- // If we are loading from source, save the computed SRI hash or a dummy SRI
- // hash in case we are going to save the bytecode of this script in the
- // cache.
- if (aRequest->IsSource()) {
- rv = SaveSRIHash(aRequest, aSRIDataVerifier);
+ // We need the SRI hash only when the channel has cache info.
+ if (aRequest->getLoadedScript()->mCacheInfo) {
+ rv = SaveSRIHash(aRequest, aSRIDataVerifier);
+ }
}
if (NS_SUCCEEDED(rv)) {