Bug 968335 - Make Auto{Entry,Incumbent}Global inherit ScriptSettingsStackEntry. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Feb 2014 22:36:43 -0800
changeset 169273 4e21b5c857cbc42972913c6f5767043728598def
parent 169272 feacaec8b46307db6ca68d8d5682513ab8cd2078
child 169274 95570aef1a27feec974a8b9ae321187257523bee
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbz
bugs968335
milestone30.0a1
Bug 968335 - Make Auto{Entry,Incumbent}Global inherit ScriptSettingsStackEntry. r=bz This will allow us to downcast from a stack entry to an AutoEntryGlobal, and thereby get at the AutoCxPusher.
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -153,18 +153,18 @@ GetIncumbentGlobal()
   // Ok, nothing from the JS engine. Let's use whatever's on the
   // explicit stack.
   return ScriptSettingsStack::Ref().IncumbentGlobal();
 }
 
 AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
                                  bool aIsMainThread,
                                  JSContext* aCx)
-  : mStack(ScriptSettingsStack::Ref())
-  , mEntry(aGlobalObject, /* aCandidate = */ true)
+  : ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true)
+  , mStack(ScriptSettingsStack::Ref())
 {
   MOZ_ASSERT(aGlobalObject);
   if (!aCx) {
     // If the caller didn't provide a cx, hunt one down. This isn't exactly
     // fast, but the callers that care about performance can pass an explicit
     // cx for now. Eventually, the whole cx pushing thing will go away
     // entirely.
     MOZ_ASSERT(aIsMainThread, "cx is mandatory off-main-thread");
@@ -175,36 +175,36 @@ AutoEntryScript::AutoEntryScript(nsIGlob
     if (!aCx) {
       aCx = nsContentUtils::GetSafeJSContext();
     }
   }
   if (aIsMainThread) {
     mCxPusher.construct(aCx);
   }
   mAc.construct(aCx, aGlobalObject->GetGlobalJSObject());
-  mStack.Push(&mEntry);
+  mStack.Push(this);
 }
 
 AutoEntryScript::~AutoEntryScript()
 {
-  MOZ_ASSERT(mStack.Incumbent() == &mEntry);
+  MOZ_ASSERT(mStack.Incumbent() == this);
   mStack.Pop();
 }
 
 AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
-  : mStack(ScriptSettingsStack::Ref())
-  , mEntry(aGlobalObject, /* aCandidate = */ false)
+  : ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ false)
+  , mStack(ScriptSettingsStack::Ref())
   , mCallerOverride(nsContentUtils::GetCurrentJSContextForThread())
 {
-  mStack.Push(&mEntry);
+  mStack.Push(this);
 }
 
 AutoIncumbentScript::~AutoIncumbentScript()
 {
-  MOZ_ASSERT(mStack.Incumbent() == &mEntry);
+  MOZ_ASSERT(mStack.Incumbent() == this);
   mStack.Pop();
 }
 
 AutoSystemCaller::AutoSystemCaller(bool aIsMainThread)
   : mStack(ScriptSettingsStack::Ref())
 {
   if (aIsMainThread) {
     mCxPusher.construct(static_cast<JSContext*>(nullptr),
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -66,42 +66,40 @@ private:
   ScriptSettingsStackEntry() : mGlobalObject(nullptr)
                              , mIsCandidateEntryPoint(true)
   {}
 };
 
 /*
  * A class that represents a new script entry point.
  */
-class AutoEntryScript {
+class AutoEntryScript : protected ScriptSettingsStackEntry {
 public:
   AutoEntryScript(nsIGlobalObject* aGlobalObject,
                   bool aIsMainThread = NS_IsMainThread(),
                   // Note: aCx is mandatory off-main-thread.
                   JSContext* aCx = nullptr);
   ~AutoEntryScript();
 
 private:
   dom::ScriptSettingsStack& mStack;
-  dom::ScriptSettingsStackEntry mEntry;
   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 {
+class AutoIncumbentScript : protected ScriptSettingsStackEntry {
 public:
   AutoIncumbentScript(nsIGlobalObject* aGlobalObject);
   ~AutoIncumbentScript();
 private:
   dom::ScriptSettingsStack& mStack;
-  dom::ScriptSettingsStackEntry mEntry;
   JS::AutoHideScriptedCaller mCallerOverride;
 };
 
 /*
  * A class used for C++ to indicate that existing entry and incumbent scripts
  * should not apply to anything in scope, and that callees should act as if
  * they were invoked "from C++".
  */