Bug 767938 part 9. Move the JSAutoRequest from AutoCxPusher to AutoJSAPI, because we're about to kill off AutoCxPusher. r=bholley

This commit is contained in:
Boris Zbarsky 2016-06-24 14:19:51 -04:00
Родитель 3fd6b57c2b
Коммит cca4d3bf70
2 изменённых файлов: 12 добавлений и 19 удалений

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

@ -309,6 +309,11 @@ AutoJSAPI::~AutoJSAPI()
JS::SetWarningReporter(JS_GetRuntime(cx()), mOldWarningReporter.value()); JS::SetWarningReporter(JS_GetRuntime(cx()), mOldWarningReporter.value());
} }
// Leave the request before popping.
if (mIsMainThread) {
mAutoRequest.reset();
}
ScriptSettingsStack::Pop(this); ScriptSettingsStack::Pop(this);
} }
@ -337,6 +342,7 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
// nsIPrincipal.Equals. Once that is removed, the Rooted<> will no longer // nsIPrincipal.Equals. Once that is removed, the Rooted<> will no longer
// be necessary. // be necessary.
JS::Rooted<JSObject*> global(JS_GetRuntime(aCx), aGlobal); JS::Rooted<JSObject*> global(JS_GetRuntime(aCx), aGlobal);
mAutoRequest.emplace(mCx);
mCxPusher.emplace(mCx); mCxPusher.emplace(mCx);
mAutoNullableCompartment.emplace(mCx, global); mAutoNullableCompartment.emplace(mCx, global);
} else { } else {
@ -781,19 +787,10 @@ danger::AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull)
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.
if (cx) {
mAutoRequest.emplace(cx);
}
} }
danger::AutoCxPusher::~AutoCxPusher() danger::AutoCxPusher::~AutoCxPusher()
{ {
// Leave the request before popping.
mAutoRequest.reset();
// 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
// haven't entered any compartment. This gets restored on Pop(), but we can // haven't entered any compartment. This gets restored on Pop(), but we can
// run into trouble if a Push/Pop are interleaved with a // run into trouble if a Push/Pop are interleaved with a

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

@ -41,7 +41,6 @@ public:
~AutoCxPusher(); ~AutoCxPusher();
private: private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
#ifdef DEBUG #ifdef DEBUG
JSContext* mPushedContext; JSContext* mPushedContext;
unsigned mCompartmentDepthOnEntry; unsigned mCompartmentDepthOnEntry;
@ -195,19 +194,15 @@ private:
* the JSContext stack. * the JSContext stack.
* * Entering an initial (possibly null) compartment, to ensure that the * * Entering an initial (possibly null) compartment, to ensure that the
* previously entered compartment for that JSContext is not used by mistake. * previously entered compartment for that JSContext is not used by mistake.
* * Reporting any exceptions left on the JSRuntime, unless the caller steals
* or silences them.
* * On main thread, entering a JSAutoRequest.
* *
* Additionally, the following duties are planned, but not yet implemented: * Additionally, the following duties are planned, but not yet implemented:
* *
* * De-poisoning the JSRuntime to allow manipulation of JSAPI. We can't * * De-poisoning the JSRuntime to allow manipulation of JSAPI. This requires
* actually implement this poisoning until all the JSContext pushing in the * implementing the poisoning first. For now, this de-poisoning
* system goes through AutoJSAPI (see bug 951991). For now, this de-poisoning
* effectively corresponds to having a non-null cx on the stack. * effectively corresponds to having a non-null cx on the stack.
* * Reporting any exceptions left on the JSRuntime, unless the caller steals
* or silences them.
* * Entering a JSAutoRequest. At present, this is handled by the cx pushing
* on the main thread, and by other code on workers. Depending on the order
* in which various cleanup lands, this may never be necessary, because
* JSAutoRequests may go away.
* *
* In situations where the consumer expects to run script, AutoEntryScript * In situations where the consumer expects to run script, AutoEntryScript
* should be used, which does additional manipulation of the script settings * should be used, which does additional manipulation of the script settings
@ -314,6 +309,7 @@ protected:
Type aType); Type aType);
private: private:
mozilla::Maybe<JSAutoRequest> mAutoRequest;
mozilla::Maybe<danger::AutoCxPusher> mCxPusher; mozilla::Maybe<danger::AutoCxPusher> mCxPusher;
mozilla::Maybe<JSAutoNullableCompartment> mAutoNullableCompartment; mozilla::Maybe<JSAutoNullableCompartment> mAutoNullableCompartment;
JSContext *mCx; JSContext *mCx;