Commits

ms2ger committed d9ef055

Cleanup XPCJSContextStack.

Comments (0)

Files changed (1)

XPCJSContextStack

 diff --git a/js/xpconnect/src/XPCCallContext.cpp b/js/xpconnect/src/XPCCallContext.cpp
 --- a/js/xpconnect/src/XPCCallContext.cpp
 +++ b/js/xpconnect/src/XPCCallContext.cpp
-@@ -39,16 +39,17 @@
-  * ***** END LICENSE BLOCK ***** */
- 
+@@ -41,16 +41,17 @@
  /* Call context. */
  
  #include "XPCCallContext.h"
  
+ #include "mozilla/Util.h"
+ 
  #include "nsXPConnect.h"
  #include "XPCContext.h"
 +#include "XPCJSContextStack.h"
  #include "XPCWrappedNative.h"
  #include "XPCWrappedNativeTearOff.h"
  
- XPCCallContext::XPCCallContext(XPCContext::LangType callerLanguage,
+ using namespace mozilla;
 diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp
 --- a/js/xpconnect/src/XPCComponents.cpp
 +++ b/js/xpconnect/src/XPCComponents.cpp
-@@ -47,16 +47,17 @@
+@@ -49,16 +49,17 @@
  #include "nsJSIID.h"
  #include "nsXPCException.h"
  #include "nsXPConnect.h"
 new file mode 100644
 --- /dev/null
 +++ b/js/xpconnect/src/XPCJSContextStack.h
-@@ -0,0 +1,48 @@
+@@ -0,0 +1,67 @@
++/* 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/. */
++
 +#ifndef XPCJSContextStack_h
 +#define XPCJSContextStack_h
 +
-+#include "nsIJSContextStack.h"
++#include "mozilla/StdInt.h"
++
 +#include "nsTArray.h"
 +
 +#include "jspubtd.h"
 +
-+// XPCJSContextStack is not actually an xpcom object, but xpcom calls are
-+// delegated to it as an implementation detail.
-+struct XPCJSContextInfo {
-+    XPCJSContextInfo(JSContext* aCx) :
-+        cx(aCx),
-+        savedFrameChain(false),
-+        suspendDepth(0)
++struct XPCJSContextInfo
++{
++    XPCJSContextInfo(JSContext *aCx)
++      : cx(aCx)
++      , savedFrameChain(false)
++      , suspendDepth(0)
 +    {}
-+    JSContext* cx;
++    JSContext *cx;
 +
 +    // Whether the frame chain was saved
 +    bool savedFrameChain;
 +class XPCJSContextStack
 +{
 +public:
-+    NS_DECL_NSIJSCONTEXTSTACK
-+    NS_DECL_NSITHREADJSCONTEXTSTACK
++    XPCJSContextStack()
++      : mSafeJSContext(NULL)
++      , mOwnSafeJSContext(NULL)
++    { }
 +
-+    XPCJSContextStack();
 +    virtual ~XPCJSContextStack();
 +
++    uint32_t Count()
++    {
++        return mStack.Length();
++    }
++
++    JSContext *Peek()
++    {
++        return mStack.IsEmpty() ? NULL : mStack[mStack.Length() - 1].cx;
++    }
++
++    JSContext *Pop();
++    bool Push(JSContext *cx);
++    JSContext *GetSafeJSContext();
++
 +#ifdef DEBUG
-+    JSBool DEBUG_StackHasJSContext(JSContext*  aJSContext);
++    bool DEBUG_StackHasJSContext(JSContext *cx);
 +#endif
 +
-+    const nsTArray<XPCJSContextInfo>* GetStack()
++    const InfallibleTArray<XPCJSContextInfo> *GetStack()
 +    { return &mStack; }
 +
 +private:
-+    nsAutoTArray<XPCJSContextInfo, 16> mStack;
-+    JSContext*  mSafeJSContext;
-+    JSContext*  mOwnSafeJSContext;
++    AutoInfallibleTArray<XPCJSContextInfo, 16> mStack;
++    JSContext *mSafeJSContext;
++    JSContext *mOwnSafeJSContext;
 +};
 +
 +#endif // XPCJSContextStack_h
 diff --git a/js/xpconnect/src/XPCLazyCallContext.cpp b/js/xpconnect/src/XPCLazyCallContext.cpp
 --- a/js/xpconnect/src/XPCLazyCallContext.cpp
 +++ b/js/xpconnect/src/XPCLazyCallContext.cpp
-@@ -1,10 +1,11 @@
+@@ -1,14 +1,15 @@
+ /* 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 "XPCLazyCallContext.h"
  
 +#include "XPCJSContextStack.h"
  #ifdef DEBUG
  // static
  void
- XPCLazyCallContext::AssertContextIsTopOfStack(JSContext* cx)
+ XPCLazyCallContext::AssertContextIsTopOfStack(JSContext *cx)
  {
-     XPCPerThreadData* tls = XPCPerThreadData::GetData(cx);
+     XPCPerThreadData *tls = XPCPerThreadData::GetData(cx);
 diff --git a/js/xpconnect/src/XPCQuickStubs.cpp b/js/xpconnect/src/XPCQuickStubs.cpp
 --- a/js/xpconnect/src/XPCQuickStubs.cpp
 +++ b/js/xpconnect/src/XPCQuickStubs.cpp
  
  #if defined(DEBUG_jband) || defined(DEBUG_jst) || defined(DEBUG_dbradley) || defined(DEBUG_shaver_no) || defined(DEBUG_timeless)
  #define DEBUG_xpc_hacker
-@@ -457,56 +458,16 @@ enum WrapperType {
+@@ -455,71 +456,16 @@ enum WrapperType {
  ***************************************************************************/
  
  /***************************************************************************/
 -class XPCJSContextStack
 -{
 -public:
--    NS_DECL_NSIJSCONTEXTSTACK
--    NS_DECL_NSITHREADJSCONTEXTSTACK
+-    XPCJSContextStack()
+-      : mSafeJSContext(NULL)
+-      , mOwnSafeJSContext(NULL)
+-    { }
 -
--    XPCJSContextStack();
 -    virtual ~XPCJSContextStack();
 -
+-    uint32_t Count()
+-    {
+-        return mStack.Length();
+-    }
+-
+-    JSContext *Peek()
+-    {
+-        return mStack.IsEmpty() ? NULL : mStack[mStack.Length() - 1].cx;
+-    }
+-
+-    JSContext *Pop();
+-    bool Push(JSContext *cx);
+-    JSContext *GetSafeJSContext();
+-
 -#ifdef DEBUG
--    JSBool DEBUG_StackHasJSContext(JSContext*  aJSContext);
+-    bool DEBUG_StackHasJSContext(JSContext *cx);
 -#endif
 -
--    const nsTArray<XPCJSContextInfo>* GetStack()
+-    const InfallibleTArray<XPCJSContextInfo>* GetStack()
 -    { return &mStack; }
 -
 -private:
--    nsAutoTArray<XPCJSContextInfo, 16> mStack;
+-    AutoInfallibleTArray<XPCJSContextInfo, 16> mStack;
 -    JSContext*  mSafeJSContext;
 -    JSContext*  mOwnSafeJSContext;
 -};