Bug 860085 - Rename xpc::{Push,Pop}JSContext and make them assert against DOM JSContexts. r=gabor

This commit is contained in:
Bobby Holley 2013-07-03 11:05:18 -06:00
parent 5ba2509426
commit 0886018b66
4 changed files with 23 additions and 15 deletions

View File

@ -1106,10 +1106,10 @@ void
XPCJSRuntime::CTypesActivityCallback(JSContext *cx, js::CTypesActivityType type)
{
if (type == js::CTYPES_CALLBACK_BEGIN) {
if (!Get()->GetJSContextStack()->Push(cx))
if (!xpc::PushJSContextNoScriptContext(cx))
MOZ_CRASH();
} else if (type == js::CTYPES_CALLBACK_END) {
Get()->GetJSContextStack()->Pop();
xpc::PopJSContextNoScriptContext();
}
}

View File

@ -113,15 +113,15 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) : mScriptIsRunning(fal
mScx = GetScriptContextFromJSContext(cx);
// NB: The GetDynamicScriptContext is historical and might not be sane.
if (cx && nsJSUtils::GetDynamicScriptContext(cx) &&
xpc::IsJSContextOnStack(cx))
XPCJSContextStack *stack = XPCJSRuntime::Get()->GetJSContextStack();
if (cx && nsJSUtils::GetDynamicScriptContext(cx) && stack->HasJSContext(cx))
{
// If the context is on the stack, that means that a script
// is running at the moment in the context.
mScriptIsRunning = true;
}
if (!xpc::PushJSContext(cx)) {
if (!stack->Push(cx)) {
MOZ_CRASH();
}
@ -154,7 +154,7 @@ AutoCxPusher::~AutoCxPusher()
js::GetEnterCompartmentDepth(mPushedContext));
DebugOnly<JSContext*> stackTop;
MOZ_ASSERT(mPushedContext == nsXPConnect::XPConnect()->GetCurrentJSContext());
xpc::PopJSContext();
XPCJSRuntime::Get()->GetJSContextStack()->Pop();
if (!mScriptIsRunning && mScx) {
// No JS is running in the context, but executing the event handler might have

View File

@ -1129,7 +1129,7 @@ nsXPConnect::OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,
// Push a null JSContext so that we don't see any script during
// event processing.
MOZ_ASSERT(NS_IsMainThread());
bool ok = PushJSContext(nullptr);
bool ok = PushJSContextNoScriptContext(nullptr);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
}
@ -1148,7 +1148,7 @@ nsXPConnect::AfterProcessNextEvent(nsIThreadInternal *aThread,
nsJSContext::MaybePokeCC();
nsDOMMutationObserver::HandleMutations();
PopJSContext();
PopJSContextNoScriptContext();
// If the cx stack is empty, that means we're at the an un-nested event
// loop. This is a good time to make changes to debug mode.
@ -1284,13 +1284,14 @@ nsXPConnect::GetSafeJSContext()
namespace xpc {
bool
PushJSContext(JSContext *aCx)
PushJSContextNoScriptContext(JSContext *aCx)
{
MOZ_ASSERT_IF(aCx, !GetScriptContextFromJSContext(aCx));
return XPCJSRuntime::Get()->GetJSContextStack()->Push(aCx);
}
void
PopJSContext()
PopJSContextNoScriptContext()
{
XPCJSRuntime::Get()->GetJSContextStack()->Pop();
}

View File

@ -3225,6 +3225,18 @@ struct XPCJSContextInfo {
bool savedFrameChain;
};
namespace xpc {
// These functions are used in a few places where a callback model makes it
// impossible to push a JSContext using one of our stack-scoped classes. We
// depend on those stack-scoped classes to maintain nsIScriptContext
// invariants, so these functions may only be used of the context is not
// associated with an nsJSContext/nsIScriptContext.
bool PushJSContextNoScriptContext(JSContext *aCx);
void PopJSContextNoScriptContext();
} /* namespace xpc */
class XPCJSContextStack
{
public:
@ -3870,11 +3882,6 @@ bool IsOutObject(JSContext* cx, JSObject* obj);
nsresult HasInstance(JSContext *cx, JS::HandleObject objArg, const nsID *iid, bool *bp);
// Internal use only.
bool PushJSContext(JSContext *aCx);
void PopJSContext();
bool IsJSContextOnStack(JSContext *aCx);
} // namespace xpc
/***************************************************************************/