Bug 809715 - Use MFBT's IsBaseOf to simplify QS_IS_NODE - r=ehsan

This commit is contained in:
Benoit Jacob 2012-11-07 21:33:31 -05:00
parent 46b2cf4f52
commit 4dbcec42c7

View File

@ -12,6 +12,7 @@
#include "nsIDOMNode.h"
#include "nsINode.h"
#include "nsWrapperCache.h"
#include "mozilla/TypeTraits.h"
inline nsISupports*
ToSupports(nsISupports *p)
@ -25,40 +26,14 @@ ToCanonicalSupports(nsISupports *p)
return NULL;
}
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2) || \
_MSC_FULL_VER >= 140050215
/* Use a compiler intrinsic if one is available. */
#define QS_CASTABLE_TO(_interface, _class) __is_base_of(_interface, _class)
#else
/* The generic version of this predicate relies on the overload resolution
* rules. If |_class| inherits from |_interface|, the |_interface*|
* overload of DOMCI_CastableTo<_interface>::p() will be chosen, otherwise
* the |void*| overload will be chosen. There is no definition of these
* functions; we determine which overload was selected by inspecting the
* size of the return type.
*/
template <typename Interface> struct QS_CastableTo {
struct false_type { int x[1]; };
struct true_type { int x[2]; };
static false_type p(void*);
static true_type p(Interface*);
template <typename T>
struct qsIsNode
{
static const bool value =
mozilla::IsBaseOf<nsINode, T>::value ||
mozilla::IsBaseOf<nsIDOMNode, T>::value;
};
#define QS_CASTABLE_TO(_interface, _class) \
(sizeof(QS_CastableTo<_interface>::p(static_cast<_class*>(0))) == \
sizeof(QS_CastableTo<_interface>::true_type))
#endif
#define QS_IS_NODE(_class) \
QS_CASTABLE_TO(nsINode, _class) || \
QS_CASTABLE_TO(nsIDOMNode, _class)
class qsObjectHelper : public xpcObjectHelper
{
public:
@ -66,7 +41,7 @@ public:
inline
qsObjectHelper(T *aObject, nsWrapperCache *aCache)
: xpcObjectHelper(ToSupports(aObject), ToCanonicalSupports(aObject),
aCache, QS_IS_NODE(T))
aCache, qsIsNode<T>::value)
{}
template <class T>
@ -74,7 +49,7 @@ public:
qsObjectHelper(nsCOMPtr<T>& aObject, nsWrapperCache *aCache)
: xpcObjectHelper(ToSupports(aObject.get()),
ToCanonicalSupports(aObject.get()), aCache,
QS_IS_NODE(T))
qsIsNode<T>::value)
{
if (mCanonical) {
// Transfer the strong reference.
@ -88,7 +63,7 @@ public:
qsObjectHelper(nsRefPtr<T>& aObject, nsWrapperCache *aCache)
: xpcObjectHelper(ToSupports(aObject.get()),
ToCanonicalSupports(aObject.get()), aCache,
QS_IS_NODE(T))
qsIsNode<T>::value)
{
if (mCanonical) {
// Transfer the strong reference.