tor-browser

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

commit 7292c3390270b56248ee9dec327fe16e57fcc06c
parent cbe156f214fc871ee210f9beda6f5045eb1965b9
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed,  8 Oct 2025 04:04:44 +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 @@ -3580,20 +3580,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(); @@ -3606,16 +3601,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()); @@ -3629,12 +3626,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); /**