Bug 968335 - Use an AutoCxPusher directly in Auto{Entry,Incumbent}Global. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Feb 2014 22:36:43 -0800
changeset 169272 feacaec8b46307db6ca68d8d5682513ab8cd2078
parent 169271 b4c42334f112acc44a8330bdeb098cfd1762bc41
child 169273 4e21b5c857cbc42972913c6f5767043728598def
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbz
bugs968335
milestone30.0a1
Bug 968335 - Use an AutoCxPusher directly in Auto{Entry,Incumbent}Global. r=bz This will let us ask whether the AutoCxPusher is stack-top.
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -172,17 +172,17 @@ AutoEntryScript::AutoEntryScript(nsIGlob
     if (sgo && sgo->GetScriptContext()) {
       aCx = sgo->GetScriptContext()->GetNativeContext();
     }
     if (!aCx) {
       aCx = nsContentUtils::GetSafeJSContext();
     }
   }
   if (aIsMainThread) {
-    mCxPusher.Push(aCx);
+    mCxPusher.construct(aCx);
   }
   mAc.construct(aCx, aGlobalObject->GetGlobalJSObject());
   mStack.Push(&mEntry);
 }
 
 AutoEntryScript::~AutoEntryScript()
 {
   MOZ_ASSERT(mStack.Incumbent() == &mEntry);
@@ -202,17 +202,18 @@ AutoIncumbentScript::~AutoIncumbentScrip
   MOZ_ASSERT(mStack.Incumbent() == &mEntry);
   mStack.Pop();
 }
 
 AutoSystemCaller::AutoSystemCaller(bool aIsMainThread)
   : mStack(ScriptSettingsStack::Ref())
 {
   if (aIsMainThread) {
-    mCxPusher.PushNull();
+    mCxPusher.construct(static_cast<JSContext*>(nullptr),
+                        /* aAllowNull = */ true);
   }
   mStack.PushSystem();
 }
 
 AutoSystemCaller::~AutoSystemCaller()
 {
   mStack.Pop();
 }
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -77,17 +77,17 @@ public:
                   bool aIsMainThread = NS_IsMainThread(),
                   // Note: aCx is mandatory off-main-thread.
                   JSContext* aCx = nullptr);
   ~AutoEntryScript();
 
 private:
   dom::ScriptSettingsStack& mStack;
   dom::ScriptSettingsStackEntry mEntry;
-  nsCxPusher mCxPusher;
+  mozilla::Maybe<AutoCxPusher> mCxPusher;
   mozilla::Maybe<JSAutoCompartment> mAc; // This can de-Maybe-fy when mCxPusher
                                          // goes away.
 };
 
 /*
  * A class that can be used to force a particular incumbent script on the stack.
  */
 class AutoIncumbentScript {
@@ -106,15 +106,15 @@ private:
  * they were invoked "from C++".
  */
 class AutoSystemCaller {
 public:
   AutoSystemCaller(bool aIsMainThread = NS_IsMainThread());
   ~AutoSystemCaller();
 private:
   dom::ScriptSettingsStack& mStack;
-  nsCxPusher mCxPusher;
+  mozilla::Maybe<AutoCxPusher> mCxPusher;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ScriptSettings_h