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
Родитель 230deafd5a
Коммит 676b2c13a5
2 изменённых файлов: 15 добавлений и 9 удалений

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

@ -125,24 +125,29 @@ AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) : mScriptIsRunning(fal
MOZ_CRASH(); 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 #ifdef DEBUG
mPushedContext = cx; mPushedContext = cx;
mCompartmentDepthOnEntry = cx ? js::GetEnterCompartmentDepth(cx) : 0; mCompartmentDepthOnEntry = cx ? js::GetEnterCompartmentDepth(cx) : 0;
#endif #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 NS_EXPORT
AutoCxPusher::~AutoCxPusher() AutoCxPusher::~AutoCxPusher()
{ {
// Leave the request before popping. // Leave the compartment and request before popping.
mAutoCompartment.destroyIfConstructed();
mAutoRequest.destroyIfConstructed(); mAutoRequest.destroyIfConstructed();
// When we push a context, we may save the frame chain and pretend like we // When we push a context, we may save the frame chain and pretend like we

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

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