Bug 806279 - CC macros refactoring: part 3: fold the TRAVERSE_NATIVE and AMBIGUOUS cases - r=mccr8,smaug

This commit is contained in:
Benoit Jacob 2012-11-15 02:32:39 -05:00
parent 178368032a
commit f4c1a03e74
22 changed files with 120 additions and 104 deletions

View File

@ -3947,9 +3947,8 @@ nsContentUtils::TraverseListenerManager(nsINode *aNode,
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(entry->mListenerManager,
nsEventListenerManager,
"[via hash] mListenerManager")
CycleCollectionNoteChild(cb, entry->mListenerManager.get(),
"[via hash] mListenerManager");
}
}

View File

@ -183,8 +183,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsNodeInfo)
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsNodeInfo, tmp->mRefCnt.get())
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mOwnerManager,
nsNodeInfoManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mOwnerManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNodeInfo)

View File

@ -173,7 +173,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
break;
}
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mPresContext.get(), nsPresContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

View File

@ -34,7 +34,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(AudioContext)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDestination)
// Cannot use NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR since AudioListener
// does not inherit from nsISupports.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mListener, AudioListener, "listener")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(AudioContext)

View File

@ -12,14 +12,14 @@ namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(BiquadFilterNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(BiquadFilterNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFrequency)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mQ)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGain)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrequency)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mQ)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGain)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(BiquadFilterNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mFrequency, AudioParam, "frequency value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mQ, AudioParam, "Q value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mGain, AudioParam, "gain value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrequency)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mQ)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGain)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BiquadFilterNode)

View File

@ -15,7 +15,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DelayNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDelay)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DelayNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mDelay, AudioParam, "delay value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDelay)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DelayNode)

View File

@ -20,12 +20,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DynamicsCompressorNode, AudioNod
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRelease)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DynamicsCompressorNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mThreshold, AudioParam, "threshold value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mKnee, AudioParam, "knee value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mRatio, AudioParam, "ratio value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mReduction, AudioParam, "reduction value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mAttack, AudioParam, "attack value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mRelease, AudioParam, "release value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mThreshold)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mKnee)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRatio)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReduction)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAttack)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRelease)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DynamicsCompressorNode)

View File

@ -15,7 +15,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GainNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGain)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GainNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->mGain, AudioParam, "gain value")
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGain)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GainNode)

View File

@ -1718,8 +1718,7 @@ nsBindingManager::Traverse(nsIContent *aContent,
if (binding) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mBindingTable key");
cb.NoteXPCOMChild(aContent);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(binding, nsXBLBinding,
"[via binding manager] mBindingTable value")
CycleCollectionNoteChild(cb, binding, "[via binding manager] mBindingTable value");
}
if (mContentListTable.ops &&
(value = LookupObject(mContentListTable, aContent))) {

View File

@ -427,8 +427,7 @@ TraverseKey(nsISupports* aKey, nsInsertionPointList* aData, void* aClosure)
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mInsertionPointTable key");
cb.NoteXPCOMChild(aKey);
if (aData) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(*aData, nsXBLInsertionPoint,
"mInsertionPointTable value")
ImplCycleCollectionTraverse(cb, *aData, "mInsertionPointTable value");
}
return PL_DHASH_NEXT;
}

View File

@ -341,9 +341,7 @@ TraverseInsertionPoint(nsHashKey* aKey, void* aData, void* aClosure)
*static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
nsXBLInsertionPointEntry* entry =
static_cast<nsXBLInsertionPointEntry*>(aData);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(entry,
nsXBLInsertionPointEntry,
"[insertion point table] value")
CycleCollectionNoteChild(cb, entry, "[insertion point table] value");
return kHashEnumerateNext;
}

View File

@ -1851,11 +1851,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsXULPrototypeNode)
cb.NoteXPCOMChild(name.NodeInfo());
}
}
for (i = 0; i < elem->mChildren.Length(); ++i) {
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(elem->mChildren[i].get(),
nsXULPrototypeNode,
"mChildren[i]")
}
ImplCycleCollectionTraverse(cb, elem->mChildren, "mChildren");
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

View File

@ -14,18 +14,6 @@
#include "nsWrapperCache.h"
#include "mozilla/TypeTraits.h"
inline nsISupports*
ToSupports(nsISupports *p)
{
return p;
}
inline nsISupports*
ToCanonicalSupports(nsISupports *p)
{
return NULL;
}
template <typename T>
struct qsIsNode
{

View File

@ -76,4 +76,10 @@ protected:
nsDataHashtable<nsStringHashKey, MiscContainer*> mCachedStyleAttrs;
};
inline nsISupports*
ToSupports(nsHTMLCSSStyleSheet* aPointer)
{
return static_cast<nsIStyleSheet*>(aPointer);
}
#endif /* !defined(nsHTMLCSSStyleSheet_h_) */

View File

@ -88,8 +88,7 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Length();
for (size_t i = 0; i < length; ++i) {
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
aCallback.NoteXPCOMChild(aField[i]);
CycleCollectionNoteChild(aCallback, aField[i].get(), aName, aFlags);
}
}

View File

@ -1088,8 +1088,7 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
const char* aName,
uint32_t aFlags = 0)
{
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
aCallback.NoteXPCOMChild(aField);
CycleCollectionNoteChild(aCallback, aField.get(), aName, aFlags);
}
template <class T>

View File

@ -114,7 +114,7 @@ private:
inline void
ImplCycleCollectionUnlink(nsCOMArray_base& aField)
{
aField.Clear();
aField.Clear();
}
inline void
@ -123,12 +123,11 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
const char* aName,
uint32_t aFlags = 0)
{
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
aCallback.NoteXPCOMChild(aField[i]);
}
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
CycleCollectionNoteChild(aCallback, aField[i], aName, aFlags);
}
}
@ -302,7 +301,7 @@ template <typename T>
inline void
ImplCycleCollectionUnlink(nsCOMArray<T>& aField)
{
aField.Clear();
aField.Clear();
}
template <typename E>
@ -312,12 +311,11 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
const char* aName,
uint32_t aFlags = 0)
{
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
aCallback.NoteXPCOMChild(aField[i]);
}
aFlags |= CycleCollectionEdgeNameArrayFlag;
size_t length = aField.Count();
for (size_t i = 0; i < length; ++i) {
CycleCollectionNoteChild(aCallback, aField[i], aName, aFlags);
}
}
#endif

View File

@ -1142,8 +1142,7 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
const char* aName,
uint32_t aFlags = 0)
{
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
aCallback.NoteXPCOMChild(aField);
CycleCollectionNoteChild(aCallback, aField.get(), aName, aFlags);
}
#ifndef NSCAP_FEATURE_USE_BASE

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -11,6 +11,7 @@
#include "nsCycleCollectionTraversalCallback.h"
#include "mozilla/Likely.h"
#include "mozilla/TypeTraits.h"
enum {
CycleCollectionEdgeNameArrayFlag = 1
@ -33,4 +34,55 @@ CycleCollectionNoteEdgeName(nsCycleCollectionTraversalCallback& aCallback,
}
}
#define NS_CYCLE_COLLECTION_INNERCLASS \
cycleCollection
#define NS_CYCLE_COLLECTION_INNERNAME \
_cycleCollectorGlobal
#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
_class::NS_CYCLE_COLLECTION_INNERNAME.GetParticipant()
template <typename T>
nsISupports* ToSupports(T* p, typename T::NS_CYCLE_COLLECTION_INNERCLASS* dummy = 0)
{
return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(p);
}
// 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 CycleCollectionNoteChildImpl
{
};
template <typename T>
struct CycleCollectionNoteChildImpl<T, true>
{
static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
{
aCallback.NoteXPCOMChild(ToSupports(aChild));
}
};
template <typename T>
struct CycleCollectionNoteChildImpl<T, false>
{
static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
{
aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
}
};
template <typename T>
inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild,
const char* aName,
uint32_t aFlags = 0)
{
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
}
#endif // nsCycleCollectionNoteChild_h__

View File

@ -58,7 +58,7 @@ nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s)
void
CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
const char* aName,
uint32_t aFlags = 0)
uint32_t aFlags)
{
nsAutoCString arrayEdgeName(aName);
if (aFlags & CycleCollectionEdgeNameArrayFlag) {

View File

@ -6,11 +6,7 @@
#ifndef nsCycleCollectionParticipant_h__
#define nsCycleCollectionParticipant_h__
#include "mozilla/Likely.h"
#include "mozilla/TypeTraits.h"
#include "nsCycleCollectionNoteChild.h"
#include "nsCycleCollectionTraversalCallback.h"
#define NS_CYCLECOLLECTIONPARTICIPANT_IID \
{ \
@ -256,18 +252,9 @@ public:
// Helpers for implementing a QI to nsXPCOMCycleCollectionParticipant
///////////////////////////////////////////////////////////////////////////////
#define NS_CYCLE_COLLECTION_INNERCLASS \
cycleCollection
#define NS_CYCLE_COLLECTION_CLASSNAME(_class) \
_class::NS_CYCLE_COLLECTION_INNERCLASS
#define NS_CYCLE_COLLECTION_INNERNAME \
_cycleCollectorGlobal
#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
_class::NS_CYCLE_COLLECTION_INNERNAME.GetParticipant()
#define NS_IMPL_QUERY_CYCLE_COLLECTION(_class) \
if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) { \
*aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \
@ -482,50 +469,33 @@ T* DowncastCCParticipant(void *p)
ImplCycleCollectionTraverse(cb, tmp->_field, #_field, 0);
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field) \
PR_BEGIN_MACRO \
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field); \
cb.NoteXPCOMChild(tmp->_field); \
PR_END_MACRO;
CycleCollectionNoteChild(cb, tmp->_field, #_field);
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(_field) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(_field, _base) \
PR_BEGIN_MACRO \
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field); \
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(_base*, tmp->_field)); \
PR_END_MACRO;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(_field) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(_ptr, _ptr_class, _name) \
PR_BEGIN_MACRO \
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, _name); \
cb.NoteNativeChild(_ptr, NS_CYCLE_COLLECTION_PARTICIPANT(_ptr_class)); \
PR_END_MACRO;
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_ptr)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(_field, _field_class) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->_field, _field_class, \
#_field)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(_array, _element_class, \
_name) \
{ \
uint32_t i, length = (_array).Length(); \
for (i = 0; i < length; ++i) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR((_array)[i], \
_element_class, \
_name "[i]"); \
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_array)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(_field) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_MEMBER(_field, \
_element_class) \
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(tmp->_field, _element_class, \
#_field)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(_field)
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS \
that->Trace(p, &nsScriptObjectTracer::NoteJSChild, &cb);
@ -600,7 +570,10 @@ public: \
static nsISupports* Upcast(_class *p) \
{ \
return NS_ISUPPORTS_CAST(_base*, p); \
}
} \
template <typename T> \
friend nsISupports* \
ToSupports(T* p, NS_CYCLE_COLLECTION_INNERCLASS* dummy);
#define NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base) \

View File

@ -33,6 +33,18 @@
#include "mozilla/Assertions.h"
#include "mozilla/Likely.h"
inline nsISupports*
ToSupports(nsISupports* p)
{
return p;
}
inline nsISupports*
ToCanonicalSupports(nsISupports* p)
{
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
// Macros to help detect thread-safety: