From 0b0c1fec9eb1d9d0e1fabd01a4a089c5faa0b1e7 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 14 Feb 2014 22:36:43 -0800 Subject: [PATCH] Bug 968335 - Add accessors to the script settings stack entries themselves, not just the globals. r=bz --- dom/base/ScriptSettings.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 748a9a6e781..526dd29a684 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -48,24 +48,34 @@ public: 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 mStack; @@ -102,10 +112,10 @@ 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; } @@ -121,11 +131,11 @@ 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; } @@ -142,7 +152,7 @@ GetIncumbentGlobal() // 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, @@ -175,7 +185,7 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, AutoEntryScript::~AutoEntryScript() { - MOZ_ASSERT(mStack.Incumbent() == mEntry.mGlobalObject); + MOZ_ASSERT(mStack.Incumbent() == &mEntry); mStack.Pop(); } @@ -189,7 +199,7 @@ AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject) AutoIncumbentScript::~AutoIncumbentScript() { - MOZ_ASSERT(mStack.Incumbent() == mEntry.mGlobalObject); + MOZ_ASSERT(mStack.Incumbent() == &mEntry); mStack.Pop(); }