V8
latest master commit
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
#include "
cppgc/type-traits.h
"
10
11
namespace
cppgc
{
12
13
class
Visitor;
14
15
namespace
internal {
16
17
template
<
typename
T,
18
bool
=
19
IsGarbageCollectedMixinTypeV<typename std::remove_const<T>::type>>
20
struct
TraceTraitImpl
;
21
22
}
// namespace internal
23
24
using
TraceCallback
= void (*)(
Visitor
*,
const
void
*);
25
26
// TraceDescriptor is used to describe how to trace an object.
27
struct
TraceDescriptor
{
28
// The adjusted base pointer of the object that should be traced.
29
const
void
*
base_object_payload
;
30
// A callback for tracing the object.
31
TraceCallback
callback
;
32
};
33
34
template
<
typename
T>
35
struct
TraceTrait
{
36
static_assert(internal::IsTraceableV<T>,
"T must have a Trace() method"
);
37
38
static
TraceDescriptor
GetTraceDescriptor
(
const
void
*
self
) {
39
return
internal::TraceTraitImpl<T>::GetTraceDescriptor
(
40
static_cast<
const
T*
>
(
self
));
41
}
42
43
static
void
Trace
(
Visitor
* visitor,
const
void
*
self
) {
44
static_cast<
const
T*
>
(
self
)->
Trace
(visitor);
45
}
46
};
47
48
namespace
internal {
49
50
template
<
typename
T>
51
struct
TraceTraitImpl
<T, false> {
52
static
TraceDescriptor
GetTraceDescriptor
(
const
void
*
self
) {
53
return
{
self
,
TraceTrait<T>::Trace
};
54
}
55
};
56
57
template
<
typename
T>
58
struct
TraceTraitImpl
<T, true> {
59
static
TraceDescriptor
GetTraceDescriptor
(
const
void
*
self
) {
60
return
static_cast<
const
T*
>
(
self
)->GetTraceDescriptor();
61
}
62
};
63
64
}
// namespace internal
65
}
// namespace cppgc
66
67
#endif // INCLUDE_CPPGC_TRACE_TRAIT_H_
cppgc::TraceTrait::Trace
static void Trace(Visitor *visitor, const void *self)
Definition:
trace-trait.h:43
cppgc::TraceTrait::GetTraceDescriptor
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition:
trace-trait.h:38
cppgc::internal::TraceTraitImpl< T, true >::GetTraceDescriptor
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition:
trace-trait.h:59
cppgc::internal::TraceTraitImpl
Definition:
trace-trait.h:20
cppgc::TraceCallback
void(*)(Visitor *, const void *) TraceCallback
Definition:
trace-trait.h:24
cppgc::internal::TraceTraitImpl< T, false >::GetTraceDescriptor
static TraceDescriptor GetTraceDescriptor(const void *self)
Definition:
trace-trait.h:52
cppgc
Definition:
allocation.h:18
cppgc::TraceDescriptor
Definition:
trace-trait.h:27
cppgc::TraceDescriptor::callback
TraceCallback callback
Definition:
trace-trait.h:31
cppgc::Visitor
Definition:
visitor.h:27
type-traits.h
cppgc::TraceDescriptor::base_object_payload
const void * base_object_payload
Definition:
trace-trait.h:29
cppgc::TraceTrait
Definition:
trace-trait.h:35
v8
include
cppgc
trace-trait.h
Generated by
1.8.17