From 0f8b18879bc109e02e096743e1ee195abba96dae Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Thu, 11 Jun 2015 00:35:18 +0200 Subject: [PATCH] Bug 1162333 - Add stronger assertions to PromiseWorkerProxy in debug builds. r=catalinb --- dom/promise/Promise.cpp | 14 +++++++++++++- dom/workers/ServiceWorkerWindowClient.cpp | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index 73faadc38a0..96a06900831 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -1481,7 +1481,7 @@ Promise::GetDependentPromises(nsTArray>& aPromises) } // A WorkerRunnable to resolve/reject the Promise on the worker thread. - +// Calling thread MUST hold PromiseWorkerProxy's mutex before creating this. class PromiseWorkerProxyRunnable : public workers::WorkerRunnable { public: @@ -1589,12 +1589,24 @@ PromiseWorkerProxy::GetWorkerPrivate() const // the assertion when we should not. MOZ_ASSERT(!mCleanedUp); +#ifdef DEBUG + if (NS_IsMainThread()) { + mCleanUpLock.AssertCurrentThreadOwns(); + } +#endif + return mWorkerPrivate; } Promise* PromiseWorkerProxy::GetWorkerPromise() const { + +#ifdef DEBUG + WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); + MOZ_ASSERT(worker); + worker->AssertIsOnWorkerThread(); +#endif return mWorkerPromise; } diff --git a/dom/workers/ServiceWorkerWindowClient.cpp b/dom/workers/ServiceWorkerWindowClient.cpp index 346903c3860..7b0cede4b90 100644 --- a/dom/workers/ServiceWorkerWindowClient.cpp +++ b/dom/workers/ServiceWorkerWindowClient.cpp @@ -7,6 +7,7 @@ #include "ServiceWorkerWindowClient.h" +#include "mozilla/Mutex.h" #include "mozilla/dom/ClientBinding.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" @@ -108,6 +109,12 @@ private: void DispatchResult(UniquePtr&& aClientInfo) { + AssertIsOnMainThread(); + MutexAutoLock lock(mPromiseProxy->GetCleanUpLock()); + if (mPromiseProxy->IsClean()) { + return; + } + WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate(); MOZ_ASSERT(workerPrivate);