Bug 1541600 part 2. Stop using AutoJSContext for the slow script dialog. r=mccr8

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-04-04 20:00:36 +00:00
Родитель 11f24f599a
Коммит 8b2ada715e
3 изменённых файлов: 9 добавлений и 8 удалений

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

@ -4537,9 +4537,9 @@ void nsGlobalWindowInner::FireOfflineStatusEventIfChanged() {
}
nsGlobalWindowInner::SlowScriptResponse
nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
nsGlobalWindowInner::ShowSlowScriptDialog(JSContext* aCx,
const nsString& aAddonId) {
nsresult rv;
AutoJSContext cx;
if (Preferences::GetBool("dom.always_stop_slow_scripts")) {
return KillSlowScript;
@ -4549,7 +4549,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
// (since that spins the event loop). In that (rare) case, we just kill the
// script and report a warning.
if (!nsContentUtils::IsSafeToRunScript()) {
JS_ReportWarningASCII(cx, "A long running script was terminated");
JS_ReportWarningASCII(aCx, "A long running script was terminated");
return KillSlowScript;
}
@ -4568,7 +4568,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
// minified scripts which is more common in Web content that is loaded in the
// content process.
unsigned* linenop = XRE_IsParentProcess() ? &lineno : nullptr;
bool hasFrame = JS::DescribeScriptedCaller(cx, &filename, linenop);
bool hasFrame = JS::DescribeScriptedCaller(aCx, &filename, linenop);
// Record the slow script event if we haven't done so already for this inner
// window (which represents a particular page to the user).
@ -4737,7 +4737,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
int32_t buttonPressed = 0; // In case the user exits dialog by clicking X.
{
// Null out the operation callback while we're re-entering JS here.
AutoDisableJSInterruptCallback disabler(cx);
AutoDisableJSInterruptCallback disabler(aCx);
// Open the dialog.
rv = prompt->ConfirmEx(
@ -4758,7 +4758,7 @@ nsGlobalWindowInner::ShowSlowScriptDialog(const nsString& aAddonId) {
return NS_SUCCEEDED(rv) ? ContinueSlowScript : KillSlowScript;
}
JS_ClearPendingException(cx);
JS_ClearPendingException(aCx);
if (checkboxValue && isAddonScript) return KillScriptGlobal;
return KillSlowScript;

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

@ -467,7 +467,8 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
KillSlowScript,
KillScriptGlobal
};
SlowScriptResponse ShowSlowScriptDialog(const nsString& aAddonId);
SlowScriptResponse ShowSlowScriptDialog(JSContext* aCx,
const nsString& aAddonId);
// Inner windows only.
void AddGamepad(uint32_t aIndex, mozilla::dom::Gamepad* aGamepad);

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

@ -700,7 +700,7 @@ bool XPCJSContext::InterruptCallback(JSContext* cx) {
// Show the prompt to the user, and kill if requested.
nsGlobalWindowInner::SlowScriptResponse response =
win->ShowSlowScriptDialog(addonId);
win->ShowSlowScriptDialog(cx, addonId);
if (response == nsGlobalWindowInner::KillSlowScript) {
if (Preferences::GetBool("dom.global_stop_script", true)) {
xpc::Scriptability::Get(global).Block();