Bug 1283855 part 3 - Make some callback setters take JSContext instead of JSRuntime. r=efaust

This commit is contained in:
Jan de Mooij 2016-07-06 11:40:20 +02:00
Родитель df019b3519
Коммит c1ed92b71b
8 изменённых файлов: 37 добавлений и 38 удалений

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

@ -11152,15 +11152,14 @@ nsGlobalWindow::ShowSlowScriptDialog()
buttonFlags += nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_2; buttonFlags += nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_2;
// Null out the operation callback while we're re-entering JS here. // Null out the operation callback while we're re-entering JS here.
JSRuntime* rt = JS_GetRuntime(cx); JSInterruptCallback old = JS_SetInterruptCallback(cx, nullptr);
JSInterruptCallback old = JS_SetInterruptCallback(rt, nullptr);
// Open the dialog. // Open the dialog.
rv = prompt->ConfirmEx(title, msg, buttonFlags, waitButton, stopButton, rv = prompt->ConfirmEx(title, msg, buttonFlags, waitButton, stopButton,
debugButton, neverShowDlg, &neverShowDlgChk, debugButton, neverShowDlg, &neverShowDlgChk,
&buttonPressed); &buttonPressed);
JS_SetInterruptCallback(rt, old); JS_SetInterruptCallback(cx, old);
if (NS_SUCCEEDED(rv) && (buttonPressed == 0)) { if (NS_SUCCEEDED(rv) && (buttonPressed == 0)) {
return neverShowDlgChk ? AlwaysContinueSlowScript : ContinueSlowScript; return neverShowDlgChk ? AlwaysContinueSlowScript : ContinueSlowScript;

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

@ -793,7 +793,7 @@ InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
return nullptr; return nullptr;
} }
JS_SetInterruptCallback(aRuntime, InterruptCallback); JS_SetInterruptCallback(workerCx, InterruptCallback);
js::SetCTypesActivityCallback(aRuntime, CTypesActivityCallback); js::SetCTypesActivityCallback(aRuntime, CTypesActivityCallback);

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

@ -4625,17 +4625,17 @@ JS_CheckForInterrupt(JSContext* cx)
} }
JS_PUBLIC_API(JSInterruptCallback) JS_PUBLIC_API(JSInterruptCallback)
JS_SetInterruptCallback(JSRuntime* rt, JSInterruptCallback callback) JS_SetInterruptCallback(JSContext* cx, JSInterruptCallback callback)
{ {
JSInterruptCallback old = rt->interruptCallback; JSInterruptCallback old = cx->interruptCallback;
rt->interruptCallback = callback; cx->interruptCallback = callback;
return old; return old;
} }
JS_PUBLIC_API(JSInterruptCallback) 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. * Promises.
*/ */
JS_PUBLIC_API(void) 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_PUBLIC_API(void)
JS::SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback, JS::SetEnqueuePromiseJobCallback(JSContext* cx, JSEnqueuePromiseJobCallback callback,
void* data /* = nullptr */) void* data /* = nullptr */)
{ {
rt->enqueuePromiseJobCallback = callback; cx->enqueuePromiseJobCallback = callback;
rt->enqueuePromiseJobCallbackData = data; cx->enqueuePromiseJobCallbackData = data;
} }
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
JS::SetPromiseRejectionTrackerCallback(JSRuntime* rt, JSPromiseRejectionTrackerCallback callback, JS::SetPromiseRejectionTrackerCallback(JSContext* cx, JSPromiseRejectionTrackerCallback callback,
void* data /* = nullptr */) void* data /* = nullptr */)
{ {
rt->promiseRejectionTrackerCallback = callback; cx->promiseRejectionTrackerCallback = callback;
rt->promiseRejectionTrackerCallbackData = data; cx->promiseRejectionTrackerCallbackData = data;
} }
JS_PUBLIC_API(JSObject*) JS_PUBLIC_API(JSObject*)

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

@ -4308,10 +4308,10 @@ JS_CheckForInterrupt(JSContext* cx);
* is disconnected before attempting such re-entry. * is disconnected before attempting such re-entry.
*/ */
extern JS_PUBLIC_API(JSInterruptCallback) extern JS_PUBLIC_API(JSInterruptCallback)
JS_SetInterruptCallback(JSRuntime* rt, JSInterruptCallback callback); JS_SetInterruptCallback(JSContext* cx, JSInterruptCallback callback);
extern JS_PUBLIC_API(JSInterruptCallback) extern JS_PUBLIC_API(JSInterruptCallback)
JS_GetInterruptCallback(JSRuntime* rt); JS_GetInterruptCallback(JSContext* cx);
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
JS_RequestInterruptCallback(JSRuntime* rt); JS_RequestInterruptCallback(JSRuntime* rt);
@ -4326,7 +4326,7 @@ namespace JS {
* See dom/base/ScriptSettings.h for details. * See dom/base/ScriptSettings.h for details.
*/ */
extern JS_PUBLIC_API(void) 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. * 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. * passed here as arguments.
*/ */
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback, SetEnqueuePromiseJobCallback(JSContext* cx, JSEnqueuePromiseJobCallback callback,
void* data = nullptr); void* data = nullptr);
/** /**
@ -4347,7 +4347,7 @@ SetEnqueuePromiseJobCallback(JSRuntime* rt, JSEnqueuePromiseJobCallback callback
* without a handler gets a handler attached. * without a handler gets a handler attached.
*/ */
extern JS_PUBLIC_API(void) extern JS_PUBLIC_API(void)
SetPromiseRejectionTrackerCallback(JSRuntime* rt, JSPromiseRejectionTrackerCallback callback, SetPromiseRejectionTrackerCallback(JSContext* cx, JSPromiseRejectionTrackerCallback callback,
void* data = nullptr); void* data = nullptr);
/** /**

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

@ -711,8 +711,7 @@ SetPromiseRejectionTrackerCallback(JSContext* cx, unsigned argc, Value* vp)
} }
GetShellRuntime(cx)->promiseRejectionTrackerCallback = args[0]; GetShellRuntime(cx)->promiseRejectionTrackerCallback = args[0];
JS::SetPromiseRejectionTrackerCallback(cx->runtime(), JS::SetPromiseRejectionTrackerCallback(cx, ForwardingPromiseRejectionTrackerCallback);
ForwardingPromiseRejectionTrackerCallback);
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE
args.rval().setUndefined(); args.rval().setUndefined();
@ -2960,8 +2959,8 @@ WorkerMain(void* arg)
#ifdef SPIDERMONKEY_PROMISE #ifdef SPIDERMONKEY_PROMISE
sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy())); sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy()));
JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback); JS::SetEnqueuePromiseJobCallback(cx, ShellEnqueuePromiseJobCallback);
JS::SetGetIncumbentGlobalCallback(rt, ShellGetIncumbentGlobalCallback); JS::SetGetIncumbentGlobalCallback(cx, ShellGetIncumbentGlobalCallback);
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE
EnvironmentPreparer environmentPreparer(cx); EnvironmentPreparer environmentPreparer(cx);
@ -2994,8 +2993,8 @@ WorkerMain(void* arg)
JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr); JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr);
#ifdef SPIDERMONKEY_PROMISE #ifdef SPIDERMONKEY_PROMISE
JS::SetGetIncumbentGlobalCallback(rt, nullptr); JS::SetGetIncumbentGlobalCallback(cx, nullptr);
JS::SetEnqueuePromiseJobCallback(rt, nullptr); JS::SetEnqueuePromiseJobCallback(cx, nullptr);
sr->jobQueue.reset(); sr->jobQueue.reset();
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE
@ -7400,7 +7399,7 @@ main(int argc, char** argv, char** envp)
JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks); JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks);
JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy); JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
JS_SetInterruptCallback(rt, ShellInterruptCallback); JS_SetInterruptCallback(cx, ShellInterruptCallback);
JS::SetBuildIdOp(cx, ShellBuildId); JS::SetBuildIdOp(cx, ShellBuildId);
JS::SetAsmJSCacheOps(cx, &asmJSCacheOps); JS::SetAsmJSCacheOps(cx, &asmJSCacheOps);
@ -7413,8 +7412,8 @@ main(int argc, char** argv, char** envp)
#ifdef SPIDERMONKEY_PROMISE #ifdef SPIDERMONKEY_PROMISE
sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy())); sr->jobQueue.init(cx, JobQueue(SystemAllocPolicy()));
JS::SetEnqueuePromiseJobCallback(rt, ShellEnqueuePromiseJobCallback); JS::SetEnqueuePromiseJobCallback(cx, ShellEnqueuePromiseJobCallback);
JS::SetGetIncumbentGlobalCallback(rt, ShellGetIncumbentGlobalCallback); JS::SetGetIncumbentGlobalCallback(cx, ShellGetIncumbentGlobalCallback);
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE
EnvironmentPreparer environmentPreparer(cx); EnvironmentPreparer environmentPreparer(cx);
@ -7446,8 +7445,8 @@ main(int argc, char** argv, char** envp)
JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr); JS::SetLargeAllocationFailureCallback(cx, nullptr, nullptr);
#ifdef SPIDERMONKEY_PROMISE #ifdef SPIDERMONKEY_PROMISE
JS::SetGetIncumbentGlobalCallback(rt, nullptr); JS::SetGetIncumbentGlobalCallback(cx, nullptr);
JS::SetEnqueuePromiseJobCallback(rt, nullptr); JS::SetEnqueuePromiseJobCallback(cx, nullptr);
sr->jobQueue.reset(); sr->jobQueue.reset();
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE

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

@ -3568,7 +3568,7 @@ XPCJSRuntime::Initialize()
#endif #endif
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback); JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
js::SetActivityCallback(cx, ActivityCallback, this); js::SetActivityCallback(cx, ActivityCallback, this);
JS_SetInterruptCallback(runtime, InterruptCallback); JS_SetInterruptCallback(cx, InterruptCallback);
js::SetWindowProxyClass(cx, &OuterWindowProxyClass); js::SetWindowProxyClass(cx, &OuterWindowProxyClass);
#ifdef MOZ_CRASHREPORTER #ifdef MOZ_CRASHREPORTER
js::AutoEnterOOMUnsafeRegion::setAnnotateOOMAllocationSizeCallback( js::AutoEnterOOMUnsafeRegion::setAnnotateOOMAllocationSizeCallback(

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

@ -1425,12 +1425,13 @@ XRE_XPCShellMain(int argc, char** argv, char** envp,
// reason to bother. // reason to bother.
sScriptedInterruptCallback = new PersistentRootedValue; sScriptedInterruptCallback = new PersistentRootedValue;
sScriptedInterruptCallback->init(rt, UndefinedValue()); sScriptedInterruptCallback->init(rt, UndefinedValue());
JS_SetInterruptCallback(rt, XPCShellInterruptCallback);
AutoJSAPI jsapi; AutoJSAPI jsapi;
jsapi.Init(); jsapi.Init();
cx = jsapi.cx(); cx = jsapi.cx();
JS_SetInterruptCallback(cx, XPCShellInterruptCallback);
argc--; argc--;
argv++; argv++;
ProcessArgsForCompartment(cx, argv, argc); ProcessArgsForCompartment(cx, argv, argc);

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

@ -547,11 +547,11 @@ CycleCollectedJSRuntime::Initialize(JSRuntime* aParentRuntime,
SetDOMCallbacks(mJSContext, &DOMcallbacks); SetDOMCallbacks(mJSContext, &DOMcallbacks);
js::SetScriptEnvironmentPreparer(mJSRuntime, &mEnvironmentPreparer); js::SetScriptEnvironmentPreparer(mJSRuntime, &mEnvironmentPreparer);
JS::SetGetIncumbentGlobalCallback(mJSRuntime, GetIncumbentGlobalCallback); JS::SetGetIncumbentGlobalCallback(mJSContext, GetIncumbentGlobalCallback);
#ifdef SPIDERMONKEY_PROMISE #ifdef SPIDERMONKEY_PROMISE
JS::SetEnqueuePromiseJobCallback(mJSRuntime, EnqueuePromiseJobCallback, this); JS::SetEnqueuePromiseJobCallback(mJSContext, EnqueuePromiseJobCallback, this);
JS::SetPromiseRejectionTrackerCallback(mJSRuntime, PromiseRejectionTrackerCallback, this); JS::SetPromiseRejectionTrackerCallback(mJSContext, PromiseRejectionTrackerCallback, this);
mUncaughtRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy())); mUncaughtRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
mConsumedRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy())); mConsumedRejections.init(mJSRuntime, JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>(js::SystemAllocPolicy()));
#endif // SPIDERMONKEY_PROMISE #endif // SPIDERMONKEY_PROMISE