1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef nsCycleCollectionTraversalCallback_h__
8 #define nsCycleCollectionTraversalCallback_h__
9 
10 #include "jspubtd.h"
11 #include "js/HeapAPI.h"
12 #include "nsISupports.h"
13 
14 class nsCycleCollectionParticipant;
15 
16 class NS_NO_VTABLE nsCycleCollectionTraversalCallback
17 {
18 public:
19   // You must call DescribeRefCountedNode() with an accurate
20   // refcount, otherwise cycle collection will fail, and probably crash.
21   // If the callback cares about objname, it should put
22   // WANT_DEBUG_INFO in mFlags.
23   NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefcount,
24                                            const char* aObjName) = 0;
25   // Note, aCompartmentAddress is 0 if it is unknown.
26   NS_IMETHOD_(void) DescribeGCedNode(bool aIsMarked,
27                                      const char* aObjName,
28                                      uint64_t aCompartmentAddress = 0) = 0;
29 
30   NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild) = 0;
31   NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aThing) = 0;
32   NS_IMETHOD_(void) NoteNativeChild(void* aChild,
33                                     nsCycleCollectionParticipant* aHelper) = 0;
34 
35   // Give a name to the edge associated with the next call to
36   // NoteXPCOMChild, NoteJSObject, NoteJSScript, or NoteNativeChild.
37   // Callbacks who care about this should set WANT_DEBUG_INFO in the
38   // flags.
39   NS_IMETHOD_(void) NoteNextEdgeName(const char* aName) = 0;
40 
41   enum
42   {
43     // Values for flags:
44 
45     // Caller should call NoteNextEdgeName and pass useful objName
46     // to DescribeRefCountedNode and DescribeGCedNode.
47     WANT_DEBUG_INFO = (1 << 0),
48 
49     // Caller should not skip objects that we know will be
50     // uncollectable.
51     WANT_ALL_TRACES = (1 << 1)
52   };
Flags()53   uint32_t Flags() const { return mFlags; }
WantDebugInfo()54   bool WantDebugInfo() const { return (mFlags & WANT_DEBUG_INFO) != 0; }
WantAllTraces()55   bool WantAllTraces() const { return (mFlags & WANT_ALL_TRACES) != 0; }
56 protected:
nsCycleCollectionTraversalCallback()57   nsCycleCollectionTraversalCallback() : mFlags(0) {}
58 
59   uint32_t mFlags;
60 };
61 
62 #endif // nsCycleCollectionTraversalCallback_h__
63