tor-browser

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

commit bf30ffb3cfae9d84b3fc955eaf7bf1fbb2beff1f
parent 276b1d0d9a8e31eb41cb60ffc4194e58ab0396bc
Author: Bryan Thrall <bthrall@mozilla.com>
Date:   Wed,  5 Nov 2025 15:42:21 +0000

Bug 1996605 - Get CycleCollectedJSContext once instead of twice in CallSetup r=smaug

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

Diffstat:
Mdom/bindings/CallbackObject.cpp | 24++++++++++++++++--------
Mdom/bindings/CallbackObject.h | 8+++++++-
2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/dom/bindings/CallbackObject.cpp b/dom/bindings/CallbackObject.cpp @@ -301,29 +301,36 @@ void CallSetup::SetupForExecution(nsIGlobalObject* aGlobalObject, // Private delegating constructor for common initialization CallSetup::CallSetup(ErrorResult& aRv, CallbackObjectBase::ExceptionHandling aExceptionHandling, - JS::Realm* aRealm, bool aIsMainThread) + JS::Realm* aRealm, bool aIsMainThread, + CycleCollectedJSContext* aCCJS) : mCx(nullptr), mRealm(aRealm), mErrorResult(aRv), mExceptionHandling(aExceptionHandling), mIsMainThread(aIsMainThread) { - CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); - MOZ_ASSERT(ccjs); - ccjs->EnterMicroTask(); + MOZ_ASSERT(aCCJS); + aCCJS->EnterMicroTask(); } CallSetup::CallSetup(CallbackObjectBase* aCallback, ErrorResult& aRv, const char* aExecutionReason, CallbackObjectBase::ExceptionHandling aExceptionHandling, JS::Realm* aRealm, bool aIsJSImplementedWebIDL) - : CallSetup(aRv, aExceptionHandling, aRealm, NS_IsMainThread()) { + : CallSetup(aCallback, aRv, aExecutionReason, aExceptionHandling, aRealm, + aIsJSImplementedWebIDL, CycleCollectedJSContext::Get()) {} + +CallSetup::CallSetup(CallbackObjectBase* aCallback, ErrorResult& aRv, + const char* aExecutionReason, + CallbackObjectBase::ExceptionHandling aExceptionHandling, + JS::Realm* aRealm, bool aIsJSImplementedWebIDL, + CycleCollectedJSContext* aCCJS) + : CallSetup(aRv, aExceptionHandling, aRealm, NS_IsMainThread(), aCCJS) { MOZ_ASSERT_IF( aExceptionHandling == CallbackObjectBase::eReportExceptions || aExceptionHandling == CallbackObjectBase::eRethrowExceptions, !aRealm); - CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); - JS::RootedTuple<JSObject*, JSObject*, JSObject*> roots(ccjs->RootingCx()); + JS::RootedTuple<JSObject*, JSObject*, JSObject*> roots(aCCJS->RootingCx()); // Compute the caller's subject principal (if necessary) early, before we // do anything that might perturb the relevant state. @@ -382,7 +389,8 @@ CallSetup::CallSetup(JS::Handle<JSObject*> aCallbackGlobal, const char* aExecutionReason, CallbackObjectBase::ExceptionHandling aExceptionHandling, JS::Realm* aRealm) - : CallSetup(aRv, aExceptionHandling, aRealm, NS_IsMainThread()) { + : CallSetup(aRv, aExceptionHandling, aRealm, NS_IsMainThread(), + CycleCollectedJSContext::Get()) { MOZ_ASSERT_IF(aExceptionHandling == CallbackFunction::eReportExceptions || aExceptionHandling == CallbackFunction::eRethrowExceptions, !aRealm); diff --git a/dom/bindings/CallbackObject.h b/dom/bindings/CallbackObject.h @@ -274,10 +274,16 @@ class MOZ_STACK_CLASS CallSetup { BindingCallContext& GetCallContext() { return *mCallContext; } private: + CallSetup(CallbackObjectBase* aCallback, ErrorResult& aRv, + const char* aExecutionReason, + CallbackObjectBase::ExceptionHandling aExceptionHandling, + JS::Realm* aRealm, bool aIsJSImplementedWebIDL, + CycleCollectedJSContext* aCCJS); // Private delegating constructor for common initialization CallSetup(ErrorResult& aRv, CallbackObjectBase::ExceptionHandling aExceptionHandling, - JS::Realm* aRealm, bool aIsMainThread); + JS::Realm* aRealm, bool aIsMainThread, + CycleCollectedJSContext* aCCJS); // We better not get copy-constructed CallSetup(const CallSetup&) = delete;