Bug 1162333 - Add stronger assertions to PromiseWorkerProxy in debug builds. r=catalinb

This commit is contained in:
Jinank Jain 2015-06-11 00:35:18 +02:00
parent b58b4730d9
commit 0f8b18879b
2 changed files with 20 additions and 1 deletions

View File

@ -1481,7 +1481,7 @@ Promise::GetDependentPromises(nsTArray<nsRefPtr<Promise>>& 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;
}

View File

@ -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<ServiceWorkerClientInfo>&& aClientInfo)
{
AssertIsOnMainThread();
MutexAutoLock lock(mPromiseProxy->GetCleanUpLock());
if (mPromiseProxy->IsClean()) {
return;
}
WorkerPrivate* workerPrivate = mPromiseProxy->GetWorkerPrivate();
MOZ_ASSERT(workerPrivate);