Bug 1250963 part 1. Change NotifyRunnable::Dispatch to not require a JSContext. r=khuey

The only reason NotifyRunnable::Dispatch needs a JSContext is so that it can call
ModifyBusyCount in Pre/PostDispatch.  The only reason that needs a JSContext is
to call Cancel(), which only needs it to call Notify(), which only needs it to
call NotifyPrivate, which only needs it to dispatch a NotifyRunnable.
This commit is contained in:
Boris Zbarsky 2016-02-25 16:05:39 -05:00
Родитель 25b679c83e
Коммит 239833a69f
3 изменённых файлов: 31 добавлений и 27 удалений

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

@ -2146,19 +2146,13 @@ RuntimeService::CancelWorkersForWindow(nsPIDOMWindowInner* aWindow)
GetWorkersForWindow(aWindow, workers);
if (!workers.IsEmpty()) {
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(aWindow))) {
return;
}
JSContext* cx = jsapi.cx();
for (uint32_t index = 0; index < workers.Length(); index++) {
WorkerPrivate*& worker = workers[index];
if (worker->IsSharedWorker()) {
worker->CloseSharedWorkersForWindow(aWindow);
} else if (!worker->Cancel(cx)) {
JS_ReportPendingException(cx);
} else {
worker->Cancel();
}
}
}

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

@ -847,10 +847,19 @@ public:
aStatus == Canceling || aStatus == Killing);
}
// We can be dispatched without a JSContext, because all we do with the
// JSContext passed to Dispatch() normally for worker runnables is call
// ModifyBusyCount... but that doesn't actually use its JSContext argument.
bool Dispatch()
{
return WorkerControlRunnable::Dispatch(nullptr);
}
private:
virtual bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{
aWorkerPrivate->AssertIsOnParentThread();
// Modify here, but not in PostRun! This busy count addition will be matched
// by the CloseEventRunnable.
return aWorkerPrivate->ModifyBusyCount(aCx, true);
@ -860,6 +869,7 @@ private:
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override
{
aWorkerPrivate->AssertIsOnParentThread();
if (!aDispatchResult) {
// We couldn't dispatch to the worker, which means it's already dead.
// Undo the busy count modification.
@ -2519,7 +2529,7 @@ WorkerPrivateParent<Derived>::Start()
// aCx is null when called from the finalizer
template <class Derived>
bool
WorkerPrivateParent<Derived>::NotifyPrivate(JSContext* aCx, Status aStatus)
WorkerPrivateParent<Derived>::NotifyPrivate(Status aStatus)
{
AssertIsOnParentThread();
@ -2571,7 +2581,7 @@ WorkerPrivateParent<Derived>::NotifyPrivate(JSContext* aCx, Status aStatus)
RefPtr<NotifyRunnable> runnable =
new NotifyRunnable(ParentAsWorkerPrivate(), aStatus);
return runnable->Dispatch(aCx);
return runnable->Dispatch();
}
template <class Derived>
@ -2778,7 +2788,8 @@ WorkerPrivateParent<Derived>::Close()
template <class Derived>
bool
WorkerPrivateParent<Derived>::ModifyBusyCount(JSContext* aCx, bool aIncrease)
WorkerPrivateParent<Derived>::ModifyBusyCount(JSContext* /* unused */,
bool aIncrease)
{
AssertIsOnParentThread();
@ -2797,7 +2808,7 @@ WorkerPrivateParent<Derived>::ModifyBusyCount(JSContext* aCx, bool aIncrease)
shouldCancel = mParentStatus == Terminating;
}
if (shouldCancel && !Cancel(aCx)) {
if (shouldCancel && !Cancel()) {
return false;
}
}
@ -3332,8 +3343,8 @@ WorkerPrivateParent<Derived>::CloseSharedWorkersForWindow(
if (!Freeze(cx, nullptr)) {
JS_ReportPendingException(cx);
}
} else if (!Cancel(cx)) {
JS_ReportPendingException(cx);
} else {
Cancel();
}
}
@ -3350,10 +3361,7 @@ WorkerPrivateParent<Derived>::CloseAllSharedWorkers()
mSharedWorkers.Clear();
AutoSafeJSContext cx;
if (!Cancel(cx)) {
JS_ReportPendingException(cx);
}
Cancel();
}
template <class Derived>
@ -5185,7 +5193,7 @@ WorkerPrivate::NotifyFeatures(JSContext* aCx, Status aStatus)
children.AppendElements(mChildWorkers);
for (uint32_t index = 0; index < children.Length(); index++) {
if (!children[index]->Notify(aCx, aStatus)) {
if (!children[index]->Notify(aStatus)) {
NS_WARNING("Failed to notify child worker!");
}
}

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

@ -218,13 +218,13 @@ private:
// aCx is null when called from the finalizer
bool
NotifyPrivate(JSContext* aCx, Status aStatus);
NotifyPrivate(Status aStatus);
// aCx is null when called from the finalizer
bool
TerminatePrivate(JSContext* aCx)
{
return NotifyPrivate(aCx, Terminating);
return NotifyPrivate(Terminating);
}
void
@ -282,21 +282,21 @@ public:
// Called on the parent thread.
bool
Notify(JSContext* aCx, Status aStatus)
Notify(Status aStatus)
{
return NotifyPrivate(aCx, aStatus);
return NotifyPrivate(aStatus);
}
bool
Cancel(JSContext* aCx)
Cancel()
{
return Notify(aCx, Canceling);
return Notify(Canceling);
}
bool
Kill(JSContext* aCx)
{
return Notify(aCx, Killing);
return Notify(Killing);
}
// We can assume that an nsPIDOMWindow will be available for Freeze, Thaw
@ -323,8 +323,10 @@ public:
bool
Close();
// The JSContext argument can be null, since it's not used for anything. It's
// about to go away.
bool
ModifyBusyCount(JSContext* aCx, bool aIncrease);
ModifyBusyCount(JSContext* /* unused */, bool aIncrease);
void
ForgetOverridenLoadGroup(nsCOMPtr<nsILoadGroup>& aLoadGroupOut);