xref: /aosp_15_r20/external/pdfium/fxjs/gc/gced_tree_node_mixin.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2020 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FXJS_GC_GCED_TREE_NODE_MIXIN_H_
6 #define FXJS_GC_GCED_TREE_NODE_MIXIN_H_
7 
8 #include "core/fxcrt/tree_node.h"
9 #include "v8/include/cppgc/garbage-collected.h"
10 #include "v8/include/cppgc/member.h"
11 #include "v8/include/cppgc/visitor.h"
12 
13 namespace fxjs {
14 
15 // For DOM/XML-ish trees, where references outside the tree are Persistent<>,
16 // usable by classes that are already garbage collected themselves.
17 template <typename T>
18 class GCedTreeNodeMixin : public cppgc::GarbageCollectedMixin,
19                           public fxcrt::TreeNodeBase<T> {
20  public:
Trace(cppgc::Visitor * visitor)21   virtual void Trace(cppgc::Visitor* visitor) const {
22     visitor->Trace(m_pParent);
23     visitor->Trace(m_pFirstChild);
24     visitor->Trace(m_pLastChild);
25     visitor->Trace(m_pNextSibling);
26     visitor->Trace(m_pPrevSibling);
27   }
28 
29  protected:
30   GCedTreeNodeMixin() = default;
31   GCedTreeNodeMixin(const GCedTreeNodeMixin& that) = delete;
32   GCedTreeNodeMixin& operator=(const GCedTreeNodeMixin& that) = delete;
33 
34  private:
35   friend class fxcrt::TreeNodeBase<T>;
36 
37   cppgc::Member<T> m_pParent;
38   cppgc::Member<T> m_pFirstChild;
39   cppgc::Member<T> m_pLastChild;
40   cppgc::Member<T> m_pNextSibling;
41   cppgc::Member<T> m_pPrevSibling;
42 };
43 
44 }  // namespace fxjs
45 
46 using fxjs::GCedTreeNodeMixin;
47 
48 #endif  // FXJS_GC_GCED_TREE_NODE_MIXIN_H_
49