Bug 1343335 - Add asserts to check for null AbstractThread targets in MozPromise; r=bholley

AbstractThread::GetCurrent() can return null if a thread isn't a
default AbstractThread (MainThread, etc). This doesn't get caught in
MozPromise until we try to check for reliability of dispatching on the
thread. Adding asserts to make things clearer on crashes.

MozReview-Commit-ID: AQJwpdTUiHZ
This commit is contained in:
Kyle Machulis 2017-02-28 12:26:07 -08:00
parent 6f01cb08c1
commit 27b05c3ae5

View File

@ -352,7 +352,9 @@ protected:
const char* aCallSite)
: mResponseTarget(aResponseTarget)
, mCallSite(aCallSite)
{ }
{
MOZ_ASSERT(aResponseTarget);
}
#ifdef PROMISE_DEBUG
~ThenValueBase()
@ -695,6 +697,7 @@ public:
const char* aCallSite)
{
PROMISE_ASSERT(mMagic1 == sMagic && mMagic2 == sMagic && mMagic3 == sMagic && mMagic4 == mMutex.mLock);
MOZ_ASSERT(aResponseThread);
MutexAutoLock lock(mMutex);
MOZ_ASSERT(aResponseThread->IsDispatchReliable());
MOZ_DIAGNOSTIC_ASSERT(!IsExclusive || !mHaveRequest);
@ -729,7 +732,10 @@ private:
: mResponseThread(aResponseThread)
, mCallSite(aCallSite)
, mThenValue(aThenValue)
, mReceiver(aReceiver) {}
, mReceiver(aReceiver)
{
MOZ_ASSERT(aResponseThread);
}
ThenCommand(ThenCommand&& aOther) = default;
@ -1243,6 +1249,8 @@ InvokeAsyncImpl(AbstractThread* aTarget, ThisType* aThisVal,
RefPtr<PromiseType>(ThisType::*aMethod)(ArgTypes...),
ActualArgTypes&&... aArgs)
{
MOZ_ASSERT(aTarget);
typedef RefPtr<PromiseType>(ThisType::*MethodType)(ArgTypes...);
typedef detail::MethodCall<PromiseType, MethodType, ThisType, Storages...> MethodCallType;
typedef detail::ProxyRunnable<PromiseType, MethodType, ThisType, Storages...> ProxyRunnableType;
@ -1364,6 +1372,7 @@ InvokeAsync(AbstractThread* aTarget, const char* aCallerName,
&& IsMozPromise<typename RemoveSmartPointer<
decltype(aFunction())>::Type>::value,
"Function object must return RefPtr<MozPromise>");
MOZ_ASSERT(aTarget);
typedef typename RemoveSmartPointer<decltype(aFunction())>::Type PromiseType;
typedef detail::ProxyFunctionRunnable<Function, PromiseType> ProxyRunnableType;