Bug 968335 - Add an API to determine if a given AutoCxPusher corresponds to the stack-top cx push. r=bz

This patch, and those following, are part of an epic quest to make this API
work properly despite the fact that we don't yet have GetEntryGlobal. See
the comment a few patches forward.
This commit is contained in:
Bobby Holley 2014-02-14 16:13:37 -08:00
Родитель acdc754107
Коммит 4a944caaf5
2 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -115,6 +115,7 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull)
if (!stack->Push(cx)) {
MOZ_CRASH();
}
mStackDepthAfterPush = stack->Count();
#ifdef DEBUG
mPushedContext = cx;
@ -163,6 +164,14 @@ AutoCxPusher::~AutoCxPusher()
mScx = nullptr;
}
bool
AutoCxPusher::IsStackTop()
{
uint32_t currentDepth = XPCJSRuntime::Get()->GetJSContextStack()->Count();
MOZ_ASSERT(currentDepth >= mStackDepthAfterPush);
return currentDepth == mStackDepthAfterPush;
}
AutoJSContext::AutoJSContext(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_IN_IMPL)
: mCx(nullptr)
{

Просмотреть файл

@ -31,10 +31,15 @@ public:
nsIScriptContext* GetScriptContext() { return mScx; }
// Returns true if this AutoCxPusher performed the push that is currently at
// the top of the cx stack.
bool IsStackTop();
private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<JSAutoCompartment> mAutoCompartment;
nsCOMPtr<nsIScriptContext> mScx;
uint32_t mStackDepthAfterPush;
#ifdef DEBUG
JSContext* mPushedContext;
unsigned mCompartmentDepthOnEntry;