Bug 1249102. Make overrides of WorkerRunnable::PostRun a bit more consistent. r=khuey

Specifically we make the following changes:

1)  Remove WorkerSameThreadRunnable::PostRun, because it does exactly the same
things as WorkerRunnable::PostRun.

2)  Always treat ModifyBusyCountFromWorker as infallible in terms of throwing
JS exceptions.

3)  Change ExtendableFunctionalEventWorkerRunnable::PostRun to properly call
its superclass PostRun so we will correctly decrement the busy count our
PreDispatch incremented.

4)  Document why some overrides of PreDispatch/PostDispatch are needed and
don't call into the superclass
This commit is contained in:
Boris Zbarsky 2016-02-18 18:02:51 -05:00
parent 1ac0bf2b79
commit 91cf3278af
6 changed files with 32 additions and 27 deletions

View File

@ -2523,6 +2523,9 @@ public:
bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
return true;
}
@ -2530,6 +2533,9 @@ public:
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
// We don't call WorkerRunnable::PostDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
}
private:
@ -2696,6 +2702,10 @@ public:
bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on. We're on whichever thread the
// channel implementation is running on (probably the main thread or socket
// transport thread).
return true;
}
@ -2703,6 +2713,10 @@ public:
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on. We're on whichever thread the
// channel implementation is running on (probably the main thread or socket
// transport thread).
}
private:

View File

@ -375,6 +375,9 @@ protected:
bool
PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
{
// We don't call WorkerRunnable::PreDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
return true;
}
@ -382,6 +385,9 @@ protected:
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override
{
// We don't call WorkerRunnable::PostDispatch because it would assert the
// wrong thing about which thread we're on.
AssertIsOnMainThread();
}
bool

View File

@ -319,6 +319,8 @@ public:
nsCOMPtr<nsIRunnable> runnable =
new RegistrationUpdateRunnable(mRegistration, true /* time check */);
NS_DispatchToMainThread(runnable.forget());
ExtendableEventWorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult);
}
};

View File

@ -610,9 +610,7 @@ private:
WorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult);
// Match the busy count increase from NotifyRunnable.
if (!aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false)) {
JS_ReportPendingException(aCx);
}
aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false);
aWorkerPrivate->CloseHandlerFinished();
}

View File

@ -223,9 +223,7 @@ WorkerRunnable::PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
#endif
if (mBehavior == WorkerThreadModifyBusyCount) {
if (!aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false)) {
aRunResult = false;
}
aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false);
}
if (!aRunResult) {
@ -644,6 +642,9 @@ bool
WorkerSameThreadRunnable::PreDispatch(JSContext* aCx,
WorkerPrivate* aWorkerPrivate)
{
// We don't call WorkerRunnable::PreDispatch, because we're using
// WorkerThreadModifyBusyCount for mBehavior, and WorkerRunnable will assert
// that PreDispatch is on the parent thread in that case.
aWorkerPrivate->AssertIsOnWorkerThread();
return true;
}
@ -653,6 +654,9 @@ WorkerSameThreadRunnable::PostDispatch(JSContext* aCx,
WorkerPrivate* aWorkerPrivate,
bool aDispatchResult)
{
// We don't call WorkerRunnable::PostDispatch, because we're using
// WorkerThreadModifyBusyCount for mBehavior, and WorkerRunnable will assert
// that PostDispatch is on the parent thread in that case.
aWorkerPrivate->AssertIsOnWorkerThread();
if (aDispatchResult) {
DebugOnly<bool> willIncrement = aWorkerPrivate->ModifyBusyCountFromWorker(aCx, true);
@ -661,21 +665,3 @@ WorkerSameThreadRunnable::PostDispatch(JSContext* aCx,
MOZ_ASSERT(willIncrement);
}
}
void
WorkerSameThreadRunnable::PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aRunResult)
{
MOZ_ASSERT(aCx);
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
DebugOnly<bool> willDecrement = aWorkerPrivate->ModifyBusyCountFromWorker(aCx, false);
MOZ_ASSERT(willDecrement);
if (!aRunResult) {
JS_ReportPendingException(aCx);
}
}

View File

@ -405,9 +405,8 @@ protected:
PostDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aDispatchResult) override;
virtual void
PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
bool aRunResult) override;
// We just delegate PostRun to WorkerRunnable, since it does exactly
// what we want.
};
// Base class for the runnable objects, which makes a synchronous call to