--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -538,27 +538,37 @@ protected:
!TakesArgument<MethodType>::value,
already_AddRefed<MozPromise>>::Type
InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
{
((*aThisVal).*aMethod)();
return nullptr;
}
- template<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
- class MethodThenValue : public ThenValueBase
+ template<typename...>
+ class ThenValue;
+
+ template<typename ThisType,
+ typename ResolveMethodType,
+ typename RejectMethodType>
+ class ThenValue<ThisType*, ResolveMethodType, RejectMethodType>
+ : public ThenValueBase
{
public:
- MethodThenValue(AbstractThread* aResponseTarget, ThisType* aThisVal,
- ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod,
- const char* aCallSite)
+ ThenValue(AbstractThread* aResponseTarget,
+ ThisType* aThisVal,
+ ResolveMethodType aResolveMethod,
+ RejectMethodType aRejectMethod,
+ const char* aCallSite)
: ThenValueBase(aResponseTarget, aCallSite)
, mThisVal(aThisVal)
, mResolveMethod(aResolveMethod)
- , mRejectMethod(aRejectMethod) {}
+ , mRejectMethod(aRejectMethod)
+ {
+ }
void Disconnect() override
{
ThenValueBase::Disconnect();
// If a Request has been disconnected, we don't guarantee that the
// resolve/reject runnable will be dispatched. Null out our refcounted
// this-value now so that it's released predictably on the dispatch thread.
@@ -587,25 +597,24 @@ protected:
}
private:
RefPtr<ThisType> mThisVal; // Only accessed and refcounted on dispatch thread.
ResolveMethodType mResolveMethod;
RejectMethodType mRejectMethod;
};
- // Specialization of MethodThenValue (with 3rd template arg being 'void')
- // that only takes one method, to be called with a ResolveOrRejectValue.
template<typename ThisType, typename ResolveRejectMethodType>
- class MethodThenValue<ThisType, ResolveRejectMethodType, void> : public ThenValueBase
+ class ThenValue<ThisType*, ResolveRejectMethodType> : public ThenValueBase
{
public:
- MethodThenValue(AbstractThread* aResponseTarget, ThisType* aThisVal,
- ResolveRejectMethodType aResolveRejectMethod,
- const char* aCallSite)
+ ThenValue(AbstractThread* aResponseTarget,
+ ThisType* aThisVal,
+ ResolveRejectMethodType aResolveRejectMethod,
+ const char* aCallSite)
: ThenValueBase(aResponseTarget, aCallSite)
, mThisVal(aThisVal)
, mResolveRejectMethod(aResolveRejectMethod)
{}
void Disconnect() override
{
ThenValueBase::Disconnect();
@@ -633,23 +642,23 @@ protected:
private:
RefPtr<ThisType> mThisVal; // Only accessed and refcounted on dispatch thread.
ResolveRejectMethodType mResolveRejectMethod;
};
// NB: We could use std::function here instead of a template if it were supported. :-(
template<typename ResolveFunction, typename RejectFunction>
- class FunctionThenValue : public ThenValueBase
+ class ThenValue<ResolveFunction, RejectFunction> : public ThenValueBase
{
public:
- FunctionThenValue(AbstractThread* aResponseTarget,
- ResolveFunction&& aResolveFunction,
- RejectFunction&& aRejectFunction,
- const char* aCallSite)
+ ThenValue(AbstractThread* aResponseTarget,
+ ResolveFunction&& aResolveFunction,
+ RejectFunction&& aRejectFunction,
+ const char* aCallSite)
: ThenValueBase(aResponseTarget, aCallSite)
{
mResolveFunction.emplace(Move(aResolveFunction));
mRejectFunction.emplace(Move(aRejectFunction));
}
void Disconnect() override
{
@@ -690,25 +699,23 @@ protected:
return completion.forget();
}
private:
Maybe<ResolveFunction> mResolveFunction; // Only accessed and deleted on dispatch thread.
Maybe<RejectFunction> mRejectFunction; // Only accessed and deleted on dispatch thread.
};
- // Specialization of FunctionThenValue (with 2nd template arg being 'void')
- // that only takes one function, to be called with a ResolveOrRejectValue.
template<typename ResolveRejectFunction>
- class FunctionThenValue<ResolveRejectFunction, void> : public ThenValueBase
+ class ThenValue<ResolveRejectFunction> : public ThenValueBase
{
public:
- FunctionThenValue(AbstractThread* aResponseTarget,
- ResolveRejectFunction&& aResolveRejectFunction,
- const char* aCallSite)
+ ThenValue(AbstractThread* aResponseTarget,
+ ResolveRejectFunction&& aResolveRejectFunction,
+ const char* aCallSite)
: ThenValueBase(aResponseTarget, aCallSite)
{
mResolveRejectFunction.emplace(Move(aResolveRejectFunction));
}
void Disconnect() override
{
ThenValueBase::Disconnect();
@@ -890,53 +897,53 @@ private:
};
public:
template<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
typename MethodThenCommand<ResolveMethodType, RejectMethodType>::type
Then(AbstractThread* aResponseThread, const char* aCallSite,
ThisType* aThisVal, ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod)
{
- using ThenType = MethodThenValue<ThisType, ResolveMethodType, RejectMethodType>;
+ using ThenType = ThenValue<ThisType*, ResolveMethodType, RejectMethodType>;
RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
aThisVal, aResolveMethod, aRejectMethod, aCallSite);
return typename MethodThenCommand<ResolveMethodType, RejectMethodType>::type(
aResponseThread, aCallSite, thenValue.forget(), this);
}
template<typename ThisType, typename ResolveRejectMethodType>
typename MethodThenCommand<ResolveRejectMethodType>::type
Then(AbstractThread* aResponseThread, const char* aCallSite,
ThisType* aThisVal, ResolveRejectMethodType aResolveRejectMethod)
{
- using ThenType = MethodThenValue<ThisType, ResolveRejectMethodType, void>;
+ using ThenType = ThenValue<ThisType*, ResolveRejectMethodType>;
RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
aThisVal, aResolveRejectMethod, aCallSite);
return typename MethodThenCommand<ResolveRejectMethodType>::type(
aResponseThread, aCallSite, thenValue.forget(), this);
}
template<typename ResolveFunction, typename RejectFunction>
typename FunctionThenCommand<ResolveFunction, RejectFunction>::type
Then(AbstractThread* aResponseThread, const char* aCallSite,
ResolveFunction&& aResolveFunction, RejectFunction&& aRejectFunction)
{
- using ThenType = FunctionThenValue<ResolveFunction, RejectFunction>;
+ using ThenType = ThenValue<ResolveFunction, RejectFunction>;
RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
Move(aResolveFunction), Move(aRejectFunction), aCallSite);
return typename FunctionThenCommand<ResolveFunction, RejectFunction>::type(
aResponseThread, aCallSite, thenValue.forget(), this);
}
template<typename ResolveRejectFunction>
typename FunctionThenCommand<ResolveRejectFunction>::type
Then(AbstractThread* aResponseThread, const char* aCallSite,
ResolveRejectFunction&& aResolveRejectFunction)
{
- using ThenType = FunctionThenValue<ResolveRejectFunction, void>;
+ using ThenType = ThenValue<ResolveRejectFunction>;
RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
Move(aResolveRejectFunction), aCallSite);
return typename FunctionThenCommand<ResolveRejectFunction>::type(
aResponseThread, aCallSite, thenValue.forget(), this);
}
void ChainTo(already_AddRefed<Private> aChainedPromise, const char* aCallSite)
{