Bug 1050795 Part 2: Remove nsCxPusher. r=bholley
authorBob Owen <bobowencode@gmail.com>
Fri, 08 Aug 2014 16:44:15 +0100
changeset 198862 17fd16e2f47be49c9acffa48037b614dd53d7252
parent 198861 9ea1fc4f59e0a4a465c3f1623316ddfba0d8c607
child 198863 19bd60030de4b70301931e51fea8a8482d06353e
push id47514
push userbobbyholley@gmail.com
push dateMon, 11 Aug 2014 16:29:24 +0000
treeherdermozilla-inbound@17fd16e2f47b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1050795
milestone34.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 1050795 Part 2: Remove nsCxPusher. r=bholley
js/xpconnect/src/nsCxPusher.cpp
js/xpconnect/src/nsCxPusher.h
--- a/js/xpconnect/src/nsCxPusher.cpp
+++ b/js/xpconnect/src/nsCxPusher.cpp
@@ -2,105 +2,22 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "nsCxPusher.h"
 
 #include "nsIScriptContext.h"
-#include "mozilla/dom/EventTarget.h"
 #include "nsDOMJSUtils.h"
 #include "xpcprivate.h"
 #include "WorkerPrivate.h"
 
-using mozilla::dom::EventTarget;
 using mozilla::DebugOnly;
 
-bool
-nsCxPusher::Push(EventTarget *aCurrentTarget)
-{
-  MOZ_ASSERT(mPusher.empty());
-  NS_ENSURE_TRUE(aCurrentTarget, false);
-  nsresult rv;
-  nsIScriptContext* scx =
-    aCurrentTarget->GetContextForEventHandlers(&rv);
-#ifdef DEBUG_smaug
-  NS_ENSURE_SUCCESS(rv, false);
-#else
-  if(NS_FAILED(rv)) {
-    return false;
-  }
-#endif
-
-  if (!scx) {
-    // The target may have a special JS context for event handlers.
-    JSContext* cx = aCurrentTarget->GetJSContextForEventHandlers();
-    if (cx) {
-      mPusher.construct(cx);
-    }
-
-    // Nothing to do here, I guess.  Have to return true so that event firing
-    // will still work correctly even if there is no associated JSContext
-    return true;
-  }
-
-  mPusher.construct(scx->GetNativeContext());
-  return true;
-}
-
-bool
-nsCxPusher::RePush(EventTarget *aCurrentTarget)
-{
-  if (mPusher.empty()) {
-    return Push(aCurrentTarget);
-  }
-
-  if (aCurrentTarget) {
-    nsresult rv;
-    nsIScriptContext* scx =
-      aCurrentTarget->GetContextForEventHandlers(&rv);
-    if (NS_FAILED(rv)) {
-      mPusher.destroy();
-      return false;
-    }
-
-    // If we have the same script context and native context is still
-    // alive, no need to Pop/Push.
-    if (scx && scx == mPusher.ref().GetScriptContext() &&
-        scx->GetNativeContext()) {
-      return true;
-    }
-  }
-
-  mPusher.destroy();
-  return Push(aCurrentTarget);
-}
-
-void
-nsCxPusher::Push(JSContext *cx)
-{
-  mPusher.construct(cx);
-}
-
-void
-nsCxPusher::PushNull()
-{
-  // Note: The Maybe<> template magic seems to need the static_cast below to
-  // work right on some older compilers.
-  mPusher.construct(static_cast<JSContext*>(nullptr), /* aAllowNull = */ true);
-}
-
-void
-nsCxPusher::Pop()
-{
-  if (!mPusher.empty())
-    mPusher.destroy();
-}
-
 namespace mozilla {
 
 AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull)
 {
   MOZ_ASSERT_IF(!allowNull, cx);
 
   // Hold a strong ref to the nsIScriptContext, if any. This ensures that we
   // only destroy the mContext of an nsJSContext when it is not on the cx stack
--- a/js/xpconnect/src/nsCxPusher.h
+++ b/js/xpconnect/src/nsCxPusher.h
@@ -6,35 +6,28 @@
 
 #ifndef nsCxPusher_h
 #define nsCxPusher_h
 
 #include "jsapi.h"
 #include "mozilla/Maybe.h"
 #include "nsCOMPtr.h"
 
-namespace mozilla {
-namespace dom {
-class EventTarget;
-}
-}
-
 class nsIScriptContext;
 
 namespace mozilla {
 
 /**
  * Fundamental cx pushing class. All other cx pushing classes are implemented
  * in terms of this class.
  */
 class MOZ_STACK_CLASS AutoCxPusher
 {
 public:
   explicit AutoCxPusher(JSContext *aCx, bool aAllowNull = false);
-  // XPCShell uses an nsCxPusher, which contains an AutoCxPusher.
   ~AutoCxPusher();
 
   nsIScriptContext* GetScriptContext() { return mScx; }
 
   // Returns true if this AutoCxPusher performed the push that is currently at
   // the top of the cx stack.
   bool IsStackTop() const;
 
@@ -44,57 +37,16 @@ private:
   nsCOMPtr<nsIScriptContext> mScx;
   uint32_t mStackDepthAfterPush;
 #ifdef DEBUG
   JSContext* mPushedContext;
   unsigned mCompartmentDepthOnEntry;
 #endif
 };
 
-} /* namespace mozilla */
-
-/**
- * Legacy cx pushing class.
- *
- * This class provides a rather wonky interface, with the following quirks:
- *   * The constructor is a no-op, and callers must explicitly call one of
- *     the Push() methods.
- *   * Null must be pushed with PushNull().
- *   * The cx pusher can be reused multiple times with RePush().
- *
- * This class implements this interface in terms of the much simpler
- * AutoCxPusher class below.
- */
-class MOZ_STACK_CLASS nsCxPusher
-{
-public:
-  // Returns false if something erroneous happened.
-  bool Push(mozilla::dom::EventTarget *aCurrentTarget);
-  // If nothing has been pushed to stack, this works like Push.
-  // Otherwise if context will change, Pop and Push will be called.
-  bool RePush(mozilla::dom::EventTarget *aCurrentTarget);
-  // If a null JSContext is passed to Push(), that will cause no
-  // push to happen and false to be returned.
-  void Push(JSContext *cx);
-  // Explicitly push a null JSContext on the the stack
-  void PushNull();
-
-  // Pop() will be a no-op if Push() or PushNull() fail
-  void Pop();
-
-  nsIScriptContext* GetCurrentScriptContext() {
-    return mPusher.empty() ? nullptr : mPusher.ref().GetScriptContext();
-  }
-
-private:
-  mozilla::Maybe<mozilla::AutoCxPusher> mPusher;
-};
-
-namespace mozilla {
-
 /**
  * Use AutoJSContext when you need a JS context on the stack but don't have one
  * passed as a parameter. AutoJSContext will take care of finding the most
  * appropriate JS context and release it when leaving the stack.
  */
 class MOZ_STACK_CLASS AutoJSContext {
 public:
   explicit AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);