Bug 860085 - Use an AutoPushJSContext in XPCCallContext instead of doing it manually. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Wed, 03 Jul 2013 11:05:18 -0600
changeset 137364 ead82531467891893a071ac92af77a9f8e9e6b27
parent 137363 55497c1e73913a066008d70ed7cee994a02afe11
child 137365 d00977f69122fedead1e6d8c1e11e52a8e55d266
push id24920
push userphilringnalda@gmail.com
push dateThu, 04 Jul 2013 17:03:47 +0000
treeherdermozilla-central@efa23d6bd3fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs860085
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 860085 - Use an AutoPushJSContext in XPCCallContext instead of doing it manually. r=gabor
js/xpconnect/src/XPCCallContext.cpp
js/xpconnect/src/XPCInlines.h
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCCallContext.cpp
+++ b/js/xpconnect/src/XPCCallContext.cpp
@@ -21,45 +21,33 @@ using namespace JS;
 XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage,
                                JSContext* cx       /* = GetDefaultJSContext() */,
                                HandleObject obj    /* = nullptr               */,
                                HandleObject funobj /* = nullptr               */,
                                HandleId name       /* = JSID_VOID             */,
                                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),
         mTearOff(nullptr),
         mName(cx)
 {
     MOZ_ASSERT(cx);
 
     NS_ASSERTION(mJSContext, "No JSContext supplied to XPCCallContext");
     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);
 
     // hook into call context chain.
     mPrevCallContext = XPCJSRuntime::Get()->SetCallContext(this);
 
     // We only need to addref xpconnect once so only do it if this is the first
     // context in the chain.
@@ -261,25 +249,16 @@ XPCCallContext::~XPCCallContext()
         mXPCContext->SetCallingLangType(mPrevCallerLanguage);
 
         DebugOnly<XPCCallContext*> old = XPCJSRuntime::Get()->SetCallContext(mPrevCallContext);
         NS_ASSERTION(old == this, "bad pop from per thread data");
 
         shouldReleaseXPC = mPrevCallContext == nullptr;
     }
 
-    if (mContextPopRequired) {
-        XPCJSContextStack* stack = XPCJSRuntime::Get()->GetJSContextStack();
-        NS_ASSERTION(stack, "bad!");
-        if (stack) {
-            DebugOnly<JSContext*> poppedCX = stack->Pop();
-            NS_ASSERTION(poppedCX == mJSContext, "bad pop");
-        }
-    }
-
     if (shouldReleaseXPC && mXPC)
         NS_RELEASE(mXPC);
 }
 
 /* readonly attribute nsISupports Callee; */
 NS_IMETHODIMP
 XPCCallContext::GetCallee(nsISupports * *aCallee)
 {
--- a/js/xpconnect/src/XPCInlines.h
+++ b/js/xpconnect/src/XPCInlines.h
@@ -56,23 +56,16 @@ XPCCallContext::GetXPCContext() const
 
 inline JSContext*
 XPCCallContext::GetJSContext() const
 {
     CHECK_STATE(HAVE_CONTEXT);
     return mJSContext;
 }
 
-inline JSBool
-XPCCallContext::GetContextPopRequired() const
-{
-    CHECK_STATE(HAVE_CONTEXT);
-    return mContextPopRequired;
-}
-
 inline XPCContext::LangType
 XPCCallContext::GetCallerLanguage() const
 {
     CHECK_STATE(HAVE_CONTEXT);
     return mCallerLanguage;
 }
 
 inline XPCContext::LangType
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -164,16 +164,17 @@
 #include "nsJSPrincipals.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsISecurityCheckedComponent.h"
 #include "xpcObjectHelper.h"
 #include "nsIThreadInternal.h"
 
 #include "SandboxPrivate.h"
 #include "BackstagePass.h"
+#include "nsCxPusher.h"
 
 #ifdef XP_WIN
 // Nasty MS defines
 #ifdef GetClassInfo
 #undef GetClassInfo
 #endif
 #ifdef GetClassName
 #undef GetClassName
@@ -1144,24 +1145,23 @@ private:
 inline void CHECK_STATE(int s) const {NS_ASSERTION(mState >= s, "bad state");}
 #else
 #define CHECK_STATE(s) ((void)0)
 #endif
 
 private:
     mozilla::Maybe<AutoJSContextDestroyer>   mCxDestroyer;
 
-    JSAutoRequest                   mAr;
+    mozilla::AutoPushJSContext      mPusher;
     State                           mState;
 
     nsXPConnect*                    mXPC;
 
     XPCContext*                     mXPCContext;
     JSContext*                      mJSContext;
-    JSBool                          mContextPopRequired;
 
     XPCContext::LangType            mCallerLanguage;
 
     // ctor does not necessarily init the following. BEWARE!
 
     XPCContext::LangType            mPrevCallerLanguage;
 
     XPCCallContext*                 mPrevCallContext;