tor-browser

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

commit e90d025bb7dc38b00379a74d0bedcfcb9812df33
parent bb017f6943c433dbefa67cdb66701c12a70cb02c
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Tue, 21 Oct 2025 15:14:56 +0000

Bug 1991370 - Part 2: Use FrontendContext-based EncodeStencil in DOM ScriptLoader. r=bthrall

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

Diffstat:
Mdom/script/ScriptLoader.cpp | 28+++++++++++++---------------
Mdom/script/ScriptLoader.h | 5+++--
2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -3559,20 +3559,15 @@ void ScriptLoader::UpdateCache() { return; } - // Should not be encoding modules at all. - nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject(); - if (!globalObject) { - GiveUpCaching(); - return; - } - - nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext(); - if (!context) { - GiveUpCaching(); + JS::FrontendContext* fc = JS::NewFrontendContext(); + if (!fc) { + LOG( + ("ScriptLoader (%p): Cannot create FrontendContext for bytecode " + "encoding.", + this)); return; } - AutoEntryScript aes(globalObject, "encode bytecode", true); RefPtr<ScriptLoadRequest> request; while (!mCachingQueue.isEmpty()) { request = mCachingQueue.StealFirst(); @@ -3585,16 +3580,18 @@ void ScriptLoader::UpdateCache() { // TODO: Move this to SharedScriptCache. if (request->PassedConditionForDiskCache() && request->getLoadedScript()->HasDiskCacheReference()) { - EncodeBytecodeAndSave(aes.cx(), request->getLoadedScript()); + EncodeBytecodeAndSave(fc, request->getLoadedScript()); } request->DropBytecode(); request->getLoadedScript()->DropDiskCacheReference(); } + + JS::DestroyFrontendContext(fc); } void ScriptLoader::EncodeBytecodeAndSave( - JSContext* aCx, JS::loader::LoadedScript* aLoadedScript) { + JS::FrontendContext* aFc, JS::loader::LoadedScript* aLoadedScript) { MOZ_ASSERT(aLoadedScript->HasDiskCacheReference()); MOZ_ASSERT(aLoadedScript->HasStencil()); @@ -3608,12 +3605,13 @@ void ScriptLoader::EncodeBytecodeAndSave( } JS::TranscodeResult result = - JS::EncodeStencil(aCx, aLoadedScript->GetStencil(), SRIAndBytecode); + JS::EncodeStencil(aFc, aLoadedScript->GetStencil(), SRIAndBytecode); + if (result != JS::TranscodeResult::Ok) { // Encoding can be aborted for non-supported syntax (e.g. asm.js), or // any other internal error. // We don't care the error and just give up encoding. - JS_ClearPendingException(aCx); + JS::ClearFrontendErrors(aFc); LOG(("LoadedScript (%p): Cannot serialize bytecode", aLoadedScript)); return; diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h @@ -10,7 +10,8 @@ #include "ModuleLoader.h" #include "SharedScriptCache.h" #include "js/TypeDecls.h" -#include "js/Utility.h" // JS::FreePolicy +#include "js/Utility.h" // JS::FreePolicy +#include "js/experimental/CompileScript.h" // JS::FrontendContext #include "js/loader/LoadedScript.h" #include "js/loader/ModuleLoaderBase.h" #include "js/loader/ScriptKind.h" @@ -764,7 +765,7 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { /** * Encode the stencils and save the bytecode to the necko cache. */ - void EncodeBytecodeAndSave(JSContext* aCx, + void EncodeBytecodeAndSave(JS::FrontendContext* aFc, JS::loader::LoadedScript* aLoadedScript); /**