2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-11-15 11:32:39 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
// This header will be included by headers that define refpointer and array
|
|
|
|
// classes in order to specialize CC helpers such as ImplCycleCollectionTraverse
|
|
|
|
// for them.
|
|
|
|
|
|
|
|
#ifndef nsCycleCollectionNoteChild_h__
|
|
|
|
#define nsCycleCollectionNoteChild_h__
|
|
|
|
|
|
|
|
#include "nsCycleCollectionTraversalCallback.h"
|
|
|
|
#include "mozilla/Likely.h"
|
2012-11-15 11:32:39 +04:00
|
|
|
#include "mozilla/TypeTraits.h"
|
2012-11-15 11:32:39 +04:00
|
|
|
|
|
|
|
enum { CycleCollectionEdgeNameArrayFlag = 1 };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
// Just a helper for appending "[i]". Didn't want to pull in string headers
|
2018-11-30 13:46:48 +03:00
|
|
|
// here.
|
2012-11-15 11:32:39 +04:00
|
|
|
void CycleCollectionNoteEdgeNameImpl(
|
|
|
|
nsCycleCollectionTraversalCallback& aCallback, const char* aName,
|
|
|
|
uint32_t aFlags = 0);
|
|
|
|
|
|
|
|
// Should be inlined so that in the no-debug-info case this is just a simple
|
|
|
|
// if().
|
|
|
|
MOZ_ALWAYS_INLINE void CycleCollectionNoteEdgeName(
|
|
|
|
nsCycleCollectionTraversalCallback& aCallback, const char* aName,
|
|
|
|
uint32_t aFlags = 0) {
|
|
|
|
if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
|
|
|
|
CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
#define NS_CYCLE_COLLECTION_INNERCLASS cycleCollection
|
|
|
|
|
|
|
|
#define NS_CYCLE_COLLECTION_INNERNAME _cycleCollectorGlobal
|
|
|
|
|
|
|
|
#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
|
2012-12-08 09:08:37 +04:00
|
|
|
_class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()
|
2012-11-15 11:32:39 +04:00
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
template <typename T>
|
|
|
|
nsISupports* ToSupports(
|
|
|
|
T* aPtr, typename T::NS_CYCLE_COLLECTION_INNERCLASS* aDummy = 0) {
|
|
|
|
return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(aPtr);
|
2012-11-15 11:32:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The default implementation of this class template is empty, because it
|
|
|
|
// should never be used: see the partial specializations below.
|
2014-06-27 05:35:39 +04:00
|
|
|
template <typename T, bool IsXPCOM = mozilla::IsBaseOf<nsISupports, T>::value>
|
2012-11-15 11:32:39 +04:00
|
|
|
struct CycleCollectionNoteChildImpl {};
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
template <typename T>
|
2012-11-15 11:32:39 +04:00
|
|
|
struct CycleCollectionNoteChildImpl<T, true> {
|
|
|
|
static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
|
|
|
|
aCallback.NoteXPCOMChild(ToSupports(aChild));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-27 05:35:39 +04:00
|
|
|
template <typename T>
|
2012-11-15 11:32:39 +04:00
|
|
|
struct CycleCollectionNoteChildImpl<T, false> {
|
|
|
|
static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
|
|
|
|
aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Bug 1097861 - make CycleCollectionNoteChild more easily forward-declarable; r=mccr8
Forward declaring functions with default arguments is difficult. If you try to say:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags);
and then later have:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
{
...
}
the compiler complains that default arguments cannot be added to a
function template that has already been declared. If you attempt to
mollify the compiler by declaring instead:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
the compiler then complains about redefining the default argument (!)
when an actual definition is found.
To circumvent this, manually implement "default" arguments by providing
a three-argument form of CycleCollectionNoteChild, which simply forwards
to the four-argument version.
2014-11-12 23:22:32 +03:00
|
|
|
// We declare CycleCollectionNoteChild in 3-argument and 4-argument variants,
|
|
|
|
// rather than using default arguments, so that forward declarations work
|
|
|
|
// regardless of header inclusion order.
|
2014-06-27 05:35:39 +04:00
|
|
|
template <typename T>
|
|
|
|
inline void CycleCollectionNoteChild(
|
|
|
|
nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName,
|
Bug 1097861 - make CycleCollectionNoteChild more easily forward-declarable; r=mccr8
Forward declaring functions with default arguments is difficult. If you try to say:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags);
and then later have:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
{
...
}
the compiler complains that default arguments cannot be added to a
function template that has already been declared. If you attempt to
mollify the compiler by declaring instead:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
the compiler then complains about redefining the default argument (!)
when an actual definition is found.
To circumvent this, manually implement "default" arguments by providing
a three-argument form of CycleCollectionNoteChild, which simply forwards
to the four-argument version.
2014-11-12 23:22:32 +03:00
|
|
|
uint32_t aFlags) {
|
2012-11-15 11:32:39 +04:00
|
|
|
CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
|
|
|
|
CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
|
|
|
|
}
|
|
|
|
|
Bug 1097861 - make CycleCollectionNoteChild more easily forward-declarable; r=mccr8
Forward declaring functions with default arguments is difficult. If you try to say:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags);
and then later have:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
{
...
}
the compiler complains that default arguments cannot be added to a
function template that has already been declared. If you attempt to
mollify the compiler by declaring instead:
template<typename T>
inline void
CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
T* aChild, const char* aName, uint32_t aFlags = 0);
the compiler then complains about redefining the default argument (!)
when an actual definition is found.
To circumvent this, manually implement "default" arguments by providing
a three-argument form of CycleCollectionNoteChild, which simply forwards
to the four-argument version.
2014-11-12 23:22:32 +03:00
|
|
|
template <typename T>
|
|
|
|
inline void CycleCollectionNoteChild(
|
|
|
|
nsCycleCollectionTraversalCallback& aCallback, T* aChild,
|
|
|
|
const char* aName) {
|
|
|
|
CycleCollectionNoteChild(aCallback, aChild, aName, 0);
|
|
|
|
}
|
|
|
|
|
2012-11-15 11:32:39 +04:00
|
|
|
#endif // nsCycleCollectionNoteChild_h__
|