Bug 1330693 Try to handle SW job double-completion better. r=ehsan

This commit is contained in:
Ben Kelly 2017-01-16 09:17:15 -05:00
Родитель e33311d3f7
Коммит 700a14067d
1 изменённых файлов: 23 добавлений и 13 удалений

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

@ -53,11 +53,11 @@ void
ServiceWorkerJob::AppendResultCallback(Callback* aCallback)
{
AssertIsOnMainThread();
MOZ_ASSERT(mState != State::Finished);
MOZ_ASSERT(aCallback);
MOZ_ASSERT(mFinalCallback != aCallback);
MOZ_DIAGNOSTIC_ASSERT(mState != State::Finished);
MOZ_DIAGNOSTIC_ASSERT(aCallback);
MOZ_DIAGNOSTIC_ASSERT(mFinalCallback != aCallback);
MOZ_ASSERT(!mResultCallbackList.Contains(aCallback));
MOZ_ASSERT(!mResultCallbacksInvoked);
MOZ_DIAGNOSTIC_ASSERT(!mResultCallbacksInvoked);
mResultCallbackList.AppendElement(aCallback);
}
@ -84,14 +84,14 @@ void
ServiceWorkerJob::Start(Callback* aFinalCallback)
{
AssertIsOnMainThread();
MOZ_ASSERT(!mCanceled);
MOZ_DIAGNOSTIC_ASSERT(!mCanceled);
MOZ_ASSERT(aFinalCallback);
MOZ_ASSERT(!mFinalCallback);
MOZ_DIAGNOSTIC_ASSERT(aFinalCallback);
MOZ_DIAGNOSTIC_ASSERT(!mFinalCallback);
MOZ_ASSERT(!mResultCallbackList.Contains(aFinalCallback));
mFinalCallback = aFinalCallback;
MOZ_ASSERT(mState == State::Initial);
MOZ_DIAGNOSTIC_ASSERT(mState == State::Initial);
mState = State::Started;
nsCOMPtr<nsIRunnable> runnable =
@ -155,9 +155,9 @@ void
ServiceWorkerJob::InvokeResultCallbacks(ErrorResult& aRv)
{
AssertIsOnMainThread();
MOZ_ASSERT(mState == State::Started);
MOZ_DIAGNOSTIC_ASSERT(mState == State::Started);
MOZ_ASSERT(!mResultCallbacksInvoked);
MOZ_DIAGNOSTIC_ASSERT(!mResultCallbacksInvoked);
mResultCallbacksInvoked = true;
nsTArray<RefPtr<Callback>> callbackList;
@ -187,7 +187,14 @@ void
ServiceWorkerJob::Finish(ErrorResult& aRv)
{
AssertIsOnMainThread();
MOZ_ASSERT(mState == State::Started);
// Avoid double-completion because it can result on operating on cleaned
// up data. This should not happen, though, so also assert to try to
// narrow down the causes.
MOZ_DIAGNOSTIC_ASSERT(mState == State::Started);
if (mState != State::Started) {
return;
}
// Ensure that we only surface SecurityErr, TypeErr or InvalidStateErr to script.
if (aRv.Failed() && !aRv.ErrorCodeIs(NS_ERROR_DOM_SECURITY_ERR) &&
@ -213,8 +220,11 @@ ServiceWorkerJob::Finish(ErrorResult& aRv)
mState = State::Finished;
mFinalCallback->JobFinished(this, aRv);
mFinalCallback = nullptr;
MOZ_DIAGNOSTIC_ASSERT(mFinalCallback);
if (mFinalCallback) {
mFinalCallback->JobFinished(this, aRv);
mFinalCallback = nullptr;
}
// The callback might not consume the error.
aRv.SuppressException();