tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 1257f9e671118460579b981196eee71de00ea5cc
parent d778f470cc27db023c4429fa1de1d3565c8cda98
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Thu, 16 Oct 2025 09:03:22 +0000

Bug 1991081 - Part 1: Rename Stencil variant to CachedStencil in LoadedScript. r=nbp

Differential Revision: https://phabricator.services.mozilla.com/D266610

Diffstat:
Mdom/script/ModuleLoader.cpp | 4++--
Mdom/script/ScriptLoader.cpp | 25+++++++++++++------------
Mjs/loader/LoadedScript.cpp | 8++++----
Mjs/loader/LoadedScript.h | 23++++++++++++++---------
Mjs/loader/ModuleLoaderBase.cpp | 8++++----
5 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/dom/script/ModuleLoader.cpp b/dom/script/ModuleLoader.cpp @@ -95,7 +95,7 @@ bool ModuleLoader::CanStartLoad(ModuleLoadRequest* aRequest, nsresult* aRvOut) { } nsresult ModuleLoader::StartFetch(ModuleLoadRequest* aRequest) { - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { GetScriptLoader()->EmulateNetworkEvents(aRequest); SetModuleFetchStarted(aRequest); return aRequest->OnFetchComplete(NS_OK); @@ -235,7 +235,7 @@ nsresult ModuleLoader::CompileJavaScriptModule( JS::MutableHandle<JSObject*> aModuleOut) { GetScriptLoader()->CalculateCacheFlag(aRequest); - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { JS::InstantiateOptions instantiateOptions(aOptions); RefPtr<JS::Stencil> stencil = aRequest->GetStencil(); aModuleOut.set( diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -636,7 +636,7 @@ static nsSecurityFlags CORSModeToSecurityFlags(CORSMode aCORSMode) { nsresult ScriptLoader::StartClassicLoad( ScriptLoadRequest* aRequest, const Maybe<nsAutoString>& aCharsetForPreload) { - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { EmulateNetworkEvents(aRequest); return NS_OK; } @@ -1205,7 +1205,7 @@ void ScriptLoader::StoreCacheInfo(LoadedScript* aLoadedScript, } void ScriptLoader::EmulateNetworkEvents(ScriptLoadRequest* aRequest) { - MOZ_ASSERT(aRequest->IsStencil()); + MOZ_ASSERT(aRequest->IsCachedStencil()); MOZ_ASSERT(aRequest->mNetworkMetadata); nsIScriptElement* element = aRequest->GetScriptLoadContext()->mScriptElement; @@ -1430,7 +1430,7 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement, return block; } - if (request->IsStencil()) { + if (request->IsCachedStencil()) { // https://html.spec.whatwg.org/#prepare-the-script-element // // Step 33. If el's type is "classic" and el has a src attribute, or el's @@ -1881,7 +1881,7 @@ nsresult ScriptLoader::CompileOffThreadOrProcessRequest( NS_ASSERTION(nsContentUtils::IsSafeToRunScript(), "Processing requests when running scripts is unsafe."); - if (!aRequest->IsStencil() && + if (!aRequest->IsCachedStencil() && !aRequest->GetScriptLoadContext()->mCompileOrDecodeTask && !aRequest->GetScriptLoadContext()->CompileStarted()) { bool couldCompile = false; @@ -2741,7 +2741,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) { // We need the nsICacheInfoChannel to exist to be able to open the alternate // data output stream. - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { // For in-memory cache, the pointer is cached in the LoadedScript, // if the cache had never been saved. if (!aRequest->getLoadedScript()->mCacheInfo) { @@ -2820,7 +2820,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) { if (hasSourceLengthMin) { size_t sourceLength; size_t minLength; - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { sourceLength = JS::GetScriptSourceLength(aRequest->GetStencil()); } else { MOZ_ASSERT(aRequest->IsTextSource()); @@ -2842,7 +2842,7 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) { // are going to be dropped soon. if (hasFetchCountMin) { uint32_t fetchCount = 0; - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { fetchCount = aRequest->mLoadedScript->mFetchCount; } else { if (NS_FAILED( @@ -3214,7 +3214,7 @@ void ScriptLoader::InstantiateClassicScriptFromAny( ScriptLoadRequest* aRequest, JS::MutableHandle<JSScript*> aScript, JS::Handle<JS::Value> aDebuggerPrivateValue, JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) { - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { RefPtr<JS::Stencil> stencil = aRequest->GetStencil(); InstantiateClassicScriptFromCachedStencil( aCx, aCompileOptions, aRequest, stencil, aScript, aDebuggerPrivateValue, @@ -3293,7 +3293,7 @@ void ScriptLoader::TryCacheRequest(ScriptLoadRequest* aRequest, cacheBehavior = CacheBehavior::Evict; } - aRequest->SetStencil(aStencil.forget()); + aRequest->SetCachedStencil(aStencil.forget()); if (cacheBehavior == CacheBehavior::Insert) { auto loadData = MakeRefPtr<ScriptLoadData>(this, aRequest); @@ -3343,7 +3343,7 @@ nsresult ScriptLoader::MaybePrepareForCacheAfterExecute( // NOTE: This assertion will fail once we start encoding more data after the // first encode. MOZ_ASSERT_IF( - !aRequest->IsStencil(), + !aRequest->IsCachedStencil(), aRequest->GetSRILength() == aRequest->SRIAndBytecode().length()); RegisterForCache(aRequest); @@ -3438,7 +3438,7 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject, } #endif - if (aRequest->IsStencil()) { + if (aRequest->IsCachedStencil()) { #ifdef DEBUG // A request with cache might not have mBaseURL. if (aRequest->mBaseURL) { @@ -3640,7 +3640,8 @@ void ScriptLoader::UpdateCache() { stencil = FinishCollectingDelazifications(aes.cx(), request); if (mCache) { if (stencil) { - MOZ_ASSERT_IF(request->IsStencil(), stencil == request->GetStencil()); + MOZ_ASSERT_IF(request->IsCachedStencil(), + stencil == request->GetStencil()); // The bytecode encoding is performed only when there was no // bytecode stored in the necko cache. diff --git a/js/loader/LoadedScript.cpp b/js/loader/LoadedScript.cpp @@ -49,7 +49,7 @@ LoadedScript::LoadedScript(ScriptKind aKind, } LoadedScript::LoadedScript(const LoadedScript& aOther) - : mDataType(DataType::eStencil), + : mDataType(DataType::eCachedStencil), mKind(aOther.mKind), mReferrerPolicy(aOther.mReferrerPolicy), mBytecodeOffset(0), @@ -62,7 +62,7 @@ LoadedScript::LoadedScript(const LoadedScript& aOther) MOZ_ASSERT(mURI); // NOTE: This is only for the stencil case. // The script text and the bytecode are not reflected. - MOZ_DIAGNOSTIC_ASSERT(aOther.mDataType == DataType::eStencil); + MOZ_DIAGNOSTIC_ASSERT(aOther.mDataType == DataType::eCachedStencil); MOZ_DIAGNOSTIC_ASSERT(mStencil); MOZ_ASSERT(!mScriptData); MOZ_ASSERT(mScriptBytecode.empty()); @@ -291,13 +291,13 @@ ModuleScript::ModuleScript(const LoadedScript& aOther) : LoadedScript(aOther) { already_AddRefed<ModuleScript> ModuleScript::FromCache( const LoadedScript& aScript) { MOZ_DIAGNOSTIC_ASSERT(aScript.IsModuleScript()); - MOZ_DIAGNOSTIC_ASSERT(aScript.IsStencil()); + MOZ_DIAGNOSTIC_ASSERT(aScript.IsCachedStencil()); return mozilla::MakeRefPtr<ModuleScript>(aScript).forget(); } already_AddRefed<LoadedScript> ModuleScript::ToCache() { - MOZ_DIAGNOSTIC_ASSERT(IsStencil()); + MOZ_DIAGNOSTIC_ASSERT(IsCachedStencil()); MOZ_DIAGNOSTIC_ASSERT(!HasParseError()); MOZ_DIAGNOSTIC_ASSERT(!HasErrorToRethrow()); diff --git a/js/loader/LoadedScript.h b/js/loader/LoadedScript.h @@ -117,7 +117,12 @@ class LoadedScript : public nsIMemoryReporter { // Type of data this instance holds, which is either provided by the nsChannel // or retrieved from the cache. - enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode, eStencil }; + enum class DataType : uint8_t { + eUnknown, + eTextSource, + eBytecode, + eCachedStencil + }; // Use a vector backed by the JS allocator for script text so that contents // can be transferred in constant time to the JS engine, not copied in linear @@ -132,7 +137,7 @@ class LoadedScript : public nsIMemoryReporter { bool IsTextSource() const { return mDataType == DataType::eTextSource; } bool IsSource() const { return IsTextSource(); } bool IsBytecode() const { return mDataType == DataType::eBytecode; } - bool IsStencil() const { return mDataType == DataType::eStencil; } + bool IsCachedStencil() const { return mDataType == DataType::eCachedStencil; } void SetUnknownDataType() { mDataType = DataType::eUnknown; @@ -150,9 +155,9 @@ class LoadedScript : public nsIMemoryReporter { mDataType = DataType::eBytecode; } - void SetStencil(already_AddRefed<Stencil> aStencil) { + void SetCachedStencil(already_AddRefed<Stencil> aStencil) { SetUnknownDataType(); - mDataType = DataType::eStencil; + mDataType = DataType::eCachedStencil; mStencil = aStencil; } @@ -204,7 +209,7 @@ class LoadedScript : public nsIMemoryReporter { } bool CanHaveBytecode() const { - return IsBytecode() || IsSource() || IsStencil(); + return IsBytecode() || IsSource() || IsCachedStencil(); } TranscodeBuffer& SRIAndBytecode() { @@ -237,7 +242,7 @@ class LoadedScript : public nsIMemoryReporter { } Stencil* GetStencil() const { - MOZ_ASSERT(IsStencil()); + MOZ_ASSERT(IsCachedStencil()); return mStencil; } @@ -322,7 +327,7 @@ class LoadedScriptDelegate { bool IsTextSource() const { return GetLoadedScript()->IsTextSource(); } bool IsSource() const { return GetLoadedScript()->IsSource(); } bool IsBytecode() const { return GetLoadedScript()->IsBytecode(); } - bool IsStencil() const { return GetLoadedScript()->IsStencil(); } + bool IsCachedStencil() const { return GetLoadedScript()->IsCachedStencil(); } void SetUnknownDataType() { GetLoadedScript()->SetUnknownDataType(); } @@ -332,8 +337,8 @@ class LoadedScriptDelegate { void SetBytecode() { GetLoadedScript()->SetBytecode(); } - void SetStencil(already_AddRefed<Stencil> aStencil) { - GetLoadedScript()->SetStencil(std::move(aStencil)); + void SetCachedStencil(already_AddRefed<Stencil> aStencil) { + GetLoadedScript()->SetCachedStencil(std::move(aStencil)); } bool IsUTF16Text() const { return GetLoadedScript()->IsUTF16Text(); } diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp @@ -543,11 +543,11 @@ nsresult ModuleLoaderBase::StartOrRestartModuleLoad(ModuleLoadRequest* aRequest, // NOTE: The LoadedScript::mDataType field used by the IsStencil call can be // modified asynchronously after the StartFetch call. // In order to avoid the race condition, cache the value here. - bool isStencil = aRequest->IsStencil(); + bool isCachedStencil = aRequest->IsCachedStencil(); - MOZ_ASSERT_IF(isStencil, aRestart == RestartRequest::No); + MOZ_ASSERT_IF(isCachedStencil, aRestart == RestartRequest::No); - if (!isStencil) { + if (!isCachedStencil) { aRequest->SetUnknownDataType(); } @@ -582,7 +582,7 @@ nsresult ModuleLoaderBase::StartOrRestartModuleLoad(ModuleLoadRequest* aRequest, rv = StartFetch(aRequest); NS_ENSURE_SUCCESS(rv, rv); - if (isStencil) { + if (isCachedStencil) { MOZ_ASSERT( IsModuleFetched(ModuleMapKey(aRequest->mURI, aRequest->mModuleType))); return NS_OK;