Bug 968335 - Make Auto{Entry,Incumbent}Global inherit ScriptSettingsStackEntry. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Feb 2014 16:13:37 -0800
changeset 186075 cac7844c804d4cc288215751d8ddfffa9e217c53
parent 186074 b057716623f9d64dfc7aa77351f51d25d21aa664
child 186076 5360c2573b1124f85b24abb822ada6a0ddf70194
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs968335
milestone30.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 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(nullptr, /* aAllowNull = */ true);
--- 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++".
  */