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 186107 4e21b5c857cbc42972913c6f5767043728598def
parent 186106 feacaec8b46307db6ca68d8d5682513ab8cd2078
child 186108 95570aef1a27feec974a8b9ae321187257523bee
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(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++".
  */