commit 11169efd0e7b407efee6f84fd6f718985d224d30
parent e47be3d3764b0242afca27539d758311c5d486d5
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Thu, 23 Oct 2025 04:16:56 +0000
Bug 1992341 - Part 3: Assert or clear the disk-cache-related info in CalculateCacheFlag. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D269520
Diffstat:
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -2692,6 +2692,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
LOG(("ScriptLoadRequest (%p): Bytecode-cache: Skip all: IsBytecode",
aRequest));
aRequest->MarkSkippedAllCaching();
+ MOZ_ASSERT(!aRequest->getLoadedScript()->HasDiskCacheReference());
return;
}
@@ -2700,6 +2701,8 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
LOG(("ScriptLoadRequest (%p): Bytecode-cache: Skip all: JSON module",
aRequest));
aRequest->MarkSkippedAllCaching();
+ MOZ_ASSERT(!aRequest->getLoadedScript()->HasDiskCacheReference());
+ MOZ_ASSERT_IF(aRequest->IsSource(), aRequest->SRIAndBytecode().empty());
return;
}
@@ -2727,6 +2730,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
"!LoadedScript::HasDiskCacheReference",
aRequest));
aRequest->MarkSkippedDiskCaching();
+ MOZ_ASSERT_IF(aRequest->IsSource(), aRequest->SRIAndBytecode().empty());
return;
}
@@ -2750,6 +2754,8 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
"pref.",
aRequest));
aRequest->MarkSkippedDiskCaching();
+
+ aRequest->getLoadedScript()->DropDiskCacheReferenceAndSRI();
return;
}
case -1: {
@@ -2798,6 +2804,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
"small.",
aRequest));
aRequest->MarkSkippedDiskCaching();
+ aRequest->getLoadedScript()->DropDiskCacheReferenceAndSRI();
return;
}
}
@@ -2818,6 +2825,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
"fetchCount.",
aRequest));
aRequest->MarkSkippedDiskCaching();
+ aRequest->getLoadedScript()->DropDiskCacheReferenceAndSRI();
return;
}
}
@@ -2827,6 +2835,20 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) {
LOG(("ScriptLoadRequest (%p): Bytecode-cache: Skip disk: fetchCount",
aRequest));
aRequest->MarkSkippedDiskCaching();
+
+ if (!mCache) {
+ // If in-memory cache is not enabled, the disk cache reference
+ // and the SRI data is necessary only when the current request
+ // reaches the minimum fetch count. And they can be discarded here
+ // if the fetch count is less than the minimum.
+ //
+ // If in-memory cache is enabled, the disk cache reference and the
+ // SRI data is cached with the LoadedScript, and the LoadedScript
+ // is reused by the subsequent requests, and the fetch count
+ // can reach the minimum later. We need to keep the disk cache
+ // reference and the SRI data until then.
+ aRequest->getLoadedScript()->DropDiskCacheReferenceAndSRI();
+ }
return;
}
}
diff --git a/js/loader/LoadedScript.h b/js/loader/LoadedScript.h
@@ -252,6 +252,11 @@ class LoadedScript : public nsIMemoryReporter {
mSRIAndBytecode.clearAndFree();
}
+ void DropSRI() {
+ MOZ_ASSERT(IsSource() || IsCachedStencil());
+ mSRIAndBytecode.clearAndFree();
+ }
+
bool HasStencil() const { return mStencil; }
Stencil* GetStencil() const {
@@ -275,6 +280,13 @@ class LoadedScript : public nsIMemoryReporter {
// Drop the reference to the cache info channel.
void DropDiskCacheReference() { mCacheInfo = nullptr; }
+ void DropDiskCacheReferenceAndSRI() {
+ DropDiskCacheReference();
+ if (IsSource()) {
+ DropSRI();
+ }
+ }
+
/*
* Set the mBaseURL, based on aChannel.
* aOriginalURI is the result of aChannel->GetOriginalURI.