v8
8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
trace-trait.h
Go to the documentation of this file.
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
// Implementation of the default TraceTrait handling GarbageCollected and
20
// GarbageCollectedMixin.
21
template
<
typename
T,
22
bool
=
23
IsGarbageCollectedMixinTypeV<
typename
std::remove_const<T>::type>>
24
struct
TraceTraitImpl;
25
26
}
// namespace internal
27
28
/**
29
* Callback for invoking tracing on a given object.
30
*
31
* \param visitor The visitor to dispatch to.
32
* \param object The object to invoke tracing on.
33
*/
34
using
TraceCallback =
void
(*)(
Visitor
* visitor,
const
void
* object);
35
36
/**
37
* Describes how to trace an object, i.e., how to visit all Oilpan-relevant
38
* fields of an object.
39
*/
40
struct
TraceDescriptor
{
41
/**
42
* Adjusted base pointer, i.e., the pointer to the class inheriting directly
43
* from GarbageCollected, of the object that is being traced.
44
*/
45
const
void
*
base_object_payload
;
46
/**
47
* Callback for tracing the object.
48
*/
49
TraceCallback
callback
;
50
};
51
52
namespace
internal
{
53
54
struct
V8_EXPORT
TraceTraitFromInnerAddressImpl
{
55
static
TraceDescriptor
GetTraceDescriptor
(
const
void
* address);
56
};
57
58
}
// namespace internal
59
60
/**
61
* Trait specifying how the garbage collector processes an object of type T.
62
*
63
* Advanced users may override handling by creating a specialization for their
64
* type.
65
*/
66
template
<
typename
T>
67
struct
TraceTrait
{
68
static_assert
(
internal
::IsTraceableV<T>,
"T must have a Trace() method"
);
69
70
/**
71
* Accessor for retrieving a TraceDescriptor to process an object of type T.
72
*
73
* \param self The object to be processed.
74
* \returns a TraceDescriptor to process the object.
75
*/
76
static
TraceDescriptor
GetTraceDescriptor
(
const
void
* self) {
77
return
internal
::TraceTraitImpl<T>::GetTraceDescriptor(
78
static_cast
<
const
T*>(self));
79
}
80
81
/**
82
* Function invoking the tracing for an object of type T.
83
*
84
* \param visitor The visitor to dispatch to.
85
* \param self The object to invoke tracing on.
86
*/
87
static
void
Trace
(
Visitor
* visitor,
const
void
* self) {
88
static_cast
<
const
T*>(self)->Trace(visitor);
89
}
90
};
91
92
namespace
internal
{
93
94
template
<
typename
T>
95
struct
TraceTraitImpl<T,
false
> {
96
static
TraceDescriptor
GetTraceDescriptor
(
const
void
* self) {
97
return
{self,
TraceTrait
<T>::Trace};
98
}
99
};
100
101
template
<
typename
T>
102
struct
TraceTraitImpl<T,
true
> {
103
static
TraceDescriptor
GetTraceDescriptor
(
const
void
* self) {
104
return
internal
::
TraceTraitFromInnerAddressImpl
::
GetTraceDescriptor
(
self
)
;
105
}
106
};
107
108
}
// namespace internal
109
}
// namespace cppgc
110
111
#
endif
// INCLUDE_CPPGC_TRACE_TRAIT_H_
include
cppgc
trace-trait.h
Generated on Fri Oct 29 2021 20:08:08 for v8 by
1.9.1