From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- xpcom/base/nsCycleCollectionNoteChild.h | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 xpcom/base/nsCycleCollectionNoteChild.h (limited to 'xpcom/base/nsCycleCollectionNoteChild.h') diff --git a/xpcom/base/nsCycleCollectionNoteChild.h b/xpcom/base/nsCycleCollectionNoteChild.h new file mode 100644 index 0000000000..3e1d345aa3 --- /dev/null +++ b/xpcom/base/nsCycleCollectionNoteChild.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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" + +enum { CycleCollectionEdgeNameArrayFlag = 1 }; + +// Just a helper for appending "[i]". Didn't want to pull in string headers +// here. +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); + } +} + +#define NS_CYCLE_COLLECTION_INNERCLASS cycleCollection + +#define NS_CYCLE_COLLECTION_INNERNAME _cycleCollectorGlobal + +#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \ + _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant() + +template +nsISupports* ToSupports( + T* aPtr, typename T::NS_CYCLE_COLLECTION_INNERCLASS* aDummy = 0) { + return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(aPtr); +} + +// The default implementation of this class template is empty, because it +// should never be used: see the partial specializations below. +template ::value> +struct CycleCollectionNoteChildImpl {}; + +template +struct CycleCollectionNoteChildImpl { + static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) { + aCallback.NoteXPCOMChild(ToSupports(aChild)); + } +}; + +template +struct CycleCollectionNoteChildImpl { + static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) { + aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T)); + } +}; + +// 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. +template +inline void CycleCollectionNoteChild( + nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName, + uint32_t aFlags) { + CycleCollectionNoteEdgeName(aCallback, aName, aFlags); + CycleCollectionNoteChildImpl::Run(aCallback, aChild); +} + +template +inline void CycleCollectionNoteChild( + nsCycleCollectionTraversalCallback& aCallback, T* aChild, + const char* aName) { + CycleCollectionNoteChild(aCallback, aChild, aName, 0); +} + +#endif // nsCycleCollectionNoteChild_h__ -- cgit v1.2.3