libv8 7.3.492.27.1-universal-darwin-18 → 8.4.255.0-universal-darwin-18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libv8/version.rb +1 -1
- data/vendor/v8/include/cppgc/allocation.h +124 -0
- data/vendor/v8/include/cppgc/garbage-collected.h +192 -0
- data/vendor/v8/include/cppgc/heap.h +50 -0
- data/vendor/v8/include/cppgc/internal/accessors.h +26 -0
- data/vendor/v8/include/cppgc/internal/api-constants.h +44 -0
- data/vendor/v8/include/cppgc/internal/compiler-specific.h +26 -0
- data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
- data/vendor/v8/include/cppgc/internal/gc-info.h +43 -0
- data/vendor/v8/include/cppgc/internal/logging.h +50 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +109 -0
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +133 -0
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +31 -0
- data/vendor/v8/include/cppgc/liveness-broker.h +50 -0
- data/vendor/v8/include/cppgc/macros.h +26 -0
- data/vendor/v8/include/cppgc/member.h +206 -0
- data/vendor/v8/include/cppgc/persistent.h +304 -0
- data/vendor/v8/include/cppgc/platform.h +31 -0
- data/vendor/v8/include/cppgc/prefinalizer.h +54 -0
- data/vendor/v8/include/cppgc/source-location.h +59 -0
- data/vendor/v8/include/cppgc/trace-trait.h +67 -0
- data/vendor/v8/include/cppgc/type-traits.h +109 -0
- data/vendor/v8/include/cppgc/visitor.h +137 -0
- data/vendor/v8/include/libplatform/libplatform.h +13 -19
- data/vendor/v8/include/libplatform/v8-tracing.h +50 -15
- data/vendor/v8/include/v8-fast-api-calls.h +412 -0
- data/vendor/v8/include/v8-inspector-protocol.h +4 -4
- data/vendor/v8/include/v8-inspector.h +60 -29
- data/vendor/v8/include/v8-internal.h +98 -82
- data/vendor/v8/include/v8-platform.h +181 -42
- data/vendor/v8/include/v8-profiler.h +162 -224
- data/vendor/v8/include/v8-util.h +1 -13
- data/vendor/v8/include/v8-version-string.h +1 -1
- data/vendor/v8/include/v8-version.h +4 -4
- data/vendor/v8/include/v8-wasm-trap-handler-posix.h +1 -1
- data/vendor/v8/include/v8-wasm-trap-handler-win.h +1 -1
- data/vendor/v8/include/v8.h +1990 -611
- data/vendor/v8/include/v8config.h +129 -48
- data/vendor/v8/out.gn/libv8/obj/libv8_libbase.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_libplatform.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicui18n.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/icu/libicuuc.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/zlib/google/libcompression_utils_portable.a +0 -0
- data/vendor/v8/out.gn/libv8/obj/third_party/zlib/libchrome_zlib.a +0 -0
- metadata +34 -8
- data/vendor/v8/include/v8-testing.h +0 -48
@@ -0,0 +1,31 @@
|
|
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_PLATFORM_H_
|
6
|
+
#define INCLUDE_CPPGC_PLATFORM_H_
|
7
|
+
|
8
|
+
#include "v8-platform.h" // NOLINT(build/include_directory)
|
9
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
10
|
+
|
11
|
+
namespace cppgc {
|
12
|
+
|
13
|
+
// TODO(v8:10346): Put PageAllocator in a non-V8 include header to avoid
|
14
|
+
// depending on namespace v8.
|
15
|
+
using PageAllocator = v8::PageAllocator;
|
16
|
+
|
17
|
+
// Initializes the garbage collector with the provided platform. Must be called
|
18
|
+
// before creating a Heap.
|
19
|
+
V8_EXPORT void InitializePlatform(PageAllocator* page_allocator);
|
20
|
+
|
21
|
+
// Must be called after destroying the last used heap.
|
22
|
+
V8_EXPORT void ShutdownPlatform();
|
23
|
+
|
24
|
+
namespace internal {
|
25
|
+
|
26
|
+
V8_EXPORT void Abort();
|
27
|
+
|
28
|
+
} // namespace internal
|
29
|
+
} // namespace cppgc
|
30
|
+
|
31
|
+
#endif // INCLUDE_CPPGC_PLATFORM_H_
|
@@ -0,0 +1,54 @@
|
|
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_PREFINALIZER_H_
|
6
|
+
#define INCLUDE_CPPGC_PREFINALIZER_H_
|
7
|
+
|
8
|
+
#include "cppgc/internal/accessors.h"
|
9
|
+
#include "cppgc/internal/compiler-specific.h"
|
10
|
+
#include "cppgc/internal/prefinalizer-handler.h"
|
11
|
+
#include "cppgc/liveness-broker.h"
|
12
|
+
#include "cppgc/macros.h"
|
13
|
+
|
14
|
+
namespace cppgc {
|
15
|
+
|
16
|
+
namespace internal {
|
17
|
+
|
18
|
+
template <typename T>
|
19
|
+
class PrefinalizerRegistration final {
|
20
|
+
public:
|
21
|
+
explicit PrefinalizerRegistration(T* self) {
|
22
|
+
static_assert(sizeof(&T::InvokePreFinalizer) > 0,
|
23
|
+
"USING_PRE_FINALIZER(T) must be defined.");
|
24
|
+
|
25
|
+
cppgc::internal::PreFinalizerRegistrationDispatcher::RegisterPrefinalizer(
|
26
|
+
internal::GetHeapFromPayload(self), {self, T::InvokePreFinalizer});
|
27
|
+
}
|
28
|
+
|
29
|
+
void* operator new(size_t, void* location) = delete;
|
30
|
+
void* operator new(size_t) = delete;
|
31
|
+
};
|
32
|
+
|
33
|
+
} // namespace internal
|
34
|
+
|
35
|
+
#define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer) \
|
36
|
+
public: \
|
37
|
+
static bool InvokePreFinalizer(const LivenessBroker& liveness_broker, \
|
38
|
+
void* object) { \
|
39
|
+
static_assert(internal::IsGarbageCollectedTypeV<Class>, \
|
40
|
+
"Only garbage collected objects can have prefinalizers"); \
|
41
|
+
Class* self = static_cast<Class*>(object); \
|
42
|
+
if (liveness_broker.IsHeapObjectAlive(self)) return false; \
|
43
|
+
self->Class::PreFinalizer(); \
|
44
|
+
return true; \
|
45
|
+
} \
|
46
|
+
\
|
47
|
+
private: \
|
48
|
+
CPPGC_NO_UNIQUE_ADDRESS internal::PrefinalizerRegistration<Class> \
|
49
|
+
prefinalizer_dummy_{this}; \
|
50
|
+
friend class internal::__thisIsHereToForceASemicolonAfterThisMacro
|
51
|
+
|
52
|
+
} // namespace cppgc
|
53
|
+
|
54
|
+
#endif // INCLUDE_CPPGC_PREFINALIZER_H_
|
@@ -0,0 +1,59 @@
|
|
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_SOURCE_LOCATION_H_
|
6
|
+
#define INCLUDE_CPPGC_SOURCE_LOCATION_H_
|
7
|
+
|
8
|
+
#include <string>
|
9
|
+
|
10
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
11
|
+
|
12
|
+
#if defined(__has_builtin)
|
13
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION \
|
14
|
+
(__has_builtin(__builtin_FUNCTION) && __has_builtin(__builtin_FILE) && \
|
15
|
+
__has_builtin(__builtin_LINE)) // NOLINT
|
16
|
+
#elif defined(V8_CC_GNU) && __GNUC__ >= 7
|
17
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 1
|
18
|
+
#elif defined(V8_CC_INTEL) && __ICC >= 1800
|
19
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 1
|
20
|
+
#else
|
21
|
+
#define CPPGC_SUPPORTS_SOURCE_LOCATION 0
|
22
|
+
#endif
|
23
|
+
|
24
|
+
namespace cppgc {
|
25
|
+
|
26
|
+
// Encapsulates source location information. Mimics C++20's
|
27
|
+
// std::source_location.
|
28
|
+
class V8_EXPORT SourceLocation final {
|
29
|
+
public:
|
30
|
+
#if CPPGC_SUPPORTS_SOURCE_LOCATION
|
31
|
+
static constexpr SourceLocation Current(
|
32
|
+
const char* function = __builtin_FUNCTION(),
|
33
|
+
const char* file = __builtin_FILE(), size_t line = __builtin_LINE()) {
|
34
|
+
return SourceLocation(function, file, line);
|
35
|
+
}
|
36
|
+
#else
|
37
|
+
static constexpr SourceLocation Current() { return SourceLocation(); }
|
38
|
+
#endif // CPPGC_SUPPORTS_SOURCE_LOCATION
|
39
|
+
|
40
|
+
constexpr SourceLocation() = default;
|
41
|
+
|
42
|
+
constexpr const char* Function() const { return function_; }
|
43
|
+
constexpr const char* FileName() const { return file_; }
|
44
|
+
constexpr size_t Line() const { return line_; }
|
45
|
+
|
46
|
+
std::string ToString() const;
|
47
|
+
|
48
|
+
private:
|
49
|
+
constexpr SourceLocation(const char* function, const char* file, size_t line)
|
50
|
+
: function_(function), file_(file), line_(line) {}
|
51
|
+
|
52
|
+
const char* function_ = nullptr;
|
53
|
+
const char* file_ = nullptr;
|
54
|
+
size_t line_ = 0u;
|
55
|
+
};
|
56
|
+
|
57
|
+
} // namespace cppgc
|
58
|
+
|
59
|
+
#endif // INCLUDE_CPPGC_SOURCE_LOCATION_H_
|
@@ -0,0 +1,67 @@
|
|
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_
|
@@ -0,0 +1,109 @@
|
|
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_TYPE_TRAITS_H_
|
6
|
+
#define INCLUDE_CPPGC_TYPE_TRAITS_H_
|
7
|
+
|
8
|
+
#include <type_traits>
|
9
|
+
|
10
|
+
namespace cppgc {
|
11
|
+
|
12
|
+
class Visitor;
|
13
|
+
|
14
|
+
namespace internal {
|
15
|
+
|
16
|
+
// Pre-C++17 custom implementation of std::void_t.
|
17
|
+
template <typename... Ts>
|
18
|
+
struct make_void {
|
19
|
+
typedef void type;
|
20
|
+
};
|
21
|
+
template <typename... Ts>
|
22
|
+
using void_t = typename make_void<Ts...>::type;
|
23
|
+
|
24
|
+
// Not supposed to be specialized by the user.
|
25
|
+
template <typename T>
|
26
|
+
struct IsWeak : std::false_type {};
|
27
|
+
|
28
|
+
template <typename T, template <typename... V> class U>
|
29
|
+
struct IsSubclassOfTemplate {
|
30
|
+
private:
|
31
|
+
template <typename... W>
|
32
|
+
static std::true_type SubclassCheck(U<W...>*);
|
33
|
+
static std::false_type SubclassCheck(...);
|
34
|
+
|
35
|
+
public:
|
36
|
+
static constexpr bool value =
|
37
|
+
decltype(SubclassCheck(std::declval<T*>()))::value;
|
38
|
+
};
|
39
|
+
|
40
|
+
// IsTraceMethodConst is used to verify that all Trace methods are marked as
|
41
|
+
// const. It is equivalent to IsTraceable but for a non-const object.
|
42
|
+
template <typename T, typename = void>
|
43
|
+
struct IsTraceMethodConst : std::false_type {};
|
44
|
+
|
45
|
+
template <typename T>
|
46
|
+
struct IsTraceMethodConst<T, void_t<decltype(std::declval<const T>().Trace(
|
47
|
+
std::declval<Visitor*>()))>> : std::true_type {
|
48
|
+
};
|
49
|
+
|
50
|
+
template <typename T, typename = void>
|
51
|
+
struct IsTraceable : std::false_type {
|
52
|
+
static_assert(sizeof(T), "T must be fully defined");
|
53
|
+
};
|
54
|
+
|
55
|
+
template <typename T>
|
56
|
+
struct IsTraceable<
|
57
|
+
T, void_t<decltype(std::declval<T>().Trace(std::declval<Visitor*>()))>>
|
58
|
+
: std::true_type {
|
59
|
+
// All Trace methods should be marked as const. If an object of type
|
60
|
+
// 'T' is traceable then any object of type 'const T' should also
|
61
|
+
// be traceable.
|
62
|
+
static_assert(IsTraceMethodConst<T>(),
|
63
|
+
"Trace methods should be marked as const.");
|
64
|
+
};
|
65
|
+
|
66
|
+
template <typename T>
|
67
|
+
constexpr bool IsTraceableV = IsTraceable<T>::value;
|
68
|
+
|
69
|
+
template <typename T, typename = void>
|
70
|
+
struct IsGarbageCollectedMixinType : std::false_type {
|
71
|
+
static_assert(sizeof(T), "T must be fully defined");
|
72
|
+
};
|
73
|
+
|
74
|
+
template <typename T>
|
75
|
+
struct IsGarbageCollectedMixinType<
|
76
|
+
T,
|
77
|
+
void_t<typename std::remove_const_t<T>::IsGarbageCollectedMixinTypeMarker>>
|
78
|
+
: std::true_type {
|
79
|
+
static_assert(sizeof(T), "T must be fully defined");
|
80
|
+
};
|
81
|
+
|
82
|
+
template <typename T, typename = void>
|
83
|
+
struct IsGarbageCollectedType : IsGarbageCollectedMixinType<T> {
|
84
|
+
static_assert(sizeof(T), "T must be fully defined");
|
85
|
+
};
|
86
|
+
|
87
|
+
template <typename T>
|
88
|
+
struct IsGarbageCollectedType<
|
89
|
+
T, void_t<typename std::remove_const_t<T>::IsGarbageCollectedTypeMarker>>
|
90
|
+
: std::true_type {
|
91
|
+
static_assert(sizeof(T), "T must be fully defined");
|
92
|
+
};
|
93
|
+
|
94
|
+
template <typename T>
|
95
|
+
constexpr bool IsGarbageCollectedTypeV =
|
96
|
+
internal::IsGarbageCollectedType<T>::value;
|
97
|
+
|
98
|
+
template <typename T>
|
99
|
+
constexpr bool IsGarbageCollectedMixinTypeV =
|
100
|
+
internal::IsGarbageCollectedMixinType<T>::value;
|
101
|
+
|
102
|
+
} // namespace internal
|
103
|
+
|
104
|
+
template <typename T>
|
105
|
+
constexpr bool IsWeakV = internal::IsWeak<T>::value;
|
106
|
+
|
107
|
+
} // namespace cppgc
|
108
|
+
|
109
|
+
#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
|
@@ -0,0 +1,137 @@
|
|
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_VISITOR_H_
|
6
|
+
#define INCLUDE_CPPGC_VISITOR_H_
|
7
|
+
|
8
|
+
#include "cppgc/garbage-collected.h"
|
9
|
+
#include "cppgc/internal/logging.h"
|
10
|
+
#include "cppgc/internal/pointer-policies.h"
|
11
|
+
#include "cppgc/liveness-broker.h"
|
12
|
+
#include "cppgc/member.h"
|
13
|
+
#include "cppgc/source-location.h"
|
14
|
+
#include "cppgc/trace-trait.h"
|
15
|
+
|
16
|
+
namespace cppgc {
|
17
|
+
namespace internal {
|
18
|
+
class VisitorBase;
|
19
|
+
} // namespace internal
|
20
|
+
|
21
|
+
using WeakCallback = void (*)(const LivenessBroker&, const void*);
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Visitor passed to trace methods. All managed pointers must have called the
|
25
|
+
* visitor's trace method on them.
|
26
|
+
*/
|
27
|
+
class Visitor {
|
28
|
+
public:
|
29
|
+
template <typename T>
|
30
|
+
void Trace(const Member<T>& member) {
|
31
|
+
const T* value = member.GetRawAtomic();
|
32
|
+
CPPGC_DCHECK(value != kSentinelPointer);
|
33
|
+
Trace(value);
|
34
|
+
}
|
35
|
+
|
36
|
+
template <typename T>
|
37
|
+
void Trace(const WeakMember<T>& weak_member) {
|
38
|
+
static_assert(sizeof(T), "T must be fully defined");
|
39
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
40
|
+
"T must be GarabgeCollected or GarbageCollectedMixin type");
|
41
|
+
|
42
|
+
const T* value = weak_member.GetRawAtomic();
|
43
|
+
|
44
|
+
// Bailout assumes that WeakMember emits write barrier.
|
45
|
+
if (!value) {
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
// TODO(chromium:1056170): DCHECK (or similar) for deleted values as they
|
50
|
+
// should come in at a different path.
|
51
|
+
VisitWeak(value, TraceTrait<T>::GetTraceDescriptor(value),
|
52
|
+
&HandleWeak<WeakMember<T>>, &weak_member);
|
53
|
+
}
|
54
|
+
|
55
|
+
template <typename Persistent,
|
56
|
+
std::enable_if_t<Persistent::IsStrongPersistent::value>* = nullptr>
|
57
|
+
void TraceRoot(const Persistent& p, const SourceLocation& loc) {
|
58
|
+
using PointeeType = typename Persistent::PointeeType;
|
59
|
+
static_assert(sizeof(PointeeType),
|
60
|
+
"Persistent's pointee type must be fully defined");
|
61
|
+
static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
|
62
|
+
"Persisent's pointee type must be GarabgeCollected or "
|
63
|
+
"GarbageCollectedMixin");
|
64
|
+
if (!p.Get()) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
VisitRoot(p.Get(), TraceTrait<PointeeType>::GetTraceDescriptor(p.Get()),
|
68
|
+
loc);
|
69
|
+
}
|
70
|
+
|
71
|
+
template <typename Persistent,
|
72
|
+
std::enable_if_t<!Persistent::IsStrongPersistent::value>* = nullptr>
|
73
|
+
void TraceRoot(const Persistent& p, const SourceLocation& loc) {
|
74
|
+
using PointeeType = typename Persistent::PointeeType;
|
75
|
+
static_assert(sizeof(PointeeType),
|
76
|
+
"Persistent's pointee type must be fully defined");
|
77
|
+
static_assert(internal::IsGarbageCollectedType<PointeeType>::value,
|
78
|
+
"Persisent's pointee type must be GarabgeCollected or "
|
79
|
+
"GarbageCollectedMixin");
|
80
|
+
VisitWeakRoot(&p, &HandleWeak<Persistent>);
|
81
|
+
}
|
82
|
+
|
83
|
+
template <typename T, void (T::*method)(const LivenessBroker&)>
|
84
|
+
void RegisterWeakCallbackMethod(const T* obj) {
|
85
|
+
RegisterWeakCallback(&WeakCallbackMethodDelegate<T, method>, obj);
|
86
|
+
}
|
87
|
+
|
88
|
+
virtual void RegisterWeakCallback(WeakCallback, const void*) {}
|
89
|
+
|
90
|
+
protected:
|
91
|
+
virtual void Visit(const void* self, TraceDescriptor) {}
|
92
|
+
virtual void VisitWeak(const void* self, TraceDescriptor, WeakCallback,
|
93
|
+
const void* weak_member) {}
|
94
|
+
virtual void VisitRoot(const void*, TraceDescriptor,
|
95
|
+
const SourceLocation& loc) {}
|
96
|
+
virtual void VisitWeakRoot(const void*, WeakCallback) {}
|
97
|
+
|
98
|
+
private:
|
99
|
+
template <typename T, void (T::*method)(const LivenessBroker&)>
|
100
|
+
static void WeakCallbackMethodDelegate(const LivenessBroker& info,
|
101
|
+
const void* self) {
|
102
|
+
// Callback is registered through a potential const Trace method but needs
|
103
|
+
// to be able to modify fields. See HandleWeak.
|
104
|
+
(const_cast<T*>(static_cast<const T*>(self))->*method)(info);
|
105
|
+
}
|
106
|
+
|
107
|
+
template <typename PointerType>
|
108
|
+
static void HandleWeak(const LivenessBroker& info, const void* object) {
|
109
|
+
const PointerType* weak = static_cast<const PointerType*>(object);
|
110
|
+
const auto* raw = weak->Get();
|
111
|
+
if (raw && !info.IsHeapObjectAlive(raw)) {
|
112
|
+
// Object is passed down through the marker as const. Alternatives are
|
113
|
+
// - non-const Trace method;
|
114
|
+
// - mutable pointer in MemberBase;
|
115
|
+
const_cast<PointerType*>(weak)->Clear();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
Visitor() = default;
|
120
|
+
|
121
|
+
template <typename T>
|
122
|
+
void Trace(const T* t) {
|
123
|
+
static_assert(sizeof(T), "T must be fully defined");
|
124
|
+
static_assert(internal::IsGarbageCollectedType<T>::value,
|
125
|
+
"T must be GarabgeCollected or GarbageCollectedMixin type");
|
126
|
+
if (!t) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
Visit(t, TraceTrait<T>::GetTraceDescriptor(t));
|
130
|
+
}
|
131
|
+
|
132
|
+
friend class internal::VisitorBase;
|
133
|
+
};
|
134
|
+
|
135
|
+
} // namespace cppgc
|
136
|
+
|
137
|
+
#endif // INCLUDE_CPPGC_VISITOR_H_
|