diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index cc80ade1a42a..a65381bacf6a 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -667,47 +667,50 @@ DefineWebIDLBindingPropertiesOnXPCObject(JSContext* cx, JS::Handle obj, const NativeProperties* properties); +#define HAS_MEMBER_TYPEDEFS \ +private: \ + typedef char yes[1]; \ + typedef char no[2] + #ifdef _MSC_VER #define HAS_MEMBER_CHECK(_name) \ - template static yes& Check(char (*)[(&V::_name == 0) + 1]) + template static yes& Check##_name(char (*)[(&V::_name == 0) + 1]) #else #define HAS_MEMBER_CHECK(_name) \ - template static yes& Check(char (*)[sizeof(&V::_name) + 1]) + template static yes& Check##_name(char (*)[sizeof(&V::_name) + 1]) #endif -#define HAS_MEMBER(_name) \ -template \ -class Has##_name##Member { \ - typedef char yes[1]; \ - typedef char no[2]; \ - HAS_MEMBER_CHECK(_name); \ - template static no& Check(...); \ +#define HAS_MEMBER(_memberName, _valueName) \ +private: \ + HAS_MEMBER_CHECK(_memberName); \ + template static no& Check##_memberName(...); \ \ public: \ - static bool const Value = sizeof(Check(nullptr)) == sizeof(yes); \ -}; + static bool const _valueName = \ + sizeof(Check##_memberName(nullptr)) == sizeof(yes) -HAS_MEMBER(WrapObject) - -// HasWrapObject::Value will be true if T has a WrapObject member but it's -// not nsWrapperCache::WrapObject. -template -struct HasWrapObject +template +struct NativeHasMember { -private: - typedef char yes[1]; - typedef char no[2]; - typedef JSObject* (nsWrapperCache::*WrapObject)(JSContext*, - JS::Handle); - template struct SFINAE; - template static no& Check(SFINAE*); - template static yes& Check(...); + HAS_MEMBER_TYPEDEFS; -public: - static bool const Value = HasWrapObjectMember::Value && - sizeof(Check(nullptr)) == sizeof(yes); + HAS_MEMBER(GetParentObject, GetParentObject); + HAS_MEMBER(JSBindingFinalized, JSBindingFinalized); + HAS_MEMBER(WrapObject, WrapObject); }; +template +struct IsSmartPtr +{ + HAS_MEMBER_TYPEDEFS; + + HAS_MEMBER(get, value); +}; + +#undef HAS_MEMBER +#undef HAS_MEMBER_CHECK +#undef HAS_MEMBER_TYPEDEFS + #ifdef DEBUG template ::value> struct @@ -1100,9 +1103,8 @@ HandleNewBindingWrappingFailure(JSContext* cx, JS::Handle scope, // Helper for calling HandleNewBindingWrappingFailure with smart pointers // (nsAutoPtr/nsRefPtr/nsCOMPtr) or references. -HAS_MEMBER(get) -template ::Value> +template ::value> struct HandleNewBindingWrappingFailureHelper { static inline bool Wrap(JSContext* cx, JS::Handle scope, @@ -1467,7 +1469,7 @@ struct WrapNativeParentFallback // Wrapping of our native parent, for cases when it's a WebIDL object (though // possibly preffed off). -template::Value > +template::WrapObject> struct WrapNativeParentHelper { static inline JSObject* Wrap(JSContext* cx, T* parent, nsWrapperCache* cache) @@ -1493,7 +1495,7 @@ struct WrapNativeParentHelper // Wrapping of our native parent, for cases when it's not a WebIDL object. In // this case it must be nsISupports. template -struct WrapNativeParentHelper +struct WrapNativeParentHelper { static inline JSObject* Wrap(JSContext* cx, T* parent, nsWrapperCache* cache) { @@ -1551,9 +1553,7 @@ WrapNativeParent(JSContext* cx, const T& p) return WrapNativeParent(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p)); } -HAS_MEMBER(GetParentObject) - -template::Value> +template::GetParentObject> struct GetParentObject { static JSObject* Get(JSContext* cx, JS::Handle obj) @@ -1632,7 +1632,7 @@ WrapCallThisObject>(JSContext* cx, // Helper for calling GetOrCreateDOMReflector with smart pointers // (nsAutoPtr/nsRefPtr/nsCOMPtr) or references. -template ::Value> +template ::value> struct GetOrCreateDOMReflectorHelper { static inline bool GetOrCreate(JSContext* cx, const T& value, @@ -1673,7 +1673,7 @@ GetOrCreateDOMReflector(JSContext* cx, JS::Handle scope, T& value, // Helper for calling GetOrCreateDOMReflectorNoWrap with smart pointers // (nsAutoPtr/nsRefPtr/nsCOMPtr) or references. -template ::Value> +template ::value> struct GetOrCreateDOMReflectorNoWrapHelper { static inline bool GetOrCreate(JSContext* cx, const T& value, @@ -1712,7 +1712,7 @@ GetCallbackFromCallbackObject(T* aObj) // Helper for getting the callback JSObject* of a smart ptr around a // CallbackObject or a reference to a CallbackObject or something like // that. -template ::Value> +template ::value> struct GetCallbackFromCallbackObjectHelper { static inline JSObject* Get(const T& aObj) @@ -2524,9 +2524,7 @@ MustInheritFromNonRefcountedDOMObject(NonRefcountedDOMObject*) { } -HAS_MEMBER(JSBindingFinalized) - -template::Value> +template::JSBindingFinalized> struct JSBindingFinalized { static void Finalized(T* self)