v8
13.6.233 (node 24.1.0)
V8 is Google's open source JavaScript engine
Toggle main menu visibility
Main Page
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Functions
a
c
d
e
f
g
i
j
k
m
n
o
p
r
s
t
u
v
Variables
f
g
i
k
m
t
Typedefs
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Enumerations
a
b
c
e
g
h
i
j
k
l
m
n
p
s
t
w
Enumerator
a
b
c
d
e
g
i
j
k
l
n
o
p
r
s
Concepts
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
Typedefs
a
b
c
d
g
i
m
n
p
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
u
v
w
Enumerator
b
c
d
e
h
j
k
n
o
p
r
s
t
u
w
Related Symbols
:
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
Files
File List
Globals
All
a
c
d
e
p
s
v
Macros
a
c
d
e
p
s
v
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Concepts
Loading...
Searching...
No Matches
finalizer-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_INTERNAL_FINALIZER_TRAIT_H_
6
#define INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
7
8
#include <type_traits>
9
10
#include "
cppgc/type-traits.h
"
11
12
namespace
cppgc
{
13
namespace
internal
{
14
15
using
FinalizationCallback
= void (*)(
void
*);
16
17
template
<
typename
T,
typename
=
void
>
18
struct
HasFinalizeGarbageCollectedObject
: std::false_type {};
19
20
template
<
typename
T>
21
struct
HasFinalizeGarbageCollectedObject
<
22
T,
23
std::void_t<decltype(std::declval<T>().FinalizeGarbageCollectedObject())>>
24
: std::true_type {};
21
struct
HasFinalizeGarbageCollectedObject
< {
…
};
25
26
// The FinalizerTraitImpl specifies how to finalize objects.
27
template
<
typename
T,
bool
isFinalized>
28
struct
FinalizerTraitImpl
;
29
30
template
<
typename
T>
31
struct
FinalizerTraitImpl
<T,
true
> {
32
private
:
33
// Dispatch to custom FinalizeGarbageCollectedObject().
34
struct
Custom {
35
static
void
Call(
void
* obj) {
36
static_cast<
T*
>
(obj)->FinalizeGarbageCollectedObject();
37
}
38
};
39
40
// Dispatch to regular destructor.
41
struct
Destructor {
42
static
void
Call(
void
* obj) {
static_cast<
T*
>
(obj)->~T(); }
43
};
44
45
using
FinalizeImpl =
46
std::conditional_t<HasFinalizeGarbageCollectedObject<T>::value, Custom,
47
Destructor>;
48
49
public
:
50
static
void
Finalize
(
void
* obj) {
51
static_assert
(
sizeof
(T),
"T must be fully defined"
);
52
FinalizeImpl::Call(obj);
53
}
50
static
void
Finalize
(
void
* obj) {
…
}
54
};
31
struct
FinalizerTraitImpl
<T,
true
> {
…
};
55
56
template
<
typename
T>
57
struct
FinalizerTraitImpl
<T,
false
> {
58
static
void
Finalize
(
void
* obj) {
59
static_assert
(
sizeof
(T),
"T must be fully defined"
);
60
}
58
static
void
Finalize
(
void
* obj) {
…
}
61
};
57
struct
FinalizerTraitImpl
<T,
false
> {
…
};
62
63
// The FinalizerTrait is used to determine if a type requires finalization and
64
// what finalization means.
65
template
<
typename
T>
66
struct
FinalizerTrait
{
67
private
:
68
// Object has a finalizer if it has
69
// - a custom FinalizeGarbageCollectedObject method, or
70
// - a destructor.
71
static
constexpr
bool
kNonTrivialFinalizer =
72
internal::HasFinalizeGarbageCollectedObject<T>::value
||
73
!std::is_trivially_destructible<typename std::remove_cv<T>::type>::value;
74
75
static
void
Finalize(
void
* obj) {
76
internal::FinalizerTraitImpl<T, kNonTrivialFinalizer>::Finalize
(obj);
77
}
78
79
public
:
80
static
constexpr
bool
HasFinalizer
() {
return
kNonTrivialFinalizer; }
81
82
// The callback used to finalize an object of type T.
83
static
constexpr
FinalizationCallback
kCallback
=
84
kNonTrivialFinalizer ? Finalize :
nullptr
;
85
};
66
struct
FinalizerTrait
{
…
};
86
87
template
<
typename
T>
88
constexpr
FinalizationCallback
FinalizerTrait<T>::kCallback
;
89
90
}
// namespace internal
91
}
// namespace cppgc
92
93
#endif
// INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
cppgc::internal
Definition
allocation.h:45
cppgc::internal::FinalizationCallback
void(*)(void *) FinalizationCallback
Definition
finalizer-trait.h:15
cppgc::internal::true
true
Definition
gc-info.h:70
cppgc::internal::false
false
Definition
gc-info.h:66
cppgc
Definition
allocation.h:38
cppgc::internal::FinalizerTrait
Definition
finalizer-trait.h:66
cppgc::internal::FinalizerTrait::kCallback
static constexpr FinalizationCallback kCallback
Definition
finalizer-trait.h:83
cppgc::internal::FinalizerTrait::HasFinalizer
static constexpr bool HasFinalizer()
Definition
finalizer-trait.h:80
cppgc::internal::FinalizerTraitImpl< T, false >::Finalize
static void Finalize(void *obj)
Definition
finalizer-trait.h:58
cppgc::internal::FinalizerTraitImpl< T, true >::Finalize
static void Finalize(void *obj)
Definition
finalizer-trait.h:50
cppgc::internal::FinalizerTraitImpl
Definition
finalizer-trait.h:28
cppgc::internal::HasFinalizeGarbageCollectedObject
Definition
finalizer-trait.h:18
type-traits.h
include
cppgc
internal
finalizer-trait.h
Generated on Fri May 30 2025 01:56:44 for v8 by
1.13.2