Bug 887334 - Add a JSAutoCompartment to AutoCxPusher. r=luke,gabor

This should hopefully take care of any cases where consumers expect to be in
the default compartment.
This commit is contained in:
Bobby Holley 2013-07-17 11:53:52 -07:00
parent e90537d5c6
commit a93493b71d
2 changed files with 15 additions and 9 deletions

View File

@ -125,24 +125,29 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) : mScriptIsRunning(fal
MOZ_CRASH();
}
// Enter a request for the duration that the cx is on the stack if non-null.
// NB: We call UnmarkGrayContext so that this can obsolete the need for the
// old XPCAutoRequest as well.
if (cx) {
mAutoRequest.construct(cx);
xpc_UnmarkGrayContext(cx);
}
#ifdef DEBUG
mPushedContext = cx;
mCompartmentDepthOnEntry = cx ? js::GetEnterCompartmentDepth(cx) : 0;
#endif
// Enter a request and a compartment for the duration that the cx is on the
// stack if non-null.
//
// NB: We call UnmarkGrayContext so that this can obsolete the need for the
// old XPCAutoRequest as well.
if (cx) {
mAutoRequest.construct(cx);
if (js::GetDefaultGlobalForContext(cx))
mAutoCompartment.construct(cx, js::GetDefaultGlobalForContext(cx));
xpc_UnmarkGrayContext(cx);
}
}
NS_EXPORT
AutoCxPusher::~AutoCxPusher()
{
// Leave the request before popping.
// Leave the compartment and request before popping.
mAutoCompartment.destroyIfConstructed();
mAutoRequest.destroyIfConstructed();
// When we push a context, we may save the frame chain and pretend like we

View File

@ -33,6 +33,7 @@ public:
private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<JSAutoCompartment> mAutoCompartment;
nsCOMPtr<nsIScriptContext> mScx;
bool mScriptIsRunning;
#ifdef DEBUG