Bug 1328307. AutoNoJSAPI should make it clearer that script is not running. r=bholley

Differential Revision: https://phabricator.services.mozilla.com/D41792

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-08-23 20:47:02 +00:00
Родитель 0fa2371ff1
Коммит 8330bb9a1b
2 изменённых файлов: 29 добавлений и 4 удалений

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

@ -677,11 +677,23 @@ AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
AutoIncumbentScript::~AutoIncumbentScript() { ScriptSettingsStack::Pop(this); }
AutoNoJSAPI::AutoNoJSAPI() : ScriptSettingsStackEntry(nullptr, eNoJSAPI) {
AutoNoJSAPI::AutoNoJSAPI(JSContext* aCx)
: ScriptSettingsStackEntry(nullptr, eNoJSAPI),
JSAutoNullableRealm(aCx, nullptr),
mCx(aCx) {
// Make sure we don't seem to have an incumbent global due to
// whatever script is running right now.
JS::HideScriptedCaller(aCx);
// Make sure the fallback GetIncumbentGlobal() behavior and
// GetEntryGlobal() both return null.
ScriptSettingsStack::Push(this);
}
AutoNoJSAPI::~AutoNoJSAPI() { ScriptSettingsStack::Pop(this); }
AutoNoJSAPI::~AutoNoJSAPI() {
ScriptSettingsStack::Pop(this);
JS::UnhideScriptedCaller(mCx);
}
} // namespace dom

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

@ -407,10 +407,23 @@ class AutoIncumbentScript : protected ScriptSettingsStackEntry {
*
* This class may not be instantiated if an exception is pending.
*/
class AutoNoJSAPI : protected ScriptSettingsStackEntry {
class AutoNoJSAPI : protected ScriptSettingsStackEntry,
protected JSAutoNullableRealm {
public:
explicit AutoNoJSAPI();
AutoNoJSAPI() : AutoNoJSAPI(danger::GetJSContext()) {}
~AutoNoJSAPI();
private:
// Helper constructor to avoid doing GetJSContext() multiple times
// during construction.
explicit AutoNoJSAPI(JSContext* aCx);
// Stashed JSContext* so we don't need to GetJSContext in our destructor.
// It's probably safe to hold on to this, in the sense that the world should
// not get torn down while we're on the stack, and if it's not, we'd need to
// fix JSAutoNullableRealm to not hold on to a JSContext either, or
// something.
JSContext* mCx;
};
} // namespace dom