From cca4d3bf70c5e08e70cc23eb0fd627d9efae117e Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 24 Jun 2016 14:19:51 -0400 Subject: [PATCH] Bug 767938 part 9. Move the JSAutoRequest from AutoCxPusher to AutoJSAPI, because we're about to kill off AutoCxPusher. r=bholley --- dom/base/ScriptSettings.cpp | 15 ++++++--------- dom/base/ScriptSettings.h | 16 ++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 12e96c43b4d2..222ec3d67d47 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -309,6 +309,11 @@ AutoJSAPI::~AutoJSAPI() JS::SetWarningReporter(JS_GetRuntime(cx()), mOldWarningReporter.value()); } + // Leave the request before popping. + if (mIsMainThread) { + mAutoRequest.reset(); + } + ScriptSettingsStack::Pop(this); } @@ -337,6 +342,7 @@ AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal, // nsIPrincipal.Equals. Once that is removed, the Rooted<> will no longer // be necessary. JS::Rooted global(JS_GetRuntime(aCx), aGlobal); + mAutoRequest.emplace(mCx); mCxPusher.emplace(mCx); mAutoNullableCompartment.emplace(mCx, global); } else { @@ -781,19 +787,10 @@ danger::AutoCxPusher::AutoCxPusher(JSContext* cx, bool allowNull) 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. - if (cx) { - mAutoRequest.emplace(cx); - } } 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 // haven't entered any compartment. This gets restored on Pop(), but we can // run into trouble if a Push/Pop are interleaved with a diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index 61992ccc072a..232008236e7d 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -41,7 +41,6 @@ public: ~AutoCxPusher(); private: - mozilla::Maybe mAutoRequest; #ifdef DEBUG JSContext* mPushedContext; unsigned mCompartmentDepthOnEntry; @@ -195,19 +194,15 @@ private: * the JSContext stack. * * Entering an initial (possibly null) compartment, to ensure that the * 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: * - * * De-poisoning the JSRuntime to allow manipulation of JSAPI. We can't - * actually implement this poisoning until all the JSContext pushing in the - * system goes through AutoJSAPI (see bug 951991). For now, this de-poisoning + * * De-poisoning the JSRuntime to allow manipulation of JSAPI. This requires + * implementing the poisoning first. For now, this de-poisoning * 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 * should be used, which does additional manipulation of the script settings @@ -314,6 +309,7 @@ protected: Type aType); private: + mozilla::Maybe mAutoRequest; mozilla::Maybe mCxPusher; mozilla::Maybe mAutoNullableCompartment; JSContext *mCx;