Bug 968335 - Add accessors to the script settings stack entries themselves, not just the globals. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Fri, 14 Feb 2014 22:36:43 -0800
changeset 186104 ccf60cc8004bc4f7ccc6bdc874eb4453612b2d1f
parent 186103 f665d5a2292c06b7103de4773558b41242c8e263
child 186105 b4c42334f112acc44a8330bdeb098cfd1762bc41
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 - Add accessors to the script settings stack entries themselves, not just the globals. r=bz
dom/base/ScriptSettings.cpp
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -43,34 +43,44 @@ public:
     mStack.AppendElement(&ScriptSettingsStackEntry::SystemSingleton);
   }
 
   void Pop() {
     MOZ_ASSERT(mStack.Length() > 0);
     mStack.RemoveElementAt(mStack.Length() - 1);
   }
 
-  nsIGlobalObject* Incumbent() {
+  ScriptSettingsStackEntry* Incumbent() {
     if (!mStack.Length()) {
       return nullptr;
     }
-    return mStack.LastElement()->mGlobalObject;
+    return mStack.LastElement();
   }
 
-  nsIGlobalObject* EntryPoint() {
+  nsIGlobalObject* IncumbentGlobal() {
+    ScriptSettingsStackEntry *entry = Incumbent();
+    return entry ? entry->mGlobalObject : nullptr;
+  }
+
+  ScriptSettingsStackEntry* EntryPoint() {
     if (!mStack.Length())
       return nullptr;
     for (int i = mStack.Length() - 1; i >= 0; --i) {
       if (mStack[i]->mIsCandidateEntryPoint) {
-        return mStack[i]->mGlobalObject;
+        return mStack[i];
       }
     }
     MOZ_ASSUME_UNREACHABLE("Non-empty stack should always have an entry point");
   }
 
+  nsIGlobalObject* EntryGlobal() {
+    ScriptSettingsStackEntry *entry = EntryPoint();
+    return entry ? entry->mGlobalObject : nullptr;
+  }
+
 private:
   // These pointers are caller-owned.
   nsTArray<ScriptSettingsStackEntry*> mStack;
 };
 
 void
 InitScriptSettings()
 {
@@ -97,57 +107,57 @@ void DestroyScriptSettings()
 // certain edge cases. It's good enough for some purposes, but not others. If
 // you want to call this function, ping bholley and describe your use-case.
 nsIGlobalObject*
 BrokenGetEntryGlobal()
 {
   // We need the current JSContext in order to check the JS for
   // scripted frames that may have appeared since anyone last
   // manipulated the stack. If it's null, that means that there
-  // must be no entry point on the stack.
+  // must be no entry global on the stack.
   JSContext *cx = nsContentUtils::GetCurrentJSContextForThread();
   if (!cx) {
-    MOZ_ASSERT(ScriptSettingsStack::Ref().EntryPoint() == nullptr);
+    MOZ_ASSERT(ScriptSettingsStack::Ref().EntryGlobal() == nullptr);
     return nullptr;
   }
 
   return nsJSUtils::GetDynamicScriptGlobal(cx);
 }
 
 // Note: When we're ready to expose it, GetEntryGlobal will look similar to
 // GetIncumbentGlobal below.
 
 nsIGlobalObject*
 GetIncumbentGlobal()
 {
   // We need the current JSContext in order to check the JS for
   // scripted frames that may have appeared since anyone last
   // manipulated the stack. If it's null, that means that there
-  // must be no entry point on the stack, and therefore no incumbent
+  // must be no entry global on the stack, and therefore no incumbent
   // global either.
   JSContext *cx = nsContentUtils::GetCurrentJSContextForThread();
   if (!cx) {
-    MOZ_ASSERT(ScriptSettingsStack::Ref().EntryPoint() == nullptr);
+    MOZ_ASSERT(ScriptSettingsStack::Ref().EntryGlobal() == nullptr);
     return nullptr;
   }
 
   // See what the JS engine has to say. If we've got a scripted caller
   // override in place, the JS engine will lie to us and pretend that
   // there's nothing on the JS stack, which will cause us to check the
   // incumbent script stack below.
   JS::RootedScript script(cx);
   if (JS_DescribeScriptedCaller(cx, &script, nullptr)) {
     JS::RootedObject global(cx, JS_GetGlobalFromScript(script));
     MOZ_ASSERT(global);
     return xpc::GetNativeForGlobal(global);
   }
 
   // Ok, nothing from the JS engine. Let's use whatever's on the
   // explicit stack.
-  return ScriptSettingsStack::Ref().Incumbent();
+  return ScriptSettingsStack::Ref().IncumbentGlobal();
 }
 
 AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
                                  bool aIsMainThread,
                                  JSContext* aCx)
   : mStack(ScriptSettingsStack::Ref())
   , mEntry(aGlobalObject, /* aCandidate = */ true)
 {
@@ -170,31 +180,31 @@ AutoEntryScript::AutoEntryScript(nsIGlob
     mCxPusher.Push(aCx);
   }
   mAc.construct(aCx, aGlobalObject->GetGlobalJSObject());
   mStack.Push(&mEntry);
 }
 
 AutoEntryScript::~AutoEntryScript()
 {
-  MOZ_ASSERT(mStack.Incumbent() == mEntry.mGlobalObject);
+  MOZ_ASSERT(mStack.Incumbent() == &mEntry);
   mStack.Pop();
 }
 
 AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
   : mStack(ScriptSettingsStack::Ref())
   , mEntry(aGlobalObject, /* aCandidate = */ false)
   , mCallerOverride(nsContentUtils::GetCurrentJSContextForThread())
 {
   mStack.Push(&mEntry);
 }
 
 AutoIncumbentScript::~AutoIncumbentScript()
 {
-  MOZ_ASSERT(mStack.Incumbent() == mEntry.mGlobalObject);
+  MOZ_ASSERT(mStack.Incumbent() == &mEntry);
   mStack.Pop();
 }
 
 AutoSystemCaller::AutoSystemCaller(bool aIsMainThread)
   : mStack(ScriptSettingsStack::Ref())
 {
   if (aIsMainThread) {
     mCxPusher.PushNull();