Bug 1367679. P1 - refactor InvokeCallbackMethod() to deal with one concern at a time. r=gerald

InvokeMethod() handles optional arguments.
InvokeCallbackMethod() handles optional return value.

MozReview-Commit-ID: AyT6TEKRqbs

--HG--
extra : rebase_source : 9327dfe75f4cb0a23925aaa7dd939b8a2ae1a95d
extra : intermediate-source : cc1df19154f7371bd6ab98ef490e1ad10c3c0ea9
extra : source : 719d64b06a0e9a345f402b8c721d08ff511a5c1b
This commit is contained in:
JW Wang 2017-05-26 00:12:29 +08:00
parent ac5349d7b2
commit 71260a8c0f

View File

@ -503,42 +503,42 @@ protected:
* 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;
}