From e11487b445efd4e80aca87c969ab61e3f88924f8 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 3 Jul 2013 11:05:18 -0600 Subject: [PATCH] Bug 860085 - Use an AutoPushJSContext in XPCCallContext instead of doing it manually. r=gabor --- js/xpconnect/src/XPCCallContext.cpp | 23 +---------------------- js/xpconnect/src/XPCInlines.h | 7 ------- js/xpconnect/src/xpcprivate.h | 4 ++-- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/js/xpconnect/src/XPCCallContext.cpp b/js/xpconnect/src/XPCCallContext.cpp index f867023aa14f..4166c110adab 100644 --- a/js/xpconnect/src/XPCCallContext.cpp +++ b/js/xpconnect/src/XPCCallContext.cpp @@ -26,12 +26,11 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage, unsigned argc /* = NO_ARGS */, jsval *argv /* = nullptr */, jsval *rval /* = nullptr */) - : mAr(cx), + : mPusher(cx), mState(INIT_FAILED), mXPC(nsXPConnect::XPConnect()), mXPCContext(nullptr), mJSContext(cx), - mContextPopRequired(false), mCallerLanguage(callerLanguage), mFlattenedJSObject(cx), mWrapper(nullptr), @@ -44,17 +43,6 @@ XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage, if (!mXPC) return; - XPCJSContextStack* stack = XPCJSRuntime::Get()->GetJSContextStack(); - JSContext *topJSContext = stack->Peek(); - - if (topJSContext != mJSContext) { - if (!stack->Push(mJSContext)) { - NS_ERROR("bad!"); - return; - } - mContextPopRequired = true; - } - mXPCContext = XPCContext::GetXPCContext(mJSContext); mPrevCallerLanguage = mXPCContext->SetCallingLangType(mCallerLanguage); @@ -266,15 +254,6 @@ XPCCallContext::~XPCCallContext() shouldReleaseXPC = mPrevCallContext == nullptr; } - if (mContextPopRequired) { - XPCJSContextStack* stack = XPCJSRuntime::Get()->GetJSContextStack(); - NS_ASSERTION(stack, "bad!"); - if (stack) { - DebugOnly poppedCX = stack->Pop(); - NS_ASSERTION(poppedCX == mJSContext, "bad pop"); - } - } - if (shouldReleaseXPC && mXPC) NS_RELEASE(mXPC); } diff --git a/js/xpconnect/src/XPCInlines.h b/js/xpconnect/src/XPCInlines.h index d08b20261ae0..65d15cebc198 100644 --- a/js/xpconnect/src/XPCInlines.h +++ b/js/xpconnect/src/XPCInlines.h @@ -61,13 +61,6 @@ XPCCallContext::GetJSContext() const return mJSContext; } -inline JSBool -XPCCallContext::GetContextPopRequired() const -{ - CHECK_STATE(HAVE_CONTEXT); - return mContextPopRequired; -} - inline XPCContext::LangType XPCCallContext::GetCallerLanguage() const { diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 06c5234b7d74..8b100418c38e 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -169,6 +169,7 @@ #include "SandboxPrivate.h" #include "BackstagePass.h" +#include "nsCxPusher.h" #ifdef XP_WIN // Nasty MS defines @@ -1149,14 +1150,13 @@ inline void CHECK_STATE(int s) const {NS_ASSERTION(mState >= s, "bad state");} private: mozilla::Maybe mCxDestroyer; - JSAutoRequest mAr; + mozilla::AutoPushJSContext mPusher; State mState; nsXPConnect* mXPC; XPCContext* mXPCContext; JSContext* mJSContext; - JSBool mContextPopRequired; XPCContext::LangType mCallerLanguage;