Bug 741245 - Remove nsresult return value from nsXPConnect::GetSafeJSContext(); r=bholley
authorMs2ger <ms2ger@gmail.com>
Sat, 14 Apr 2012 15:05:01 +0200
changeset 94981 2d70a752ff798b7aea2eb2430efd5e2564c9af93
parent 94980 df765acf1a600b5521ae291705abbee09010ce3c
child 94982 58b6908bbb6c379ca873012b3a845e9acf910dcf
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs741245
milestone14.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 741245 - Remove nsresult return value from nsXPConnect::GetSafeJSContext(); r=bholley
caps/src/nsScriptSecurityManager.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsDocument.cpp
content/base/src/nsFrameMessageManager.cpp
content/events/src/nsEventListenerService.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsGlobalWindow.cpp
dom/indexedDB/IDBRequest.cpp
dom/plugins/base/nsJSNPRuntime.cpp
dom/plugins/base/nsNPAPIPlugin.cpp
dom/plugins/ipc/PluginIdentifierParent.cpp
dom/system/gonk/SystemWorkerManager.cpp
dom/workers/RuntimeService.cpp
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
js/xpconnect/idl/nsIJSContextStack.idl
js/xpconnect/src/nsXPConnect.cpp
toolkit/components/alerts/mac/mozGrowlDelegate.mm
toolkit/xre/nsNativeAppSupportOS2.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -358,20 +358,17 @@ nsScriptSecurityManager::GetCurrentJSCon
         return nsnull;
     return cx;
 }
 
 JSContext *
 nsScriptSecurityManager::GetSafeJSContext()
 {
     // Get JSContext from stack.
-    JSContext *cx;
-    if (NS_FAILED(sJSContextStack->GetSafeJSContext(&cx)))
-        return nsnull;
-    return cx;
+    return sJSContextStack->GetSafeJSContext();
 }
 
 /* static */
 bool
 nsScriptSecurityManager::SecurityCompareURIs(nsIURI* aSourceURI,
                                              nsIURI* aTargetURI)
 {
     return NS_SecurityCompareURIs(aSourceURI, aTargetURI, sStrictFileOriginPolicy);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -1618,18 +1618,17 @@ nsContentUtils::GetContextFromDocument(n
 
 //static
 void
 nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
 {
   if (!sThreadJSContextStack) {
     return;
   }
-  JSContext* cx = nsnull;
-  sThreadJSContextStack->GetSafeJSContext(&cx);
+  JSContext* cx = sThreadJSContextStack->GetSafeJSContext();
   if (!cx) {
     return;
   }
   if (JSObject* global = JS_GetGlobalObject(cx)) {
     JS_CALL_OBJECT_TRACER(aTrc, global, "safe context");
   }
 }
 
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -3840,17 +3840,17 @@ nsDocument::SetScriptGlobalObject(nsIScr
       JSObject *obj = GetWrapperPreserveColor();
       if (obj) {
         JSObject *newScope = aScriptGlobalObject->GetGlobalJSObject();
         nsIScriptContext *scx = aScriptGlobalObject->GetContext();
         JSContext *cx = scx ? scx->GetNativeContext() : nsnull;
         if (!cx) {
           nsContentUtils::ThreadJSContextStack()->Peek(&cx);
           if (!cx) {
-            nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(&cx);
+            cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
             NS_ASSERTION(cx, "Uhoh, no context, this is bad!");
           }
         }
         if (cx) {
           NS_ASSERTION(JS_GetGlobalForObject(cx, obj) == newScope,
                        "Wrong scope, this is really bad!");
         }
       }
@@ -6049,17 +6049,17 @@ GetContextAndScope(nsIDocument* aOldDocu
       // No context reachable from the old or new document, use the
       // calling context, or the safe context if no caller can be
       // found.
 
       nsIThreadJSContextStack* stack = nsContentUtils::ThreadJSContextStack();
       stack->Peek(&cx);
 
       if (!cx) {
-        stack->GetSafeJSContext(&cx);
+        cx = stack->GetSafeJSContext();
 
         if (!cx) {
           // No safe context reachable, bail.
           NS_WARNING("No context reachable in GetContextAndScopes()!");
 
           return NS_ERROR_NOT_AVAILABLE;
         }
       }
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -374,17 +374,17 @@ nsFrameMessageManager::ReceiveMessage(ns
                                       const nsAString& aMessage,
                                       bool aSync, const nsAString& aJSON,
                                       JSObject* aObjectsArray,
                                       InfallibleTArray<nsString>* aJSONRetVal,
                                       JSContext* aContext)
 {
   JSContext* ctx = mContext ? mContext : aContext;
   if (!ctx) {
-    nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(&ctx);
+    ctx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
   }
   if (mListeners.Length()) {
     nsCOMPtr<nsIAtom> name = do_GetAtom(aMessage);
     MMListenerRemover lr(this);
 
     for (PRUint32 i = 0; i < mListeners.Length(); ++i) {
       if (mListeners[i].mMessage == name) {
         nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS =
@@ -718,18 +718,17 @@ CachedScriptUnrooter(const nsAString& aK
   return PL_DHASH_REMOVE;
 }
 
 // static
 void
 nsFrameScriptExecutor::Shutdown()
 {
   if (sCachedScripts) {
-    JSContext* cx = nsnull;
-    nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(&cx);
+    JSContext* cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
     if (cx) {
 #ifdef DEBUG_smaug
       printf("Will clear cached frame manager scripts!\n");
 #endif
       JSAutoRequest ar(cx);
       NS_ASSERTION(sCachedScripts != nsnull, "Need cached scripts");
       sCachedScripts->Enumerate(CachedScriptUnrooter, cx);
     } else {
--- a/content/events/src/nsEventListenerService.cpp
+++ b/content/events/src/nsEventListenerService.cpp
@@ -129,18 +129,17 @@ nsEventListenerInfo::GetJSVal(JSContext*
 NS_IMETHODIMP
 nsEventListenerInfo::ToSource(nsAString& aResult)
 {
   aResult.SetIsVoid(true);
 
   nsCOMPtr<nsIThreadJSContextStack> stack =
     nsContentUtils::ThreadJSContextStack();
   if (stack) {
-    JSContext* cx = nsnull;
-    stack->GetSafeJSContext(&cx);
+    JSContext* cx = stack->GetSafeJSContext();
     if (cx && NS_SUCCEEDED(stack->Push(cx))) {
       {
         // Extra block to finish the auto request before calling pop
         JSAutoRequest ar(cx);
         JSAutoEnterCompartment ac;
         jsval v = JSVAL_NULL;
         if (GetJSVal(cx, ac, &v)) {
           JSString* str = JS_ValueToSource(cx, v);
@@ -172,18 +171,17 @@ nsEventListenerInfo::GetDebugObject(nsIS
   
   bool isOn = false;
   jsd->GetIsOn(&isOn);
   NS_ENSURE_TRUE(isOn, NS_OK);
 
   nsCOMPtr<nsIThreadJSContextStack> stack =
     nsContentUtils::ThreadJSContextStack();
   if (stack) {
-    JSContext* cx = nsnull;
-    stack->GetSafeJSContext(&cx);
+    JSContext* cx = stack->GetSafeJSContext();
     if (cx && NS_SUCCEEDED(stack->Push(cx))) {
       {
         // Extra block to finish the auto request before calling pop
         JSAutoRequest ar(cx);
         JSAutoEnterCompartment ac;
         jsval v = JSVAL_NULL;
         if (GetJSVal(cx, ac, &v)) {
           nsCOMPtr<jsdIValue> jsdValue;
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -2413,20 +2413,18 @@ nsDOMClassInfo::Init()
 
   sSecMan = sm;
   NS_ADDREF(sSecMan);
 
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  JSContext *cx = nsnull;
-
-  rv = stack->GetSafeJSContext(&cx);
-  NS_ENSURE_SUCCESS(rv, rv);
+  JSContext* cx = stack->GetSafeJSContext();
+  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
 
   DOM_CLASSINFO_MAP_BEGIN(Window, nsIDOMWindow)
     DOM_CLASSINFO_WINDOW_MAP_ENTRIES(nsGlobalWindow::HasIndexedDBSupport())
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(WindowUtils, nsIDOMWindowUtils)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMWindowUtils)
   DOM_CLASSINFO_MAP_END
@@ -9585,17 +9583,17 @@ public:
     JSContext* cx = nsnull;
     if (mContext) {
       cx = mContext->GetNativeContext();
     } else {
       nsCOMPtr<nsIThreadJSContextStack> stack =
         do_GetService("@mozilla.org/js/xpc/ContextStack;1");
       NS_ENSURE_TRUE(stack, NS_OK);
 
-      stack->GetSafeJSContext(&cx);
+      cx = stack->GetSafeJSContext();
       NS_ENSURE_TRUE(cx, NS_OK);
     }
 
     JSObject* obj = nsnull;
     mWrapper->GetJSObject(&obj);
     NS_ASSERTION(obj, "Should never be null");
     nsHTMLPluginObjElementSH::SetupProtoChain(mWrapper, cx, obj);
     return NS_OK;
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -6194,17 +6194,17 @@ PostMessageEvent::Run()
     cx = scriptContext->GetNativeContext();
   }
 
   if (!cx) {
     // This can happen if mTargetWindow has been closed.  To avoid leaking,
     // we need to find a JSContext.
     nsIThreadJSContextStack* cxStack = nsContentUtils::ThreadJSContextStack();
     if (cxStack) {
-      cxStack->GetSafeJSContext(&cx);
+      cx = cxStack->GetSafeJSContext();
     }
 
     if (!cx) {
       NS_WARNING("Cannot find a JSContext!  Leaking PostMessage buffer.");
       return NS_ERROR_FAILURE;
     }
   }
 
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -129,17 +129,18 @@ IDBRequest::NotifyHelperCompleted(Helper
   }
 
   // Otherwise we need to get the result from the helper.
   JSContext* cx;
   if (GetScriptOwner()) {
     nsIThreadJSContextStack* cxStack = nsContentUtils::ThreadJSContextStack();
     NS_ASSERTION(cxStack, "Failed to get thread context stack!");
 
-    if (NS_FAILED(cxStack->GetSafeJSContext(&cx))) {
+    cx = cxStack->GetSafeJSContext();
+    if (!cx) {
       NS_WARNING("Failed to get safe JSContext!");
       rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
       mError = DOMError::CreateForNSResult(rv);
       return rv;
     }
   }
   else {
     nsIScriptContext* sc = GetContextForEventHandlers(&rv);
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -1980,18 +1980,17 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1");
   if (!stack) {
     NS_ERROR("No context stack available!");
 
     return;
   }
 
-  JSContext *cx;
-  stack->GetSafeJSContext(&cx);
+  JSContext* cx = stack->GetSafeJSContext();
   if (!cx) {
     NS_ERROR("No safe JS context available!");
 
     return;
   }
 
   JSAutoRequest ar(cx);
 
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -1343,20 +1343,20 @@ NPIdentifier NP_CALLBACK
     NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("NPN_getstringidentifier called from the wrong thread\n"));
   }
 
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1");
   if (!stack)
     return NULL;
 
-  JSContext *cx = nsnull;
-  stack->GetSafeJSContext(&cx);
-  if (!cx)
+  JSContext* cx = stack->GetSafeJSContext();
+  if (!cx) {
     return NULL;
+  }
 
   JSAutoRequest ar(cx);
   return doGetIdentifier(cx, name);
 }
 
 void NP_CALLBACK
 _getstringidentifiers(const NPUTF8** names, int32_t nameCount,
                       NPIdentifier *identifiers)
@@ -1364,20 +1364,20 @@ void NP_CALLBACK
   if (!NS_IsMainThread()) {
     NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("NPN_getstringidentifiers called from the wrong thread\n"));
   }
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1");
   if (!stack)
     return;
 
-  JSContext *cx = nsnull;
-  stack->GetSafeJSContext(&cx);
-  if (!cx)
+  JSContext* cx = stack->GetSafeJSContext();
+  if (!cx) {
     return;
+  }
 
   JSAutoRequest ar(cx);
 
   for (int32_t i = 0; i < nameCount; ++i) {
     if (names[i]) {
       identifiers[i] = doGetIdentifier(cx, names[i]);
     } else {
       NPN_PLUGIN_LOG(PLUGIN_LOG_ALWAYS, ("NPN_getstringidentifiers: passed null name"));
--- a/dom/plugins/ipc/PluginIdentifierParent.cpp
+++ b/dom/plugins/ipc/PluginIdentifierParent.cpp
@@ -64,18 +64,17 @@ PluginIdentifierParent::RecvRetain()
   // The following is what nsNPAPIPlugin.cpp does. Gross, but the API doesn't
   // give you a NPP to play with.
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1");
   if (!stack) {
     return false;
   }
 
-  JSContext *cx = nsnull;
-  stack->GetSafeJSContext(&cx);
+  JSContext* cx = stack->GetSafeJSContext();
   if (!cx) {
     return false;
   }
 
   JSAutoRequest ar(cx);
   JSString* str = JSID_TO_STRING(id);
   JSString* str2 = JS_InternJSString(cx, str);
   if (!str2) {
--- a/dom/system/gonk/SystemWorkerManager.cpp
+++ b/dom/system/gonk/SystemWorkerManager.cpp
@@ -211,26 +211,25 @@ SystemWorkerManager::~SystemWorkerManage
 }
 
 nsresult
 SystemWorkerManager::Init()
 {
   NS_ASSERTION(NS_IsMainThread(), "We can only initialize on the main thread");
   NS_ASSERTION(!mShutdown, "Already shutdown!");
 
-  JSContext *cx;
-  nsresult rv = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext(&cx);
-  NS_ENSURE_SUCCESS(rv, rv);
+  JSContext* cx = nsContentUtils::ThreadJSContextStack()->GetSafeJSContext();
+  NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
 
   nsCxPusher pusher;
-  if (!cx || !pusher.Push(cx, false)) {
+  if (!pusher.Push(cx, false)) {
     return NS_ERROR_FAILURE;
   }
 
-  rv = InitRIL(cx);
+  nsresult rv = InitRIL(cx);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = InitWifi(cx);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIObserverService> obs =
     do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
   if (!obs) {
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -1332,17 +1332,17 @@ RuntimeService::AutoSafeJSContext::~Auto
 JSContext*
 RuntimeService::AutoSafeJSContext::GetSafeContext()
 {
   AssertIsOnMainThread();
 
   nsIThreadJSContextStack* stack = nsContentUtils::ThreadJSContextStack();
   NS_ASSERTION(stack, "This should never be null!");
 
-  JSContext* cx;
-  if (NS_FAILED(stack->GetSafeJSContext(&cx))) {
+  JSContext* cx = stack->GetSafeJSContext();
+  if (!cx) {
     NS_ERROR("Couldn't get safe JSContext!");
     return nsnull;
   }
 
   NS_ASSERTION(!JS_IsExceptionPending(cx), "Already has an exception?!");
   return cx;
 }
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -301,20 +301,20 @@ JSContextAutoPopper::~JSContextAutoPoppe
 }
 
 nsresult JSContextAutoPopper::Push(JSContext *cx)
 {
   if (mContext) // only once
     return NS_ERROR_FAILURE;
 
   mService = do_GetService(sJSStackContractID);
-  if(mService) {
+  if (mService) {
     // Get the safe context if we're not provided one.
-    if (!cx && NS_FAILED(mService->GetSafeJSContext(&cx))) {
-      cx = nsnull;
+    if (!cx) {
+      cx = mService->GetSafeJSContext();
     }
 
     // Save cx in mContext to indicate need to pop.
     if (cx && NS_SUCCEEDED(mService->Push(cx))) {
       mContext = cx;
       mContextKungFuDeathGrip = nsJSUtils::GetDynamicScriptContext(cx);
     }
   }
--- a/js/xpconnect/idl/nsIJSContextStack.idl
+++ b/js/xpconnect/idl/nsIJSContextStack.idl
@@ -72,14 +72,14 @@ interface nsIJSContextStackIterator : ns
      *
      * @throws NS_ERROR_NOT_INITIALIZED If there has not been a previous call
      *         to reset.
      * @throws NS_ERROR_NOT_AVAILABLE if already at the end.
      */
     JSContext prev();
 };
 
-[uuid(b7056a2a-a02d-43b1-abb9-47f81f8bf258)]
+[uuid(3f8d6996-172d-4c0a-b591-50d6966cdb9a)]
 interface nsIThreadJSContextStack : nsIJSContextStack
 {
     /* inherits methods of nsIJSContextStack */
-    readonly attribute JSContext safeJSContext;
+    [notxpcom,nostdcall] JSContext getSafeJSContext();
 };
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -2600,31 +2600,27 @@ nsXPConnect::Push(JSContext * cx)
              if (!runningJS)
                  CheckForDebugMode(mRuntime->GetJSRuntime());
          }
      }
 
      return data->GetJSContextStack()->Push(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
-/* attribute JSContext SafeJSContext; */
-NS_IMETHODIMP
-nsXPConnect::GetSafeJSContext(JSContext * *aSafeJSContext)
+/* virtual */
+JSContext*
+nsXPConnect::GetSafeJSContext()
 {
-    NS_ASSERTION(aSafeJSContext, "loser!");
-
-    XPCPerThreadData* data = XPCPerThreadData::GetData(nsnull);
+    XPCPerThreadData *data = XPCPerThreadData::GetData(NULL);
 
     if (!data) {
-        *aSafeJSContext = nsnull;
-        return NS_ERROR_FAILURE;
+        return NULL;
     }
 
-    *aSafeJSContext = data->GetJSContextStack()->GetSafeJSContext();
-    return *aSafeJSContext ? NS_OK : NS_ERROR_FAILURE;
+    return data->GetJSContextStack()->GetSafeJSContext();
 }
 
 nsIPrincipal*
 nsXPConnect::GetPrincipal(JSObject* obj, bool allowShortCircuit) const
 {
     NS_ASSERTION(IS_WRAPPER_CLASS(js::GetObjectClass(obj)),
                  "What kind of wrapper is this?");
 
--- a/toolkit/components/alerts/mac/mozGrowlDelegate.mm
+++ b/toolkit/components/alerts/mac/mozGrowlDelegate.mm
@@ -69,19 +69,18 @@ GetWindowOfObserver(nsIObserver* aObserv
   JSObject* obj;
   nsresult rv = wrappedJS->GetJSObject(&obj);
   NS_ENSURE_SUCCESS(rv, nsnull);
 
   nsCOMPtr<nsIThreadJSContextStack> stack =
     do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
   NS_ENSURE_SUCCESS(rv, nsnull);
 
-  JSContext* cx;
-  rv = stack->GetSafeJSContext(&cx);
-  NS_ENSURE_SUCCESS(rv, nsnull);
+  JSContext* cx = stack->GetSafeJSContext();
+  NS_ENSURE_TRUE(cx, nsnull);
 
   JSAutoRequest ar(cx);
   JSAutoEnterCompartment ac;
   if (!ac.enter(cx, obj)) {
     return nsnull;
   }
 
   JSObject* global = JS_GetGlobalForObject(cx, obj);
--- a/toolkit/xre/nsNativeAppSupportOS2.cpp
+++ b/toolkit/xre/nsNativeAppSupportOS2.cpp
@@ -1673,21 +1673,19 @@ SafeJSContext::~SafeJSContext() {
   }
 }
 
 nsresult SafeJSContext::Push() {
   if (mContext) // only once
     return NS_ERROR_FAILURE;
 
   mService = do_GetService(sJSStackContractID);
-  if(mService) {
-    JSContext *cx;
-    if (NS_SUCCEEDED(mService->GetSafeJSContext(&cx)) &&
-        cx &&
-        NS_SUCCEEDED(mService->Push(cx))) {
+  if (mService) {
+    JSContext* cx = mService->GetSafeJSContext();
+    if (cx && NS_SUCCEEDED(mService->Push(cx))) {
       // Save cx in mContext to indicate need to pop.
       mContext = cx;
     }
   }
   return mContext ? NS_OK : NS_ERROR_FAILURE;
 }
 
 
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -1496,21 +1496,19 @@ SafeJSContext::~SafeJSContext() {
   }
 }
 
 nsresult SafeJSContext::Push() {
   if (mContext) // only once
     return NS_ERROR_FAILURE;
 
   mService = do_GetService(sJSStackContractID);
-  if(mService) {
-    JSContext *cx;
-    if (NS_SUCCEEDED(mService->GetSafeJSContext(&cx)) &&
-        cx &&
-        NS_SUCCEEDED(mService->Push(cx))) {
+  if (mService) {
+    JSContext* cx = mService->GetSafeJSContext();
+    if (cx && NS_SUCCEEDED(mService->Push(cx))) {
       // Save cx in mContext to indicate need to pop.
       mContext = cx;
     }
   }
   return mContext ? NS_OK : NS_ERROR_FAILURE;
 }