Bug 806279 - CC macros refactoring: part 2: generic BEGIN_ macros folding in the NATIVE case - r=mccr8,smaug

This commit is contained in:
Benoit Jacob 2012-11-15 02:32:39 -05:00
parent 826d3b4b65
commit 178368032a
4 changed files with 52 additions and 58 deletions

View File

@ -224,7 +224,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsWrapperCache, NS_WRAPPERCACHE_IID)
nsContentUtils::TraceWrapper(tmp, aCallback, aClosure);
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
nsContentUtils::ReleaseWrapper(s, tmp);
nsContentUtils::ReleaseWrapper(static_cast<nsISupports*>(p), tmp);
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER_NATIVE \
nsContentUtils::ReleaseWrapper(tmp, tmp);

View File

@ -1182,7 +1182,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMCSSStyleRule)
// Unlink the wrapper for our declaraton. This just expands out
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
// directly because the wrapper is on the declaration, not on us.
nsContentUtils::ReleaseWrapper(s, tmp->DOMDeclaration());
nsContentUtils::ReleaseWrapper(static_cast<nsISupports*>(p), tmp->DOMDeclaration());
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMCSSStyleRule)

View File

@ -1725,7 +1725,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSFontFaceRule)
// Unlink the wrapper for our declaraton. This just expands out
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
// directly because the wrapper is on the declaration, not on us.
nsContentUtils::ReleaseWrapper(s, &tmp->mDecl);
nsContentUtils::ReleaseWrapper(static_cast<nsISupports*>(p), &tmp->mDecl);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSFontFaceRule)

View File

@ -317,6 +317,43 @@ public:
#define NS_CYCLE_COLLECTION_UPCAST(obj, clazz) \
NS_CYCLE_COLLECTION_CLASSNAME(clazz)::Upcast(obj)
// The default implementation of this class template is empty, because it
// should never be used: see the partial specializations below.
template <typename T,
bool IsXPCOM = mozilla::IsBaseOf<nsISupports, T>::value>
struct DowncastCCParticipantImpl
{
};
// Specialization for XPCOM CC participants
template <typename T>
struct DowncastCCParticipantImpl<T, true>
{
static T* Run(void *p)
{
nsISupports *s = static_cast<nsISupports*>(p);
NS_ASSERTION(NS_CYCLE_COLLECTION_CLASSNAME(T)::CheckForRightISupports(s),
"not the nsISupports pointer we expect");
return NS_CYCLE_COLLECTION_CLASSNAME(T)::Downcast(s);
}
};
// Specialization for native CC participants
template <typename T>
struct DowncastCCParticipantImpl<T, false>
{
static T* Run(void *p)
{
return static_cast<T*>(p);
}
};
template <typename T>
T* DowncastCCParticipant(void *p)
{
return DowncastCCParticipantImpl<T>::Run(p);
}
///////////////////////////////////////////////////////////////////////////////
// Helpers for implementing CanSkip methods
///////////////////////////////////////////////////////////////////////////////
@ -326,10 +363,7 @@ public:
NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipImpl(void *p, \
bool aRemovingAllowed) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s);
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END \
(void)tmp; \
@ -340,10 +374,7 @@ public:
NS_METHOD_(bool) \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipInCCImpl(void *p) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s);
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END \
(void)tmp; \
@ -354,10 +385,7 @@ public:
NS_METHOD_(bool) \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipThisImpl(void *p) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s);
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END \
(void)tmp; \
@ -372,26 +400,15 @@ public:
NS_METHOD \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s);
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class) \
NS_METHOD \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \
{ \
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = static_cast<_class*>(Downcast(s)); \
NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::UnlinkImpl(s);
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(_class) \
NS_METHOD \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::UnlinkImpl(void *p) \
{ \
_class *tmp = static_cast<_class*>(p);
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class)
#define NS_IMPL_CYCLE_COLLECTION_UNLINK(_field) \
ImplCycleCollectionUnlink(tmp->_field);
@ -440,10 +457,7 @@ public:
(NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, void *p,\
nsCycleCollectionTraversalCallback &cb) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = static_cast<_class*>(Downcast(s));
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
@ -455,19 +469,14 @@ public:
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
nsISupports *s = static_cast<nsISupports*>(p); \
if (NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::TraverseImpl(that, s, cb) \
== NS_SUCCESS_INTERRUPTED_TRAVERSE) { \
return NS_SUCCESS_INTERRUPTED_TRAVERSE; \
}
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(_class) \
NS_METHOD \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraverseImpl \
(NS_CYCLE_COLLECTION_CLASSNAME(_class) *that, void *p,\
nsCycleCollectionTraversalCallback &cb) \
{ \
_class *tmp = static_cast<_class*>(p); \
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, tmp->mRefCnt.get())
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field) \
ImplCycleCollectionTraverse(cb, tmp->_field, #_field, 0);
@ -536,32 +545,17 @@ public:
TraceCallback aCallback, \
void *aClosure) \
{ \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = Downcast(s);
_class *tmp = DowncastCCParticipant<_class >(p);
#define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(_class, _base_class) \
void \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraceImpl(void *p, \
TraceCallback aCallback, \
void *aClosure) \
{ \
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class) \
nsISupports *s = static_cast<nsISupports*>(p); \
NS_ASSERTION(CheckForRightISupports(s), \
"not the nsISupports pointer we expect"); \
_class *tmp = static_cast<_class*>(Downcast(s)); \
NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::TraceImpl(s, \
aCallback, \
aClosure);
#define NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(_class) \
void \
NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraceImpl(void *p, \
TraceCallback aCallback, \
void *aClosure) \
{ \
_class *tmp = static_cast<_class*>(p);
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class)
#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(_object, _name) \
if (_object) \