Bug 865729 - Remove nsIJSContextStack. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Apr 2013 11:16:24 -0700
changeset 141202 a751e69be9f132a673c6edf3a3a87e99ead49a96
parent 141201 88dff387b118ff7419c639f8100b6682143811aa
child 141203 dbb499490f45e19a81c81b94d20ca64777b8bccf
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs865729
milestone23.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 865729 - Remove nsIJSContextStack. r=gabor \o/
caps/src/nsScriptSecurityManager.cpp
content/base/src/nsContentUtils.cpp
js/xpconnect/idl/moz.build
js/xpconnect/idl/nsIJSContextStack.idl
js/xpconnect/idl/nsIXPConnect.idl
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcprivate.h
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -257,20 +257,17 @@ private:
     bool mDidGetFlags;
     bool mMustFreeName;
 };
 
 JSContext *
 nsScriptSecurityManager::GetCurrentJSContext()
 {
     // Get JSContext from stack.
-    JSContext *cx;
-    if (NS_FAILED(sXPConnect->Peek(&cx)))
-        return nullptr;
-    return cx;
+    return sXPConnect->GetCurrentJSContext();
 }
 
 JSContext *
 nsScriptSecurityManager::GetSafeJSContext()
 {
     // Get JSContext from stack.
     return sXPConnect->GetSafeJSContext();
 }
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -5442,21 +5442,17 @@ nsContentUtils::GetContextForEventHandle
 
   return nullptr;
 }
 
 /* static */
 JSContext *
 nsContentUtils::GetCurrentJSContext()
 {
-  JSContext *cx = nullptr;
-
-  sXPConnect->Peek(&cx);
-
-  return cx;
+  return sXPConnect->GetCurrentJSContext();
 }
 
 /* static */
 JSContext *
 nsContentUtils::GetSafeJSContext()
 {
   return sXPConnect->GetSafeJSContext();
 }
--- a/js/xpconnect/idl/moz.build
+++ b/js/xpconnect/idl/moz.build
@@ -1,17 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPIDL_SOURCES += [
     'mozIJSSubScriptLoader.idl',
-    'nsIJSContextStack.idl',
     'nsIJSEngineTelemetryStats.idl',
     'nsIJSRuntimeService.idl',
     'nsIScriptError.idl',
     'nsIXPCScriptNotify.idl',
     'nsIXPCScriptable.idl',
     'nsIXPCSecurityManager.idl',
     'nsIXPConnect.idl',
     'xpcIJSGetFactory.idl',
deleted file mode 100644
--- a/js/xpconnect/idl/nsIJSContextStack.idl
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-[ptr] native JSContext(JSContext);
-
-[uuid(ff1e7ec6-249b-4bda-9068-7b06ebb58a2a)]
-interface nsIJSContextStack : nsISupports
-{
-    readonly attribute int32_t  count;
-    JSContext                   peek();
-};
-
-[uuid(59ad3ff1-a2d3-4c11-b825-098bff3c3e15)]
-interface nsIThreadJSContextStack : nsIJSContextStack
-{
-    /* inherits methods of nsIJSContextStack */
-    [notxpcom,nostdcall] JSContext getSafeJSContext();
-};
--- a/js/xpconnect/idl/nsIXPConnect.idl
+++ b/js/xpconnect/idl/nsIXPConnect.idl
@@ -12,17 +12,16 @@
 #include "xpcjsid.idl"
 #include "xpcexception.idl"
 #include "nsIInterfaceInfo.idl"
 #include "nsIInterfaceInfoManager.idl"
 #include "nsIExceptionService.idl"
 #include "nsIVariant.idl"
 #include "nsIObjectOutputStream.idl"
 #include "nsIObjectInputStream.idl"
-#include "nsIJSContextStack.idl"
 
 %{ C++
 #include "jspubtd.h"
 #include "xptinfo.h"
 #include "nsAXPCNativeCallContext.h"
 
 class nsWrapperCache;
 %}
@@ -286,18 +285,18 @@ interface nsIXPCFunctionThisTranslator :
 %{ C++
 // For use with the service manager
 // {CB6593E0-F9B2-11d2-BDD6-000064657374}
 #define NS_XPCONNECT_CID \
 { 0xcb6593e0, 0xf9b2, 0x11d2, \
     { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
 %}
 
-[uuid(b3012603-aa25-4192-b331-c16272499957)]
-interface nsIXPConnect : nsIThreadJSContextStack
+[uuid(4d292c29-9d18-403b-b98e-2056e550a3b4)]
+interface nsIXPConnect : nsISupports
 {
 %{ C++
   NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID)
 %}
 
     /**
      * Initializes classes on a global object that has already been created.
      */
@@ -460,20 +459,19 @@ interface nsIXPConnect : nsIThreadJSCont
 
     nsIStackFrame
     createStackFrameLocation(in uint32_t       aLanguage,
                              in string         aFilename,
                              in string         aFunctionName,
                              in int32_t        aLineNumber,
                              in nsIStackFrame  aCaller);
 
-    /**
-    * @deprecated do-nothing function.
-    */
-    [deprecated] void syncJSContexts();
+
+    [noscript,notxpcom,nostdcall] JSContextPtr getCurrentJSContext();
+    [noscript,notxpcom,nostdcall] JSContextPtr getSafeJSContext();
 
     readonly attribute nsIStackFrame                CurrentJSStack;
     readonly attribute nsAXPCNativeCallContextPtr   CurrentNativeCallContext;
 
     void debugDump(in short depth);
     void debugDumpObject(in nsISupports aCOMObj, in short depth);
     void debugDumpJSStack(in boolean showArgs,
                           in boolean showLocals,
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -43,23 +43,21 @@
 #include "nsThread.h"
 #include "mozilla/XPTInterfaceInfoManager.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace xpc;
 using namespace JS;
 
-NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
+NS_IMPL_THREADSAFE_ISUPPORTS5(nsXPConnect,
                               nsIXPConnect,
                               nsISupportsWeakReference,
                               nsIThreadObserver,
                               nsIJSRuntimeService,
-                              nsIJSContextStack,
-                              nsIThreadJSContextStack,
                               nsIJSEngineTelemetryStats)
 
 nsXPConnect* nsXPConnect::gSelf = nullptr;
 JSBool       nsXPConnect::gOnceAliveNowDead = false;
 uint32_t     nsXPConnect::gReportAllJSExceptions = 0;
 
 JSBool       xpc::gDebugMode = false;
 JSBool       xpc::gDesiredDebugMode = false;
@@ -1515,19 +1513,18 @@ nsXPConnect::CreateStackFrameLocation(ui
 
 /* readonly attribute nsIStackFrame CurrentJSStack; */
 NS_IMETHODIMP
 nsXPConnect::GetCurrentJSStack(nsIStackFrame * *aCurrentJSStack)
 {
     NS_ASSERTION(aCurrentJSStack, "bad param");
     *aCurrentJSStack = nullptr;
 
-    JSContext* cx;
     // is there a current context available?
-    if (NS_SUCCEEDED(Peek(&cx)) && cx) {
+    if (JSContext *cx = GetCurrentJSContext()) {
         nsCOMPtr<nsIStackFrame> stack;
         XPCJSStack::CreateStack(cx, getter_AddRefs(stack));
         if (stack) {
             // peel off native frames...
             uint32_t language;
             nsCOMPtr<nsIStackFrame> caller;
             while (stack &&
                    NS_SUCCEEDED(stack->GetLanguage(&language)) &&
@@ -1547,23 +1544,16 @@ NS_IMETHODIMP
 nsXPConnect::GetCurrentNativeCallContext(nsAXPCNativeCallContext * *aCurrentNativeCallContext)
 {
     NS_ASSERTION(aCurrentNativeCallContext, "bad param");
 
     *aCurrentNativeCallContext = XPCJSRuntime::Get()->GetCallContext();
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXPConnect::SyncJSContexts(void)
-{
-    // Do-nothing compatibility function
-    return NS_OK;
-}
-
 /* void setFunctionThisTranslator (in nsIIDRef aIID, in nsIXPCFunctionThisTranslator aTranslator); */
 NS_IMETHODIMP
 nsXPConnect::SetFunctionThisTranslator(const nsIID & aIID,
                                        nsIXPCFunctionThisTranslator *aTranslator)
 {
     XPCJSRuntime* rt = GetRuntime();
     IID2ThisTranslatorMap* map = rt->GetThisTranslatorMap();
     {
@@ -1769,51 +1759,45 @@ nsXPConnect::DebugDumpObject(nsISupports
 }
 
 /* void debugDumpJSStack (in bool showArgs, in bool showLocals, in bool showThisProps); */
 NS_IMETHODIMP
 nsXPConnect::DebugDumpJSStack(bool showArgs,
                               bool showLocals,
                               bool showThisProps)
 {
-    JSContext* cx;
-    if (NS_FAILED(Peek(&cx)))
-        printf("failed to peek into nsIThreadJSContextStack service!\n");
-    else if (!cx)
+    JSContext* cx = GetCurrentJSContext();
+    if (!cx)
         printf("there is no JSContext on the nsIThreadJSContextStack!\n");
     else
         xpc_DumpJSStack(cx, showArgs, showLocals, showThisProps);
 
     return NS_OK;
 }
 
 char*
 nsXPConnect::DebugPrintJSStack(bool showArgs,
                                bool showLocals,
                                bool showThisProps)
 {
-    JSContext* cx;
-    if (NS_FAILED(Peek(&cx)))
-        printf("failed to peek into nsIThreadJSContextStack service!\n");
-    else if (!cx)
+    JSContext* cx = GetCurrentJSContext();
+    if (!cx)
         printf("there is no JSContext on the nsIThreadJSContextStack!\n");
     else
         return xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps);
 
     return nullptr;
 }
 
 /* void debugDumpEvalInJSStackFrame (in uint32_t aFrameNumber, in string aSourceText); */
 NS_IMETHODIMP
 nsXPConnect::DebugDumpEvalInJSStackFrame(uint32_t aFrameNumber, const char *aSourceText)
 {
-    JSContext* cx;
-    if (NS_FAILED(Peek(&cx)))
-        printf("failed to peek into nsIThreadJSContextStack service!\n");
-    else if (!cx)
+    JSContext* cx = GetCurrentJSContext();
+    if (!cx)
         printf("there is no JSContext on the nsIThreadJSContextStack!\n");
     else
         xpc_DumpEvalInJSStackFrame(cx, aFrameNumber, aSourceText);
 
     return NS_OK;
 }
 
 /* jsval variantToJS (in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value); */
@@ -1958,38 +1942,16 @@ nsXPConnect::RegisterGCCallback(JSGCCall
 
 /* [noscript, notxpcom] void unregisterGCCallback(in JSGCCallback func); */
 NS_IMETHODIMP_(void)
 nsXPConnect::UnregisterGCCallback(JSGCCallback func)
 {
     mRuntime->RemoveGCCallback(func);
 }
 
-//  nsIJSContextStack and nsIThreadJSContextStack implementations
-
-/* readonly attribute int32_t Count; */
-NS_IMETHODIMP
-nsXPConnect::GetCount(int32_t *aCount)
-{
-    MOZ_ASSERT(aCount);
-
-    *aCount = XPCJSRuntime::Get()->GetJSContextStack()->Count();
-    return NS_OK;
-}
-
-/* JSContext Peek (); */
-NS_IMETHODIMP
-nsXPConnect::Peek(JSContext * *_retval)
-{
-    MOZ_ASSERT(_retval);
-
-    *_retval = xpc_UnmarkGrayContext(XPCJSRuntime::Get()->GetJSContextStack()->Peek());
-    return NS_OK;
-}
-
 #ifdef MOZ_JSDEBUGGER
 void
 nsXPConnect::CheckForDebugMode(JSRuntime *rt)
 {
     JSContext *cx = NULL;
 
     if (gDebugMode == gDesiredDebugMode) {
         return;
@@ -2060,16 +2022,24 @@ xpc_ActivateDebugMode()
 {
     XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
     nsXPConnect::GetXPConnect()->SetDebugModeWhenPossible(true, true);
     nsXPConnect::CheckForDebugMode(rt->GetJSRuntime());
 }
 
 /* virtual */
 JSContext*
+nsXPConnect::GetCurrentJSContext()
+{
+    JSContext *cx = XPCJSRuntime::Get()->GetJSContextStack()->Peek();
+    return xpc_UnmarkGrayContext(cx);
+}
+
+/* virtual */
+JSContext*
 nsXPConnect::GetSafeJSContext()
 {
     return XPCJSRuntime::Get()->GetJSContextStack()->GetSafeJSContext();
 }
 
 namespace xpc {
 namespace danger {
 
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -141,17 +141,16 @@
 #include "nsAutoJSValHolder.h"
 
 #include "js/HashTable.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/Mutex.h"
 
 #include "nsThreadUtils.h"
-#include "nsIJSContextStack.h"
 #include "nsIJSEngineTelemetryStats.h"
 
 #include "nsIConsoleService.h"
 #include "nsIScriptError.h"
 #include "nsIExceptionService.h"
 
 #include "nsVariant.h"
 #include "nsIPropertyBag.h"
@@ -467,18 +466,16 @@ class nsXPConnect : public nsIXPConnect,
                     public nsIJSEngineTelemetryStats
 {
 public:
     // all the interface method declarations...
     NS_DECL_ISUPPORTS
     NS_DECL_NSIXPCONNECT
     NS_DECL_NSITHREADOBSERVER
     NS_DECL_NSIJSRUNTIMESERVICE
-    NS_DECL_NSIJSCONTEXTSTACK
-    NS_DECL_NSITHREADJSCONTEXTSTACK
     NS_DECL_NSIJSENGINETELEMETRYSTATS
 
     // non-interface implementation
 public:
     // These get non-addref'd pointers
     static nsXPConnect*  GetXPConnect();
     static nsXPConnect*  FastGetXPConnect() { return gSelf ? gSelf : GetXPConnect(); }
     static XPCJSRuntime* GetRuntimeInstance();