Bug 1367679. P1 - refactor InvokeCallbackMethod() to deal with one concern at a time. r=gerald
authorJW Wang <jwwang@mozilla.com>
Fri, 26 May 2017 00:12:29 +0800
changeset 412768 715ef330d2d49ea52e292efbd856de61de7d73b5
parent 412767 69601a67ea2cd87b175e58afa106eccb16596c70
child 412769 e9ec33eda9087943a17a608287c4c4b2fa92ff26
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1367679
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
xpcom/threads/MozPromise.h
--- 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;