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.
This commit is contained in:
Bobby Holley 2014-02-14 22:36:43 -08:00
parent e8d850c291
commit cbd65e36d6
2 changed files with 10 additions and 12 deletions

View File

@ -158,8 +158,8 @@ GetIncumbentGlobal()
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) {
@ -180,26 +180,26 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
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();
}

View File

@ -71,7 +71,7 @@ private:
/*
* A class that represents a new script entry point.
*/
class AutoEntryScript {
class AutoEntryScript : protected ScriptSettingsStackEntry {
public:
AutoEntryScript(nsIGlobalObject* aGlobalObject,
bool aIsMainThread = NS_IsMainThread(),
@ -81,7 +81,6 @@ public:
private:
dom::ScriptSettingsStack& mStack;
dom::ScriptSettingsStackEntry mEntry;
mozilla::Maybe<AutoCxPusher> mCxPusher;
mozilla::Maybe<JSAutoCompartment> mAc; // This can de-Maybe-fy when mCxPusher
// goes away.
@ -90,13 +89,12 @@ private:
/*
* 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;
};