tor-browser

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

commit 7f4d0b5564cb2707c8c92a597fe6748d10c4340a
parent 7292c3390270b56248ee9dec327fe16e57fcc06c
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed,  8 Oct 2025 04:04:44 +0000

Bug 1991370 - Part 3: Use FrontendContext-based EncodeStencil in XUL prototype cache. r=bthrall

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

Diffstat:
Mdom/xul/nsXULElement.cpp | 22++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp @@ -1456,15 +1456,21 @@ nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo) mSrcLoadWaiters(nullptr), mStencil(nullptr) {} -static nsresult WriteStencil(nsIObjectOutputStream* aStream, JSContext* aCx, +static nsresult WriteStencil(nsIObjectOutputStream* aStream, JS::Stencil* aStencil) { + JS::FrontendContext* fc = JS::NewFrontendContext(); + if (!fc) { + return NS_ERROR_OUT_OF_MEMORY; + } + JS::TranscodeBuffer buffer; JS::TranscodeResult code; - code = JS::EncodeStencil(aCx, aStencil, buffer); + code = JS::EncodeStencil(fc, aStencil, buffer); + + JS::DestroyFrontendContext(fc); if (code != JS::TranscodeResult::Ok) { if (code == JS::TranscodeResult::Throw) { - JS_ClearPendingException(aCx); return NS_ERROR_OUT_OF_MEMORY; } @@ -1557,11 +1563,6 @@ nsresult nsXULPrototypeScript::Serialize( const nsTArray<RefPtr<mozilla::dom::NodeInfo>>* aNodeInfos) { NS_ENSURE_TRUE(aProtoDoc, NS_ERROR_UNEXPECTED); - AutoJSAPI jsapi; - if (!jsapi.Init(xpc::CompilationScope())) { - return NS_ERROR_UNEXPECTED; - } - NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr || !mStencil, "script source still loading when serializing?!"); if (!mStencil) return NS_ERROR_FAILURE; @@ -1571,10 +1572,7 @@ nsresult nsXULPrototypeScript::Serialize( rv = aStream->Write32(mLineNo); if (NS_FAILED(rv)) return rv; - JSContext* cx = jsapi.cx(); - MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx)); - - return WriteStencil(aStream, cx, mStencil); + return WriteStencil(aStream, mStencil); } nsresult nsXULPrototypeScript::SerializeOutOfLine(