tor-browser

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

commit a52ae7f8463026fc79ee76622fe5eb4cfd94c0f8
parent c2cf93cc4884e7b777f073a0a44465c16891ba3f
Author: Matthew Gaudet <mgaudet@mozilla.com>
Date:   Fri,  3 Oct 2025 21:45:32 +0000

Bug 1992174 - Common up initialization for CallSetup r=smaug

I believe ccjs->EnterMicroTask was lost by accident during refactoring while
splitting D265352 out of D261175. Rather than just put it back, I thought
we should create a common base constructor.

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

Diffstat:
Mdom/bindings/CallbackObject.cpp | 26+++++++++++++++-----------
Mdom/bindings/CallbackObject.h | 5+++++
2 files changed, 20 insertions(+), 11 deletions(-)

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