Bug 1367679. P1 - refactor InvokeCallbackMethod() to deal with one concern at a time.
InvokeMethod() handles optional arguments.
InvokeCallbackMethod() handles optional return value.
MozReview-Commit-ID: AyT6TEKRqbs
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -498,52 +498,52 @@ protected:
uint32_t mMagic2 = sMagic;
#endif
};
/*
* We create two overloads for invoking Resolve/Reject Methods so as to
* make the resolve/reject value argument "optional".
*/
-
template<typename ThisType, typename MethodType, typename ValueType>
- static typename EnableIf<ReturnTypeIs<MethodType, RefPtr<MozPromise>>::value &&
- TakesArgument<MethodType>::value,
- already_AddRefed<MozPromise>>::Type
- InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
+ static typename EnableIf<
+ TakesArgument<MethodType>::value,
+ typename detail::MethodTrait<MethodType>::ReturnType>::Type
+ InvokeMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
{
- return ((*aThisVal).*aMethod)(Forward<ValueType>(aValue)).forget();
+ return (aThisVal->*aMethod)(Forward<ValueType>(aValue));
}
template<typename ThisType, typename MethodType, typename ValueType>
- static typename EnableIf<ReturnTypeIs<MethodType, void>::value &&
- TakesArgument<MethodType>::value,
- already_AddRefed<MozPromise>>::Type
- InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
+ static typename EnableIf<
+ !TakesArgument<MethodType>::value,
+ typename detail::MethodTrait<MethodType>::ReturnType>::Type
+ InvokeMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
{
- ((*aThisVal).*aMethod)(Forward<ValueType>(aValue));
- return nullptr;
+ return (aThisVal->*aMethod)();
}
template<typename ThisType, typename MethodType, typename ValueType>
- static typename EnableIf<ReturnTypeIs<MethodType, RefPtr<MozPromise>>::value &&
- !TakesArgument<MethodType>::value,
+ static typename EnableIf<ReturnTypeIs<MethodType, RefPtr<MozPromise>>::value,
already_AddRefed<MozPromise>>::Type
- InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
+ InvokeCallbackMethod(ThisType* aThisVal,
+ MethodType aMethod,
+ ValueType&& aValue)
{
- return ((*aThisVal).*aMethod)().forget();
+ return InvokeMethod(aThisVal, aMethod, Forward<ValueType>(aValue)).forget();
}
template<typename ThisType, typename MethodType, typename ValueType>
- static typename EnableIf<ReturnTypeIs<MethodType, void>::value &&
- !TakesArgument<MethodType>::value,
+ static typename EnableIf<ReturnTypeIs<MethodType, void>::value,
already_AddRefed<MozPromise>>::Type
- InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
+ InvokeCallbackMethod(ThisType* aThisVal,
+ MethodType aMethod,
+ ValueType&& aValue)
{
- ((*aThisVal).*aMethod)();
+ InvokeMethod(aThisVal, aMethod, Forward<ValueType>(aValue));
return nullptr;
}
template<typename>
class ThenCommand;
template<typename...>
class ThenValue;