tor-browser

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

commit 32c285e820a9af61686af64a34dd250ccec08da0
parent d26b0876c94ee1d266304563731c43ba9853e721
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Thu, 23 Oct 2025 04:16:56 +0000

Bug 1992341 - Part 6: Update the method names and comments. r=nbp

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

Diffstat:
Mdom/script/ScriptLoader.cpp | 34+++++++++++++++++-----------------
Mdom/script/ScriptLoader.h | 31++++++++++++-------------------
Mjs/loader/ModuleLoaderBase.cpp | 4++--
Mjs/loader/ModuleLoaderBase.h | 7++-----
4 files changed, 33 insertions(+), 43 deletions(-)

diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -205,7 +205,7 @@ ScriptLoader::ScriptLoader(Document* aDocument) mDeferCheckpointReached(false), mBlockingDOMContentLoaded(false), mLoadEventFired(false), - mGiveUpCaching(false), + mGiveUpDiskCaching(false), mContinueParsingDocumentAfterCurrentScript(false), mReporter(new ConsoleReportCollector()) { LOG(("ScriptLoader::ScriptLoader %p", this)); @@ -3333,7 +3333,7 @@ nsCString& ScriptLoader::BytecodeMimeTypeFor( return nsContentUtils::JSScriptBytecodeMimeType(); } -nsresult ScriptLoader::MaybePrepareForCacheAfterExecute( +nsresult ScriptLoader::MaybePrepareForDiskCacheAfterExecute( ScriptLoadRequest* aRequest, nsresult aRv) { if (!aRequest->PassedConditionForDiskCache() || !aRequest->HasStencil()) { LOG(("ScriptLoadRequest (%p): Bytecode-cache: disabled (rv = %X)", aRequest, @@ -3366,7 +3366,7 @@ nsresult ScriptLoader::MaybePrepareForCacheAfterExecute( return aRv; } -nsresult ScriptLoader::MaybePrepareModuleForCacheAfterExecute( +nsresult ScriptLoader::MaybePrepareModuleForDiskCacheAfterExecute( ModuleLoadRequest* aRequest, nsresult aRv) { MOZ_ASSERT(aRequest->IsTopLevel()); @@ -3380,7 +3380,7 @@ nsresult ScriptLoader::MaybePrepareModuleForCacheAfterExecute( return aRv; } - aRv = MaybePrepareForCacheAfterExecute(aRequest, aRv); + aRv = MaybePrepareForDiskCacheAfterExecute(aRequest, aRv); for (auto* r = mDiskCacheableDependencyModules.getFirst(); r;) { auto* dep = r->AsModuleRequest(); @@ -3394,7 +3394,7 @@ nsresult ScriptLoader::MaybePrepareModuleForCacheAfterExecute( mDiskCacheableDependencyModules.Remove(dep); - aRv = MaybePrepareForCacheAfterExecute(dep, aRv); + aRv = MaybePrepareForDiskCacheAfterExecute(dep, aRv); } return aRv; @@ -3473,13 +3473,13 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject, // This must be called also for compilation failure case, in order to // dispatch test-only event. - rv = MaybePrepareForCacheAfterExecute(aRequest, rv); + rv = MaybePrepareForDiskCacheAfterExecute(aRequest, rv); // Even if we are not saving the bytecode of the current script, we have // to trigger the encoding of the bytecode, as the current script can // call functions of a script for which we are recording the bytecode. LOG(("ScriptLoadRequest (%p): ScriptLoader = %p", aRequest, this)); - MaybeUpdateCache(); + MaybeUpdateDiskCache(); return rv; } @@ -3504,7 +3504,7 @@ void ScriptLoader::RegisterForDiskCache(ScriptLoadRequest* aRequest) { void ScriptLoader::LoadEventFired() { mLoadEventFired = true; - MaybeUpdateCache(); + MaybeUpdateDiskCache(); } void ScriptLoader::Destroy() { @@ -3514,15 +3514,15 @@ void ScriptLoader::Destroy() { } CancelAndClearScriptLoadRequests(); - GiveUpCaching(); + GiveUpDiskCaching(); } -void ScriptLoader::MaybeUpdateCache() { +void ScriptLoader::MaybeUpdateDiskCache() { // If we already gave up, ensure that we are not going to enqueue any script, // and that we finalize them properly. - if (mGiveUpCaching) { + if (mGiveUpDiskCaching) { LOG(("ScriptLoader (%p): Keep giving-up bytecode encoding.", this)); - GiveUpCaching(); + GiveUpDiskCaching(); return; } @@ -3553,17 +3553,17 @@ void ScriptLoader::MaybeUpdateCache() { // all enqueued scripts when the document is idle. In case of failure, we // give-up on encoding the bytecode. nsCOMPtr<nsIRunnable> encoder = NewRunnableMethod( - "ScriptLoader::UpdateCache", this, &ScriptLoader::UpdateCache); + "ScriptLoader::UpdateCache", this, &ScriptLoader::UpdateDiskCache); if (NS_FAILED(NS_DispatchToCurrentThreadQueue(encoder.forget(), EventQueuePriority::Idle))) { - GiveUpCaching(); + GiveUpDiskCaching(); return; } LOG(("ScriptLoader (%p): Schedule bytecode encoding.", this)); } -void ScriptLoader::UpdateCache() { +void ScriptLoader::UpdateDiskCache() { LOG(("ScriptLoader (%p): Start bytecode encoding.", this)); // If any script got added in the previous loop cycle, wait until all @@ -3685,10 +3685,10 @@ void ScriptLoader::EncodeBytecodeAndSave( MOZ_RELEASE_ASSERT(compressedBytecode.length() == n); } -void ScriptLoader::GiveUpCaching() { +void ScriptLoader::GiveUpDiskCaching() { // If the document went away prematurely, we still want to set this, in order // to avoid queuing more scripts. - mGiveUpCaching = true; + mGiveUpDiskCaching = true; while (!mDiskCacheQueue.isEmpty()) { RefPtr<ScriptLoadRequest> request = mDiskCacheQueue.StealFirst(); diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h @@ -717,15 +717,15 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { // cleanup the script load request fields otherwise. // // This method must be called after executing the script. - nsresult MaybePrepareForCacheAfterExecute(ScriptLoadRequest* aRequest, - nsresult aRv); + nsresult MaybePrepareForDiskCacheAfterExecute(ScriptLoadRequest* aRequest, + nsresult aRv); // Queue the top-level module load request for caching if we decided to cache // it, or cleanup the module load request fields otherwise. // // This method must be called after executing the script. - nsresult MaybePrepareModuleForCacheAfterExecute(ModuleLoadRequest* aRequest, - nsresult aRv) override; + nsresult MaybePrepareModuleForDiskCacheAfterExecute( + ModuleLoadRequest* aRequest, nsresult aRv) override; // Implements https://html.spec.whatwg.org/#run-a-classic-script nsresult EvaluateScript(nsIGlobalObject* aGlobalObject, @@ -746,19 +746,14 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { /** * Check if all conditions are met, i-e that the onLoad event fired and that * no more script have to be processed. If all conditions are met, queue an - * event to perform the cache handling, which does: - * - finish collecting the delazifications - * - optionally save to the necko cache + * event to perform the cache handling, which saves them to the necko cache. */ - void MaybeUpdateCache() override; + void MaybeUpdateDiskCache() override; /** - * Iterate over all script load request and perform the caching operations, - * which is: - * - finish collecting delazifications - * - encode and save it to the necko cache + * Iterate over all scripts and save them to the necko cache. */ - void UpdateCache(); + void UpdateDiskCache(); /** * Encode the stencils and save the bytecode to the necko cache. @@ -767,14 +762,12 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { JS::loader::LoadedScript* aLoadedScript); /** - * Stop collecting delazifications for all requests. + * Discard all disk-cache-related info for scripts queued for the disk cache. + * * This should be used when the ScriptLoader is getting destroyed, or * when it hits any critical error. - * - * The delazifications collected so far are reflected to the stencils, - * but they won't be encoded. */ - void GiveUpCaching(); + void GiveUpDiskCaching(); already_AddRefed<nsIGlobalObject> GetGlobalForRequest( ScriptLoadRequest* aRequest); @@ -905,7 +898,7 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { bool mDeferCheckpointReached; bool mBlockingDOMContentLoaded; bool mLoadEventFired; - bool mGiveUpCaching; + bool mGiveUpDiskCaching; bool mContinueParsingDocumentAfterCurrentScript; TimeDuration mMainThreadParseTime; diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp @@ -1636,9 +1636,9 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext( } // TODO: Bug 1973321: Prepare Bytecode encoding for dynamic import - rv = mLoader->MaybePrepareModuleForCacheAfterExecute(aRequest, NS_OK); + rv = mLoader->MaybePrepareModuleForDiskCacheAfterExecute(aRequest, NS_OK); - mLoader->MaybeUpdateCache(); + mLoader->MaybeUpdateDiskCache(); return rv; } diff --git a/js/loader/ModuleLoaderBase.h b/js/loader/ModuleLoaderBase.h @@ -110,15 +110,12 @@ class ScriptLoaderInterface : public nsISupports { JSContext* cx, ScriptLoadRequest* aRequest, CompileOptions* aOptions, MutableHandle<JSScript*> aIntroductionScript) = 0; - virtual void MaybePrepareModuleForCacheBeforeExecute( - JSContext* aCx, ModuleLoadRequest* aRequest) {} - - virtual nsresult MaybePrepareModuleForCacheAfterExecute( + virtual nsresult MaybePrepareModuleForDiskCacheAfterExecute( ModuleLoadRequest* aRequest, nsresult aRv) { return NS_OK; } - virtual void MaybeUpdateCache() {} + virtual void MaybeUpdateDiskCache() {} }; class ModuleMapKey : public PLDHashEntryHdr {