/src/node/deps/v8/include/cppgc/trace-trait.h
Line  | Count  | Source  | 
1  |  | // Copyright 2020 the V8 project authors. All rights reserved.  | 
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 INCLUDE_CPPGC_TRACE_TRAIT_H_  | 
6  |  | #define INCLUDE_CPPGC_TRACE_TRAIT_H_  | 
7  |  |  | 
8  |  | #include <type_traits>  | 
9  |  |  | 
10  |  | #include "cppgc/type-traits.h"  | 
11  |  | #include "v8config.h"  // NOLINT(build/include_directory)  | 
12  |  |  | 
13  |  | namespace cppgc { | 
14  |  |  | 
15  |  | class Visitor;  | 
16  |  |  | 
17  |  | namespace internal { | 
18  |  |  | 
19  |  | class RootVisitor;  | 
20  |  |  | 
21  |  | using TraceRootCallback = void (*)(RootVisitor&, const void* object);  | 
22  |  |  | 
23  |  | // Implementation of the default TraceTrait handling GarbageCollected and  | 
24  |  | // GarbageCollectedMixin.  | 
25  |  | template <typename T,  | 
26  |  |           bool = IsGarbageCollectedMixinTypeV<std::remove_const_t<T>>>  | 
27  |  | struct TraceTraitImpl;  | 
28  |  |  | 
29  |  | }  // namespace internal  | 
30  |  |  | 
31  |  | /**  | 
32  |  |  * Callback for invoking tracing on a given object.  | 
33  |  |  *  | 
34  |  |  * \param visitor The visitor to dispatch to.  | 
35  |  |  * \param object The object to invoke tracing on.  | 
36  |  |  */  | 
37  |  | using TraceCallback = void (*)(Visitor* visitor, const void* object);  | 
38  |  |  | 
39  |  | /**  | 
40  |  |  * Describes how to trace an object, i.e., how to visit all Oilpan-relevant  | 
41  |  |  * fields of an object.  | 
42  |  |  */  | 
43  |  | struct TraceDescriptor { | 
44  |  |   /**  | 
45  |  |    * Adjusted base pointer, i.e., the pointer to the class inheriting directly  | 
46  |  |    * from GarbageCollected, of the object that is being traced.  | 
47  |  |    */  | 
48  |  |   const void* base_object_payload;  | 
49  |  |   /**  | 
50  |  |    * Callback for tracing the object.  | 
51  |  |    */  | 
52  |  |   TraceCallback callback;  | 
53  |  | };  | 
54  |  |  | 
55  |  | /**  | 
56  |  |  * Callback for getting a TraceDescriptor for a given address.  | 
57  |  |  *  | 
58  |  |  * \param address Possibly inner address of an object.  | 
59  |  |  * \returns a TraceDescriptor for the provided address.  | 
60  |  |  */  | 
61  |  | using TraceDescriptorCallback = TraceDescriptor (*)(const void* address);  | 
62  |  |  | 
63  |  | namespace internal { | 
64  |  |  | 
65  |  | struct V8_EXPORT TraceTraitFromInnerAddressImpl { | 
66  |  |   static TraceDescriptor GetTraceDescriptor(const void* address);  | 
67  |  | };  | 
68  |  |  | 
69  |  | /**  | 
70  |  |  * Trait specifying how the garbage collector processes an object of type T.  | 
71  |  |  *  | 
72  |  |  * Advanced users may override handling by creating a specialization for their  | 
73  |  |  * type.  | 
74  |  |  */  | 
75  |  | template <typename T>  | 
76  |  | struct TraceTraitBase { | 
77  |  |   static_assert(internal::IsTraceableV<T>, "T must have a Trace() method");  | 
78  |  |  | 
79  |  |   /**  | 
80  |  |    * Accessor for retrieving a TraceDescriptor to process an object of type T.  | 
81  |  |    *  | 
82  |  |    * \param self The object to be processed.  | 
83  |  |    * \returns a TraceDescriptor to process the object.  | 
84  |  |    */  | 
85  | 0  |   static TraceDescriptor GetTraceDescriptor(const void* self) { | 
86  | 0  |     return internal::TraceTraitImpl<T>::GetTraceDescriptor(  | 
87  | 0  |         static_cast<const T*>(self));  | 
88  | 0  |   }  | 
89  |  |  | 
90  |  |   /**  | 
91  |  |    * Function invoking the tracing for an object of type T.  | 
92  |  |    *  | 
93  |  |    * \param visitor The visitor to dispatch to.  | 
94  |  |    * \param self The object to invoke tracing on.  | 
95  |  |    */  | 
96  | 0  |   static void Trace(Visitor* visitor, const void* self) { | 
97  | 0  |     static_cast<const T*>(self)->Trace(visitor);  | 
98  | 0  |   } Unexecuted instantiation: cppgc::internal::TraceTraitBase<v8::Object::Wrappable>::Trace(cppgc::Visitor*, void const*) Unexecuted instantiation: cppgc::internal::TraceTraitBase<node::contextify::ContextifyContext>::Trace(cppgc::Visitor*, void const*) Unexecuted instantiation: cppgc::internal::TraceTraitBase<node::contextify::ContextifyScript>::Trace(cppgc::Visitor*, void const*)  | 
99  |  | };  | 
100  |  |  | 
101  |  | }  // namespace internal  | 
102  |  |  | 
103  |  | template <typename T>  | 
104  |  | struct TraceTrait : public internal::TraceTraitBase<T> {}; | 
105  |  |  | 
106  |  | namespace internal { | 
107  |  |  | 
108  |  | template <typename T>  | 
109  |  | struct TraceTraitImpl<T, false> { | 
110  |  |   static_assert(IsGarbageCollectedTypeV<T>,  | 
111  |  |                 "T must be of type GarbageCollected or GarbageCollectedMixin");  | 
112  |  |   static TraceDescriptor GetTraceDescriptor(const void* self) { | 
113  |  |     return {self, TraceTrait<T>::Trace}; | 
114  |  |   }  | 
115  |  | };  | 
116  |  |  | 
117  |  | template <typename T>  | 
118  |  | struct TraceTraitImpl<T, true> { | 
119  | 0  |   static TraceDescriptor GetTraceDescriptor(const void* self) { | 
120  | 0  |     return internal::TraceTraitFromInnerAddressImpl::GetTraceDescriptor(self);  | 
121  | 0  |   }  | 
122  |  | };  | 
123  |  |  | 
124  |  | }  // namespace internal  | 
125  |  | }  // namespace cppgc  | 
126  |  |  | 
127  |  | #endif  // INCLUDE_CPPGC_TRACE_TRAIT_H_  |