tor-browser

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

commit 58730279e1f1346b898e5c95c301e237e188d49d
parent 927e82fdf7c052d95890f97f747a1ecb6d3b56cf
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed, 26 Nov 2025 04:10:50 +0000

Bug 1907011 - Part 1: Rename bytecode to serialized stencil in LoadedScript DataType. r=nbp

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

Diffstat:
Mdom/script/ModuleLoader.cpp | 2+-
Mdom/script/ScriptLoadHandler.cpp | 10+++++-----
Mdom/script/ScriptLoader.cpp | 18++++++++++--------
Mjs/loader/LoadedScript.h | 26+++++++++++++++-----------
4 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/dom/script/ModuleLoader.cpp b/dom/script/ModuleLoader.cpp @@ -300,7 +300,7 @@ nsresult ModuleLoader::CompileJavaScriptModule( }; stencil = maybeSource.mapNonEmpty(compile); } else { - MOZ_ASSERT(aRequest->IsBytecode()); + MOZ_ASSERT(aRequest->IsSerializedStencil()); JS::DecodeOptions decodeOptions(aOptions); decodeOptions.borrowBuffer = true; diff --git a/dom/script/ScriptLoadHandler.cpp b/dom/script/ScriptLoadHandler.cpp @@ -165,7 +165,7 @@ ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader, NS_ENSURE_SUCCESS(rv, rv); } - if (mRequest->IsBytecode() && firstTime) { + if (mRequest->IsSerializedStencil() && firstTime) { PerfStats::RecordMeasurementStart(PerfStats::Metric::JSBC_IO_Read); } @@ -189,7 +189,7 @@ ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader, mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); } } else { - MOZ_ASSERT(mRequest->IsBytecode()); + MOZ_ASSERT(mRequest->IsSerializedStencil()); if (!mRequest->SRIAndBytecode().append(aData, aDataLength)) { return NS_ERROR_OUT_OF_MEMORY; } @@ -344,7 +344,7 @@ nsresult ScriptLoadHandler::EnsureKnownDataType( nsAutoCString altDataType; cic->GetAlternativeDataType(altDataType); if (altDataType.Equals(ScriptLoader::BytecodeMimeTypeFor(mRequest))) { - mRequest->SetBytecode(); + mRequest->SetSerializedStencil(); TRACE_FOR_TEST(mRequest, "load:diskcache"); return NS_OK; } @@ -399,7 +399,7 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, NS_ENSURE_SUCCESS(rv, rv); } - if (mRequest->IsBytecode() && !firstMessage) { + if (mRequest->IsSerializedStencil() && !firstMessage) { // if firstMessage, then entire stream is in aData, and PerfStats would // measure 0 time PerfStats::RecordMeasurementEnd(PerfStats::Metric::JSBC_IO_Read); @@ -421,7 +421,7 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader, mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); } } else { - MOZ_ASSERT(mRequest->IsBytecode()); + MOZ_ASSERT(mRequest->IsSerializedStencil()); JS::TranscodeBuffer& bytecode = mRequest->SRIAndBytecode(); if (!bytecode.append(aData, aDataLength)) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -378,7 +378,7 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) { } else { if (aRequest->IsTextSource()) { script_loading_source.EnumGet(ScriptLoadingSourceLabel::eSource).Add(); - } else if (aRequest->IsBytecode()) { + } else if (aRequest->IsSerializedStencil()) { script_loading_source.EnumGet(ScriptLoadingSourceLabel::eAltdata).Add(); } } @@ -1978,7 +1978,7 @@ class OffThreadCompilationCompleteTask : public Task { if (mRequest->IsTextSource()) { scriptSourceString = "ScriptCompileOffThread"; } else { - MOZ_ASSERT(mRequest->IsBytecode()); + MOZ_ASSERT(mRequest->IsSerializedStencil()); scriptSourceString = "BytecodeDecodeOffThread"; } @@ -2080,7 +2080,7 @@ nsresult ScriptLoader::AttemptOffThreadScriptCompile( return NS_OK; } } else { - MOZ_ASSERT(aRequest->IsBytecode()); + MOZ_ASSERT(aRequest->IsSerializedStencil()); JS::TranscodeRange bytecode = aRequest->Bytecode(); if (!StaticPrefs::javascript_options_parallel_parsing() || @@ -2336,7 +2336,7 @@ class ScriptDecodeTask final : public CompileOrDecodeTask { nsresult ScriptLoader::CreateOffThreadTask( JSContext* aCx, ScriptLoadRequest* aRequest, JS::CompileOptions& aOptions, CompileOrDecodeTask** aCompileOrDecodeTask) { - if (aRequest->IsBytecode()) { + if (aRequest->IsSerializedStencil()) { JS::TranscodeRange bytecode = aRequest->Bytecode(); JS::DecodeOptions decodeOptions(aOptions); RefPtr<ScriptDecodeTask> decodeTask = new ScriptDecodeTask(bytecode); @@ -2534,7 +2534,7 @@ nsresult ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest) { // Free any source data, but keep the bytecode content as we might have to // save it later. aRequest->ClearScriptSource(); - if (aRequest->IsBytecode()) { + if (aRequest->IsSerializedStencil()) { // We received bytecode as input, thus we were decoding, and we will not be // encoding the bytecode once more. We can safely clear the content of this // buffer. @@ -2806,8 +2806,10 @@ void ScriptLoader::CalculateCacheFlag(ScriptLoadRequest* aRequest) { // The following conditions apply only to the disk cache. - if (aRequest->IsBytecode()) { - LOG(("ScriptLoadRequest (%p): Bytecode-cache: Skip disk: IsBytecode", + if (aRequest->IsSerializedStencil()) { + LOG( + ("ScriptLoadRequest (%p): Bytecode-cache: Skip disk: " + "IsSerializedStencil", aRequest)); aRequest->MarkSkippedDiskCaching(); MOZ_ASSERT(!aRequest->getLoadedScript()->HasDiskCacheReference()); @@ -3124,7 +3126,7 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource( CalculateCacheFlag(aRequest); - if (aRequest->IsBytecode()) { + if (aRequest->IsSerializedStencil()) { if (aRequest->GetScriptLoadContext()->mCompileOrDecodeTask) { LOG(("ScriptLoadRequest (%p): Decode Bytecode & instantiate and Execute", aRequest)); diff --git a/js/loader/LoadedScript.h b/js/loader/LoadedScript.h @@ -124,10 +124,10 @@ class LoadedScript : public nsIMemoryReporter { // mSRIAndBytecode holds the SRI. eTextSource, - // This script is received as a bytecode from the channel. - // mSRIAndBytecode holds the SRI and the bytecode, and mStencil holds the - // decoded stencil. - eBytecode, + // This script is received as a serialized stencil from the channel, + // mSRIAndBytecode holds the SRI and the serialized stencil, and mStencil + // holds the decoded stencil. + eSerializedStencil, // This script is cached from the previous load. // mStencil holds the cached stencil, and mSRIAndBytecode holds the SRI. @@ -147,7 +147,9 @@ class LoadedScript : public nsIMemoryReporter { bool IsUnknownDataType() const { return mDataType == DataType::eUnknown; } bool IsTextSource() const { return mDataType == DataType::eTextSource; } bool IsSource() const { return IsTextSource(); } - bool IsBytecode() const { return mDataType == DataType::eBytecode; } + bool IsSerializedStencil() const { + return mDataType == DataType::eSerializedStencil; + } bool IsCachedStencil() const { return mDataType == DataType::eCachedStencil; } void SetUnknownDataType() { @@ -161,9 +163,9 @@ class LoadedScript : public nsIMemoryReporter { mScriptData.emplace(VariantType<ScriptTextBuffer<Utf8Unit>>()); } - void SetBytecode() { + void SetSerializedStencil() { MOZ_ASSERT(IsUnknownDataType()); - mDataType = DataType::eBytecode; + mDataType = DataType::eSerializedStencil; } void ConvertToCachedStencil() { @@ -220,7 +222,7 @@ class LoadedScript : public nsIMemoryReporter { } bool CanHaveBytecode() const { - return IsBytecode() || IsSource() || IsCachedStencil(); + return IsSerializedStencil() || IsSource() || IsCachedStencil(); } TranscodeBuffer& SRIAndBytecode() { @@ -231,7 +233,7 @@ class LoadedScript : public nsIMemoryReporter { return mSRIAndBytecode; } TranscodeRange Bytecode() const { - MOZ_ASSERT(IsBytecode()); + MOZ_ASSERT(IsSerializedStencil()); const auto& bytecode = mSRIAndBytecode; auto offset = mBytecodeOffset; return TranscodeRange(bytecode.begin() + offset, @@ -467,7 +469,9 @@ class LoadedScriptDelegate { } bool IsTextSource() const { return GetLoadedScript()->IsTextSource(); } bool IsSource() const { return GetLoadedScript()->IsSource(); } - bool IsBytecode() const { return GetLoadedScript()->IsBytecode(); } + bool IsSerializedStencil() const { + return GetLoadedScript()->IsSerializedStencil(); + } bool IsCachedStencil() const { return GetLoadedScript()->IsCachedStencil(); } void SetUnknownDataType() { GetLoadedScript()->SetUnknownDataType(); } @@ -476,7 +480,7 @@ class LoadedScriptDelegate { GetLoadedScript()->SetTextSource(maybeLoadContext); } - void SetBytecode() { GetLoadedScript()->SetBytecode(); } + void SetSerializedStencil() { GetLoadedScript()->SetSerializedStencil(); } void ConvertToCachedStencil() { GetLoadedScript()->ConvertToCachedStencil(); }