diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index b1b56df35b2b..506d975c6e83 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -11152,15 +11152,14 @@ nsGlobalWindow::ShowSlowScriptDialog() buttonFlags += nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_2; // Null out the operation callback while we're re-entering JS here. - JSRuntime* rt = JS_GetRuntime(cx); - JSInterruptCallback old = JS_SetInterruptCallback(rt, nullptr); + JSInterruptCallback old = JS_SetInterruptCallback(cx, nullptr); // Open the dialog. rv = prompt->ConfirmEx(title, msg, buttonFlags, waitButton, stopButton, debugButton, neverShowDlg, &neverShowDlgChk, &buttonPressed); - JS_SetInterruptCallback(rt, old); + JS_SetInterruptCallback(cx, old); if (NS_SUCCEEDED(rv) && (buttonPressed == 0)) { return neverShowDlgChk ? AlwaysContinueSlowScript : ContinueSlowScript; diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 886ea41b1b77..91be4def722b 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -793,7 +793,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime) return nullptr; } - JS_SetInterruptCallback(aRuntime, InterruptCallback); + JS_SetInterruptCallback(workerCx, InterruptCallback); js::SetCTypesActivityCallback(aRuntime, CTypesActivityCallback); diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 8f6967e453e8..2ff85e809504 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -4625,17 +4625,17 @@ JS_CheckForInterrupt(JSContext* cx) } JS_PUBLIC_API(JSInterruptCallback) -JS_SetInterruptCallback(JSRuntime* rt, JSInterruptCallback callback) +JS_SetInterruptCallback(JSContext* cx, JSInterruptCallback callback) { - JSInterruptCallback old = rt->interruptCallback; - rt->interruptCallback = callback; + JSInterruptCallback old = cx->interruptCallback; + cx->interruptCallback = callback; return old; } JS_PUBLIC_API(JSInterruptCallback) -JS_GetInterruptCallback(JSRuntime* rt) +JS_GetInterruptCallback(JSContext* cx) { - return rt->interruptCallback; + return cx->interruptCallback; } /************************************************************************/ @@ -4644,25 +4644,25 @@ JS_GetInterruptCallback(JSRuntime* rt) * Promises. */ JS_PUBLIC_API(void) -JS::SetGetIncumbentGlobalCallback(JSRuntime* rt, JSGetIncumbentGlobalCallback callback) +JS::SetGetIncumbentGlobalCallback(JSContext* cx, JSGetIncumbentGlobalCallback callback) { - rt->getIncumbentGlobalCallback = callback; + cx->getIncumbentGlobalCallback = callback; } JS_PUBLIC_API(void) -JS::SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback, +JS::SetEnqueuePromiseJobCallback(JSContext* cx, JSEnqueuePromiseJobCallback callback, void* data /* = nullptr */) { - rt->enqueuePromiseJobCallback = callback; - rt->enqueuePromiseJobCallbackData = data; + cx->enqueuePromiseJobCallback = callback; + cx->enqueuePromiseJobCallbackData = data; } extern JS_PUBLIC_API(void) -JS::SetPromiseRejectionTrackerCallback(JSRuntime* rt, JSPromiseRejectionTrackerCallback callback, +JS::SetPromiseRejectionTrackerCallback(JSContext* cx, JSPromiseRejectionTrackerCallback callback, void* data /* = nullptr */) { - rt->promiseRejectionTrackerCallback = callback; - rt->promiseRejectionTrackerCallbackData = data; + cx->promiseRejectionTrackerCallback = callback; + cx->promiseRejectionTrackerCallbackData = data; } JS_PUBLIC_API(JSObject*) diff --git a/js/src/jsapi.h b/js/src/jsapi.h index 546759e66fc2..43ba7697cb5d 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -4308,10 +4308,10 @@ JS_CheckForInterrupt(JSContext* cx); * is disconnected before attempting such re-entry. */ extern JS_PUBLIC_API(JSInterruptCallback) -JS_SetInterruptCallback(JSRuntime* rt, JSInterruptCallback callback); +JS_SetInterruptCallback(JSContext* cx, JSInterruptCallback callback); extern JS_PUBLIC_API(JSInterruptCallback) -JS_GetInterruptCallback(JSRuntime* rt); +JS_GetInterruptCallback(JSContext* cx); extern JS_PUBLIC_API(void) JS_RequestInterruptCallback(JSRuntime* rt); @@ -4326,7 +4326,7 @@ namespace JS { * See dom/base/ScriptSettings.h for details. */ extern JS_PUBLIC_API(void) -SetGetIncumbentGlobalCallback(JSRuntime* rt, JSGetIncumbentGlobalCallback callback); +SetGetIncumbentGlobalCallback(JSContext* cx, JSGetIncumbentGlobalCallback callback); /** * Sets the callback that's invoked whenever a Promise job should be enqeued. @@ -4338,7 +4338,7 @@ SetGetIncumbentGlobalCallback(JSRuntime* rt, JSGetIncumbentGlobalCallback callba * passed here as arguments. */ extern JS_PUBLIC_API(void) -SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback, +SetEnqueuePromiseJobCallback(JSContext* cx, JSEnqueuePromiseJobCallback callback, void* data = nullptr); /** @@ -4347,7 +4347,7 @@ SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback * without a handler gets a handler attached. */ extern JS_PUBLIC_API(void) -SetPromiseRejectionTrackerCallback(JSRuntime* rt, JSPromiseRejectionTrackerCallback callback, +SetPromiseRejectionTrackerCallback(JSContext* cx, JSPromiseRejectionTrackerCallback callback, void* data = nullptr); /** diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 735b672de90a..941e1ff5aa97 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -711,8 +711,7 @@ SetPromiseRejectionTrackerCallback(JSContext* cx, unsigned argc, Value* vp) } GetShellRuntime(cx)->promiseRejectionTrackerCallback = args[0]; - JS::SetPromiseRejectionTrackerCallback(cx->runtime(), - ForwardingPromiseRejectionTrackerCallback); + JS::SetPromiseRejectionTrackerCallback(cx, ForwardingPromiseRejectionTrackerCallback); #endif // SPIDERMONKEY_PROMISE args.rval().setUndefined(); @@ -2960,8 +2959,8 @@ WorkerMain(void* arg) #ifdef SPIDERMONKEY_PROMISE sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy())); - JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback); - JS::SetGetIncumbentGlobalCallback(rt, ShellGetIncumbentGlobalCallback); + JS::SetEnqueuePromiseJobCallback(cx, ShellEnqueuePromiseJobCallback); + JS::SetGetIncumbentGlobalCallback(cx, ShellGetIncumbentGlobalCallback); #endif // SPIDERMONKEY_PROMISE EnvironmentPreparer environmentPreparer(cx); @@ -2994,8 +2993,8 @@ WorkerMain(void* arg) JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr); #ifdef SPIDERMONKEY_PROMISE - JS::SetGetIncumbentGlobalCallback(rt, nullptr); - JS::SetEnqueuePromiseJobCallback(rt, nullptr); + JS::SetGetIncumbentGlobalCallback(cx, nullptr); + JS::SetEnqueuePromiseJobCallback(cx, nullptr); sr->jobQueue.reset(); #endif // SPIDERMONKEY_PROMISE @@ -7400,7 +7399,7 @@ main(int argc, char** argv, char** envp) JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks); JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy); - JS_SetInterruptCallback(rt, ShellInterruptCallback); + JS_SetInterruptCallback(cx, ShellInterruptCallback); JS::SetBuildIdOp(cx, ShellBuildId); JS::SetAsmJSCacheOps(cx, &asmJSCacheOps); @@ -7413,8 +7412,8 @@ main(int argc, char** argv, char** envp) #ifdef SPIDERMONKEY_PROMISE sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy())); - JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback); - JS::SetGetIncumbentGlobalCallback(rt, ShellGetIncumbentGlobalCallback); + JS::SetEnqueuePromiseJobCallback(cx, ShellEnqueuePromiseJobCallback); + JS::SetGetIncumbentGlobalCallback(cx, ShellGetIncumbentGlobalCallback); #endif // SPIDERMONKEY_PROMISE EnvironmentPreparer environmentPreparer(cx); @@ -7446,8 +7445,8 @@ main(int argc, char** argv, char** envp) JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr); #ifdef SPIDERMONKEY_PROMISE - JS::SetGetIncumbentGlobalCallback(rt, nullptr); - JS::SetEnqueuePromiseJobCallback(rt, nullptr); + JS::SetGetIncumbentGlobalCallback(cx, nullptr); + JS::SetEnqueuePromiseJobCallback(cx, nullptr); sr->jobQueue.reset(); #endif // SPIDERMONKEY_PROMISE diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 9ae771f4a1b6..fc43b329f439 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -3568,7 +3568,7 @@ XPCJSRuntime::Initialize() #endif JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback); js::SetActivityCallback(cx, ActivityCallback, this); - JS_SetInterruptCallback(runtime, InterruptCallback); + JS_SetInterruptCallback(cx, InterruptCallback); js::SetWindowProxyClass(cx, &OuterWindowProxyClass); #ifdef MOZ_CRASHREPORTER js::AutoEnterOOMUnsafeRegion::setAnnotateOOMAllocationSizeCallback( diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index 247240daab2a..5502565053f8 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -1425,12 +1425,13 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, // reason to bother. sScriptedInterruptCallback = new PersistentRootedValue; sScriptedInterruptCallback->init(rt, UndefinedValue()); - JS_SetInterruptCallback(rt, XPCShellInterruptCallback); AutoJSAPI jsapi; jsapi.Init(); cx = jsapi.cx(); + JS_SetInterruptCallback(cx, XPCShellInterruptCallback); + argc--; argv++; ProcessArgsForCompartment(cx, argv, argc); diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index 03f9eafee8ee..10835eb939ff 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -547,11 +547,11 @@ CycleCollectedJSRuntime::Initialize(JSRuntime* aParentRuntime, SetDOMCallbacks(mJSContext, &DOMcallbacks); js::SetScriptEnvironmentPreparer(mJSRuntime, &mEnvironmentPreparer); - JS::SetGetIncumbentGlobalCallback(mJSRuntime, GetIncumbentGlobalCallback); + JS::SetGetIncumbentGlobalCallback(mJSContext, GetIncumbentGlobalCallback); #ifdef SPIDERMONKEY_PROMISE - JS::SetEnqueuePromiseJobCallback(mJSRuntime, EnqueuePromiseJobCallback, this); - JS::SetPromiseRejectionTrackerCallback(mJSRuntime, PromiseRejectionTrackerCallback, this); + JS::SetEnqueuePromiseJobCallback(mJSContext, EnqueuePromiseJobCallback, this); + JS::SetPromiseRejectionTrackerCallback(mJSContext, PromiseRejectionTrackerCallback, this); mUncaughtRejections.init(mJSRuntime, JS::GCVector(js::SystemAllocPolicy())); mConsumedRejections.init(mJSRuntime, JS::GCVector(js::SystemAllocPolicy())); #endif // SPIDERMONKEY_PROMISE