aha-libv8-node 16.0.0.0-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +1 -0
  3. data/ext/libv8-node/location.rb +76 -0
  4. data/ext/libv8-node/paths.rb +30 -0
  5. data/lib/libv8-node.rb +1 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8/node/version.rb +7 -0
  8. data/vendor/v8/include/cppgc/allocation.h +229 -0
  9. data/vendor/v8/include/cppgc/common.h +29 -0
  10. data/vendor/v8/include/cppgc/cross-thread-persistent.h +345 -0
  11. data/vendor/v8/include/cppgc/custom-space.h +97 -0
  12. data/vendor/v8/include/cppgc/default-platform.h +75 -0
  13. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  14. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  15. data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
  16. data/vendor/v8/include/cppgc/heap-state.h +59 -0
  17. data/vendor/v8/include/cppgc/heap-statistics.h +110 -0
  18. data/vendor/v8/include/cppgc/heap.h +199 -0
  19. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  20. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  21. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +68 -0
  22. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  23. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  24. data/vendor/v8/include/cppgc/internal/gc-info.h +47 -0
  25. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  26. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  27. data/vendor/v8/include/cppgc/internal/persistent-node.h +132 -0
  28. data/vendor/v8/include/cppgc/internal/pointer-policies.h +143 -0
  29. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  30. data/vendor/v8/include/cppgc/internal/write-barrier.h +390 -0
  31. data/vendor/v8/include/cppgc/liveness-broker.h +74 -0
  32. data/vendor/v8/include/cppgc/macros.h +26 -0
  33. data/vendor/v8/include/cppgc/member.h +271 -0
  34. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  35. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  36. data/vendor/v8/include/cppgc/persistent.h +365 -0
  37. data/vendor/v8/include/cppgc/platform.h +151 -0
  38. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  39. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  40. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  41. data/vendor/v8/include/cppgc/source-location.h +91 -0
  42. data/vendor/v8/include/cppgc/testing.h +50 -0
  43. data/vendor/v8/include/cppgc/trace-trait.h +116 -0
  44. data/vendor/v8/include/cppgc/type-traits.h +228 -0
  45. data/vendor/v8/include/cppgc/visitor.h +340 -0
  46. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  47. data/vendor/v8/include/libplatform/libplatform.h +117 -0
  48. data/vendor/v8/include/libplatform/v8-tracing.h +334 -0
  49. data/vendor/v8/include/v8-cppgc.h +278 -0
  50. data/vendor/v8/include/v8-fast-api-calls.h +419 -0
  51. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  52. data/vendor/v8/include/v8-inspector.h +336 -0
  53. data/vendor/v8/include/v8-internal.h +462 -0
  54. data/vendor/v8/include/v8-metrics.h +189 -0
  55. data/vendor/v8/include/v8-platform.h +710 -0
  56. data/vendor/v8/include/v8-profiler.h +1116 -0
  57. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  58. data/vendor/v8/include/v8-util.h +652 -0
  59. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  60. data/vendor/v8/include/v8-version-string.h +38 -0
  61. data/vendor/v8/include/v8-version.h +20 -0
  62. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  63. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  64. data/vendor/v8/include/v8.h +12479 -0
  65. data/vendor/v8/include/v8config.h +521 -0
  66. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  67. metadata +137 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 247a69f1b364304acf7bed6c84f39098f98e6c625209748651ac3d10e3f69163
4
+ data.tar.gz: aaabf4cde879803687dd8a5b29171c2edf9d59ee5d3672ca762787f01894fbb7
5
+ SHA512:
6
+ metadata.gz: c4804940e00e50b71a43ac603c8e2c5a994a94e8f9e8ac2f53b4b6437f951baa93b7dbb3028d31e610d78cef2a5464164300abd2fae8f42e9b15b07ff55a36ff
7
+ data.tar.gz: 239193338bcb8f5c9fe8b692daf5ec6ddc36a8297d3d0af6b5253862e9910bfff1e214f78b2f80c619a57e585a0f08a64a2e65efb758cd07a887db34f28d09d9
@@ -0,0 +1 @@
1
+ --- !ruby/object:Libv8::Node::Location::Vendor {}
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'pathname'
5
+ require File.expand_path('paths', __dir__)
6
+
7
+ module Libv8; end
8
+
9
+ module Libv8::Node
10
+ class Location
11
+ def install!
12
+ File.open(Pathname(__FILE__).dirname.join('.location.yml'), 'w') do |f|
13
+ f.write(to_yaml)
14
+ end
15
+
16
+ 0
17
+ end
18
+
19
+ def self.load!
20
+ File.open(Pathname(__FILE__).dirname.join('.location.yml')) do |f|
21
+ YAML.load(f) # rubocop:disable Security/YAMLLoad
22
+ end
23
+ end
24
+
25
+ class Vendor < Location
26
+ def install!
27
+ require File.expand_path('builder', __dir__)
28
+
29
+ builder = Libv8::Node::Builder.new
30
+ exit_status = builder.build_libv8!
31
+ builder.remove_intermediates!
32
+
33
+ super if exit_status == 0
34
+
35
+ verify_installation!
36
+
37
+ exit_status
38
+ end
39
+
40
+ def configure(context = MkmfContext.new)
41
+ context.incflags.insert(0, Libv8::Node::Paths.include_paths.map { |p| "-I#{p}" }.join(' ') << ' ')
42
+ context.ldflags.insert(0, Libv8::Node::Paths.object_paths.join(' ') << ' ')
43
+ end
44
+
45
+ def verify_installation!
46
+ include_paths = Libv8::Node::Paths.include_paths
47
+
48
+ unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? }
49
+ raise(HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}")
50
+ end
51
+
52
+ Libv8::Node::Paths.object_paths.each do |p|
53
+ raise(ArchiveNotFound, p) unless File.exist?(p)
54
+ end
55
+ end
56
+
57
+ class HeaderNotFound < StandardError; end
58
+
59
+ class ArchiveNotFound < StandardError
60
+ def initialize(filename)
61
+ super "libv8 did not install properly, expected binary v8 archive '#{filename}'to exist, but it was not found"
62
+ end
63
+ end
64
+ end
65
+
66
+ class MkmfContext
67
+ def incflags
68
+ $INCFLAGS # rubocop:disable Style/GlobalVars
69
+ end
70
+
71
+ def ldflags
72
+ $LDFLAGS # rubocop:disable Style/GlobalVars
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ require 'rbconfig'
2
+ require 'shellwords'
3
+
4
+ module Libv8; end
5
+
6
+ module Libv8::Node
7
+ module Paths
8
+ module_function
9
+
10
+ def include_paths
11
+ [Shellwords.escape(File.join(vendored_source_path, 'include'))]
12
+ end
13
+
14
+ def object_paths
15
+ [Shellwords.escape(File.join(vendored_source_path,
16
+ 'out.gn',
17
+ 'libv8',
18
+ 'obj',
19
+ "libv8_monolith.#{config['LIBEXT']}"))]
20
+ end
21
+
22
+ def config
23
+ RbConfig::MAKEFILE_CONFIG
24
+ end
25
+
26
+ def vendored_source_path
27
+ File.expand_path('../../vendor/v8', __dir__)
28
+ end
29
+ end
30
+ end
data/lib/libv8-node.rb ADDED
@@ -0,0 +1 @@
1
+ require 'libv8/node'
data/lib/libv8/node.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'libv8/node/version'
2
+ require 'libv8-node/location'
3
+
4
+ module Libv8; end
5
+
6
+ module Libv8::Node
7
+ def self.configure_makefile
8
+ location = Location.load!
9
+ location.configure
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Libv8; end
2
+
3
+ module Libv8::Node
4
+ VERSION = '16.0.0.0'.freeze
5
+ NODE_VERSION = '16.0.0'.freeze
6
+ LIBV8_VERSION = '9.0.257.17'.freeze # from v8/include/v8-version.h
7
+ end
@@ -0,0 +1,229 @@
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_ALLOCATION_H_
6
+ #define INCLUDE_CPPGC_ALLOCATION_H_
7
+
8
+ #include <stdint.h>
9
+
10
+ #include <atomic>
11
+
12
+ #include "cppgc/custom-space.h"
13
+ #include "cppgc/garbage-collected.h"
14
+ #include "cppgc/internal/api-constants.h"
15
+ #include "cppgc/internal/gc-info.h"
16
+
17
+ namespace cppgc {
18
+
19
+ template <typename T>
20
+ class MakeGarbageCollectedTraitBase;
21
+
22
+ namespace internal {
23
+ class ObjectAllocator;
24
+ } // namespace internal
25
+
26
+ /**
27
+ * AllocationHandle is used to allocate garbage-collected objects.
28
+ */
29
+ class AllocationHandle;
30
+
31
+ namespace internal {
32
+
33
+ class V8_EXPORT MakeGarbageCollectedTraitInternal {
34
+ protected:
35
+ static inline void MarkObjectAsFullyConstructed(const void* payload) {
36
+ // See api_constants for an explanation of the constants.
37
+ std::atomic<uint16_t>* atomic_mutable_bitfield =
38
+ reinterpret_cast<std::atomic<uint16_t>*>(
39
+ const_cast<uint16_t*>(reinterpret_cast<const uint16_t*>(
40
+ reinterpret_cast<const uint8_t*>(payload) -
41
+ api_constants::kFullyConstructedBitFieldOffsetFromPayload)));
42
+ atomic_mutable_bitfield->fetch_or(api_constants::kFullyConstructedBitMask,
43
+ std::memory_order_release);
44
+ }
45
+
46
+ static void* Allocate(cppgc::AllocationHandle& handle, size_t size,
47
+ GCInfoIndex index);
48
+ static void* Allocate(cppgc::AllocationHandle& handle, size_t size,
49
+ GCInfoIndex index, CustomSpaceIndex space_index);
50
+
51
+ friend class HeapObjectHeader;
52
+ };
53
+
54
+ } // namespace internal
55
+
56
+ /**
57
+ * Base trait that provides utilities for advancers users that have custom
58
+ * allocation needs (e.g., overriding size). It's expected that users override
59
+ * MakeGarbageCollectedTrait (see below) and inherit from
60
+ * MakeGarbageCollectedTraitBase and make use of the low-level primitives
61
+ * offered to allocate and construct an object.
62
+ */
63
+ template <typename T>
64
+ class MakeGarbageCollectedTraitBase
65
+ : private internal::MakeGarbageCollectedTraitInternal {
66
+ private:
67
+ static_assert(internal::IsGarbageCollectedType<T>::value,
68
+ "T needs to be a garbage collected object");
69
+ static_assert(!IsGarbageCollectedWithMixinTypeV<T> ||
70
+ sizeof(T) <=
71
+ internal::api_constants::kLargeObjectSizeThreshold,
72
+ "GarbageCollectedMixin may not be a large object");
73
+
74
+ template <typename U, typename CustomSpace>
75
+ struct SpacePolicy {
76
+ static void* Allocate(AllocationHandle& handle, size_t size) {
77
+ // Custom space.
78
+ static_assert(std::is_base_of<CustomSpaceBase, CustomSpace>::value,
79
+ "Custom space must inherit from CustomSpaceBase.");
80
+ return internal::MakeGarbageCollectedTraitInternal::Allocate(
81
+ handle, size, internal::GCInfoTrait<T>::Index(),
82
+ CustomSpace::kSpaceIndex);
83
+ }
84
+ };
85
+
86
+ template <typename U>
87
+ struct SpacePolicy<U, void> {
88
+ static void* Allocate(AllocationHandle& handle, size_t size) {
89
+ // Default space.
90
+ return internal::MakeGarbageCollectedTraitInternal::Allocate(
91
+ handle, size, internal::GCInfoTrait<T>::Index());
92
+ }
93
+ };
94
+
95
+ protected:
96
+ /**
97
+ * Allocates memory for an object of type T.
98
+ *
99
+ * \param handle AllocationHandle identifying the heap to allocate the object
100
+ * on.
101
+ * \param size The size that should be reserved for the object.
102
+ * \returns the memory to construct an object of type T on.
103
+ */
104
+ static void* Allocate(AllocationHandle& handle, size_t size) {
105
+ return SpacePolicy<T, typename SpaceTrait<T>::Space>::Allocate(handle,
106
+ size);
107
+ }
108
+
109
+ /**
110
+ * Marks an object as fully constructed, resulting in precise handling by the
111
+ * garbage collector.
112
+ *
113
+ * \param payload The base pointer the object is allocated at.
114
+ */
115
+ static void MarkObjectAsFullyConstructed(const void* payload) {
116
+ internal::MakeGarbageCollectedTraitInternal::MarkObjectAsFullyConstructed(
117
+ payload);
118
+ }
119
+ };
120
+
121
+ /**
122
+ * Passed to MakeGarbageCollected to specify how many bytes should be appended
123
+ * to the allocated object.
124
+ *
125
+ * Example:
126
+ * \code
127
+ * class InlinedArray final : public GarbageCollected<InlinedArray> {
128
+ * public:
129
+ * explicit InlinedArray(size_t bytes) : size(bytes), byte_array(this + 1) {}
130
+ * void Trace(Visitor*) const {}
131
+
132
+ * size_t size;
133
+ * char* byte_array;
134
+ * };
135
+ *
136
+ * auto* inlined_array = MakeGarbageCollected<InlinedArray(
137
+ * GetAllocationHandle(), AdditionalBytes(4), 4);
138
+ * for (size_t i = 0; i < 4; i++) {
139
+ * Process(inlined_array->byte_array[i]);
140
+ * }
141
+ * \endcode
142
+ */
143
+ struct AdditionalBytes {
144
+ constexpr explicit AdditionalBytes(size_t bytes) : value(bytes) {}
145
+ const size_t value;
146
+ };
147
+
148
+ /**
149
+ * Default trait class that specifies how to construct an object of type T.
150
+ * Advanced users may override how an object is constructed using the utilities
151
+ * that are provided through MakeGarbageCollectedTraitBase.
152
+ *
153
+ * Any trait overriding construction must
154
+ * - allocate through `MakeGarbageCollectedTraitBase<T>::Allocate`;
155
+ * - mark the object as fully constructed using
156
+ * `MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed`;
157
+ */
158
+ template <typename T>
159
+ class MakeGarbageCollectedTrait : public MakeGarbageCollectedTraitBase<T> {
160
+ public:
161
+ template <typename... Args>
162
+ static T* Call(AllocationHandle& handle, Args&&... args) {
163
+ void* memory =
164
+ MakeGarbageCollectedTraitBase<T>::Allocate(handle, sizeof(T));
165
+ T* object = ::new (memory) T(std::forward<Args>(args)...);
166
+ MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
167
+ return object;
168
+ }
169
+
170
+ template <typename... Args>
171
+ static T* Call(AllocationHandle& handle, AdditionalBytes additional_bytes,
172
+ Args&&... args) {
173
+ void* memory = MakeGarbageCollectedTraitBase<T>::Allocate(
174
+ handle, sizeof(T) + additional_bytes.value);
175
+ T* object = ::new (memory) T(std::forward<Args>(args)...);
176
+ MakeGarbageCollectedTraitBase<T>::MarkObjectAsFullyConstructed(object);
177
+ return object;
178
+ }
179
+ };
180
+
181
+ /**
182
+ * Allows users to specify a post-construction callback for specific types. The
183
+ * callback is invoked on the instance of type T right after it has been
184
+ * constructed. This can be useful when the callback requires a
185
+ * fully-constructed object to be able to dispatch to virtual methods.
186
+ */
187
+ template <typename T, typename = void>
188
+ struct PostConstructionCallbackTrait {
189
+ static void Call(T*) {}
190
+ };
191
+
192
+ /**
193
+ * Constructs a managed object of type T where T transitively inherits from
194
+ * GarbageCollected.
195
+ *
196
+ * \param args List of arguments with which an instance of T will be
197
+ * constructed.
198
+ * \returns an instance of type T.
199
+ */
200
+ template <typename T, typename... Args>
201
+ T* MakeGarbageCollected(AllocationHandle& handle, Args&&... args) {
202
+ T* object =
203
+ MakeGarbageCollectedTrait<T>::Call(handle, std::forward<Args>(args)...);
204
+ PostConstructionCallbackTrait<T>::Call(object);
205
+ return object;
206
+ }
207
+
208
+ /**
209
+ * Constructs a managed object of type T where T transitively inherits from
210
+ * GarbageCollected. Created objects will have additional bytes appended to
211
+ * it. Allocated memory would suffice for `sizeof(T) + additional_bytes`.
212
+ *
213
+ * \param additional_bytes Denotes how many bytes to append to T.
214
+ * \param args List of arguments with which an instance of T will be
215
+ * constructed.
216
+ * \returns an instance of type T.
217
+ */
218
+ template <typename T, typename... Args>
219
+ T* MakeGarbageCollected(AllocationHandle& handle,
220
+ AdditionalBytes additional_bytes, Args&&... args) {
221
+ T* object = MakeGarbageCollectedTrait<T>::Call(handle, additional_bytes,
222
+ std::forward<Args>(args)...);
223
+ PostConstructionCallbackTrait<T>::Call(object);
224
+ return object;
225
+ }
226
+
227
+ } // namespace cppgc
228
+
229
+ #endif // INCLUDE_CPPGC_ALLOCATION_H_
@@ -0,0 +1,29 @@
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_COMMON_H_
6
+ #define INCLUDE_CPPGC_COMMON_H_
7
+
8
+ // TODO(chromium:1056170): Remove dependency on v8.
9
+ #include "v8config.h" // NOLINT(build/include_directory)
10
+
11
+ namespace cppgc {
12
+
13
+ /**
14
+ * Indicator for the stack state of the embedder.
15
+ */
16
+ enum class EmbedderStackState {
17
+ /**
18
+ * Stack may contain interesting heap pointers.
19
+ */
20
+ kMayContainHeapPointers,
21
+ /**
22
+ * Stack does not contain any interesting heap pointers.
23
+ */
24
+ kNoHeapPointers,
25
+ };
26
+
27
+ } // namespace cppgc
28
+
29
+ #endif // INCLUDE_CPPGC_COMMON_H_
@@ -0,0 +1,345 @@
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_CROSS_THREAD_PERSISTENT_H_
6
+ #define INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
7
+
8
+ #include <atomic>
9
+
10
+ #include "cppgc/internal/persistent-node.h"
11
+ #include "cppgc/internal/pointer-policies.h"
12
+ #include "cppgc/persistent.h"
13
+ #include "cppgc/visitor.h"
14
+
15
+ namespace cppgc {
16
+
17
+ namespace internal {
18
+
19
+ template <typename T, typename WeaknessPolicy, typename LocationPolicy,
20
+ typename CheckingPolicy>
21
+ class BasicCrossThreadPersistent final : public PersistentBase,
22
+ public LocationPolicy,
23
+ private WeaknessPolicy,
24
+ private CheckingPolicy {
25
+ public:
26
+ using typename WeaknessPolicy::IsStrongPersistent;
27
+ using PointeeType = T;
28
+
29
+ ~BasicCrossThreadPersistent() { Clear(); }
30
+
31
+ BasicCrossThreadPersistent( // NOLINT
32
+ const SourceLocation& loc = SourceLocation::Current())
33
+ : LocationPolicy(loc) {}
34
+
35
+ BasicCrossThreadPersistent( // NOLINT
36
+ std::nullptr_t, const SourceLocation& loc = SourceLocation::Current())
37
+ : LocationPolicy(loc) {}
38
+
39
+ BasicCrossThreadPersistent( // NOLINT
40
+ SentinelPointer s, const SourceLocation& loc = SourceLocation::Current())
41
+ : PersistentBase(s), LocationPolicy(loc) {}
42
+
43
+ BasicCrossThreadPersistent( // NOLINT
44
+ T* raw, const SourceLocation& loc = SourceLocation::Current())
45
+ : PersistentBase(raw), LocationPolicy(loc) {
46
+ if (!IsValid(raw)) return;
47
+ PersistentRegion& region = this->GetPersistentRegion(raw);
48
+ SetNode(region.AllocateNode(this, &Trace));
49
+ this->CheckPointer(raw);
50
+ }
51
+
52
+ BasicCrossThreadPersistent( // NOLINT
53
+ T& raw, const SourceLocation& loc = SourceLocation::Current())
54
+ : BasicCrossThreadPersistent(&raw, loc) {}
55
+
56
+ template <typename U, typename MemberBarrierPolicy,
57
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
58
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
59
+ BasicCrossThreadPersistent( // NOLINT
60
+ internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
61
+ MemberCheckingPolicy>
62
+ member,
63
+ const SourceLocation& loc = SourceLocation::Current())
64
+ : BasicCrossThreadPersistent(member.Get(), loc) {}
65
+
66
+ BasicCrossThreadPersistent(
67
+ const BasicCrossThreadPersistent& other,
68
+ const SourceLocation& loc = SourceLocation::Current())
69
+ : BasicCrossThreadPersistent(loc) {
70
+ // Invoke operator=.
71
+ *this = other;
72
+ }
73
+
74
+ // Heterogeneous ctor.
75
+ template <typename U, typename OtherWeaknessPolicy,
76
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
77
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
78
+ BasicCrossThreadPersistent( // NOLINT
79
+ const BasicCrossThreadPersistent<U, OtherWeaknessPolicy,
80
+ OtherLocationPolicy,
81
+ OtherCheckingPolicy>& other,
82
+ const SourceLocation& loc = SourceLocation::Current())
83
+ : BasicCrossThreadPersistent(loc) {
84
+ *this = other;
85
+ }
86
+
87
+ BasicCrossThreadPersistent(
88
+ BasicCrossThreadPersistent&& other,
89
+ const SourceLocation& loc = SourceLocation::Current()) noexcept {
90
+ // Invoke operator=.
91
+ *this = std::move(other);
92
+ }
93
+
94
+ BasicCrossThreadPersistent& operator=(
95
+ const BasicCrossThreadPersistent& other) {
96
+ PersistentRegionLock guard;
97
+ AssignUnsafe(other.Get());
98
+ return *this;
99
+ }
100
+
101
+ template <typename U, typename OtherWeaknessPolicy,
102
+ typename OtherLocationPolicy, typename OtherCheckingPolicy,
103
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
104
+ BasicCrossThreadPersistent& operator=(
105
+ const BasicCrossThreadPersistent<U, OtherWeaknessPolicy,
106
+ OtherLocationPolicy,
107
+ OtherCheckingPolicy>& other) {
108
+ PersistentRegionLock guard;
109
+ AssignUnsafe(other.Get());
110
+ return *this;
111
+ }
112
+
113
+ BasicCrossThreadPersistent& operator=(BasicCrossThreadPersistent&& other) {
114
+ if (this == &other) return *this;
115
+ Clear();
116
+ PersistentRegionLock guard;
117
+ PersistentBase::operator=(std::move(other));
118
+ LocationPolicy::operator=(std::move(other));
119
+ if (!IsValid(GetValue())) return *this;
120
+ GetNode()->UpdateOwner(this);
121
+ other.SetValue(nullptr);
122
+ other.SetNode(nullptr);
123
+ this->CheckPointer(GetValue());
124
+ return *this;
125
+ }
126
+
127
+ BasicCrossThreadPersistent& operator=(T* other) {
128
+ Assign(other);
129
+ return *this;
130
+ }
131
+
132
+ // Assignment from member.
133
+ template <typename U, typename MemberBarrierPolicy,
134
+ typename MemberWeaknessTag, typename MemberCheckingPolicy,
135
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
136
+ BasicCrossThreadPersistent& operator=(
137
+ internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
138
+ MemberCheckingPolicy>
139
+ member) {
140
+ return operator=(member.Get());
141
+ }
142
+
143
+ BasicCrossThreadPersistent& operator=(std::nullptr_t) {
144
+ Clear();
145
+ return *this;
146
+ }
147
+
148
+ BasicCrossThreadPersistent& operator=(SentinelPointer s) {
149
+ Assign(s);
150
+ return *this;
151
+ }
152
+
153
+ /**
154
+ * Returns a pointer to the stored object.
155
+ *
156
+ * Note: **Not thread-safe.**
157
+ *
158
+ * \returns a pointer to the stored object.
159
+ */
160
+ // CFI cast exemption to allow passing SentinelPointer through T* and support
161
+ // heterogeneous assignments between different Member and Persistent handles
162
+ // based on their actual types.
163
+ V8_CLANG_NO_SANITIZE("cfi-unrelated-cast") T* Get() const {
164
+ return static_cast<T*>(const_cast<void*>(GetValue()));
165
+ }
166
+
167
+ /**
168
+ * Clears the stored object.
169
+ */
170
+ void Clear() {
171
+ // Simplified version of `Assign()` to allow calling without a complete type
172
+ // `T`.
173
+ const void* old_value = GetValue();
174
+ if (IsValid(old_value)) {
175
+ PersistentRegionLock guard;
176
+ PersistentRegion& region = this->GetPersistentRegion(old_value);
177
+ region.FreeNode(GetNode());
178
+ SetNode(nullptr);
179
+ }
180
+ SetValue(nullptr);
181
+ }
182
+
183
+ /**
184
+ * Returns a pointer to the stored object and releases it.
185
+ *
186
+ * Note: **Not thread-safe.**
187
+ *
188
+ * \returns a pointer to the stored object.
189
+ */
190
+ T* Release() {
191
+ T* result = Get();
192
+ Clear();
193
+ return result;
194
+ }
195
+
196
+ /**
197
+ * Conversio to boolean.
198
+ *
199
+ * Note: **Not thread-safe.**
200
+ *
201
+ * \returns true if an actual object has been stored and false otherwise.
202
+ */
203
+ explicit operator bool() const { return Get(); }
204
+
205
+ /**
206
+ * Conversion to object of type T.
207
+ *
208
+ * Note: **Not thread-safe.**
209
+ *
210
+ * \returns the object.
211
+ */
212
+ operator T*() const { return Get(); } // NOLINT
213
+
214
+ /**
215
+ * Dereferences the stored object.
216
+ *
217
+ * Note: **Not thread-safe.**
218
+ */
219
+ T* operator->() const { return Get(); }
220
+ T& operator*() const { return *Get(); }
221
+
222
+ template <typename U, typename OtherWeaknessPolicy = WeaknessPolicy,
223
+ typename OtherLocationPolicy = LocationPolicy,
224
+ typename OtherCheckingPolicy = CheckingPolicy>
225
+ BasicCrossThreadPersistent<U, OtherWeaknessPolicy, OtherLocationPolicy,
226
+ OtherCheckingPolicy>
227
+ To() const {
228
+ PersistentRegionLock guard;
229
+ return BasicCrossThreadPersistent<U, OtherWeaknessPolicy,
230
+ OtherLocationPolicy, OtherCheckingPolicy>(
231
+ static_cast<U*>(Get()));
232
+ }
233
+
234
+ template <typename U = T,
235
+ typename = typename std::enable_if<!BasicCrossThreadPersistent<
236
+ U, WeaknessPolicy>::IsStrongPersistent::value>::type>
237
+ BasicCrossThreadPersistent<U, internal::StrongCrossThreadPersistentPolicy>
238
+ Lock() const {
239
+ return BasicCrossThreadPersistent<
240
+ U, internal::StrongCrossThreadPersistentPolicy>(*this);
241
+ }
242
+
243
+ private:
244
+ static bool IsValid(const void* ptr) {
245
+ return ptr && ptr != kSentinelPointer;
246
+ }
247
+
248
+ static void Trace(Visitor* v, const void* ptr) {
249
+ const auto* handle = static_cast<const BasicCrossThreadPersistent*>(ptr);
250
+ v->TraceRoot(*handle, handle->Location());
251
+ }
252
+
253
+ void Assign(T* ptr) {
254
+ const void* old_value = GetValue();
255
+ if (IsValid(old_value)) {
256
+ PersistentRegionLock guard;
257
+ PersistentRegion& region = this->GetPersistentRegion(old_value);
258
+ if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) {
259
+ SetValue(ptr);
260
+ this->CheckPointer(ptr);
261
+ return;
262
+ }
263
+ region.FreeNode(GetNode());
264
+ SetNode(nullptr);
265
+ }
266
+ SetValue(ptr);
267
+ if (!IsValid(ptr)) return;
268
+ PersistentRegionLock guard;
269
+ SetNode(this->GetPersistentRegion(ptr).AllocateNode(this, &Trace));
270
+ this->CheckPointer(ptr);
271
+ }
272
+
273
+ void AssignUnsafe(T* ptr) {
274
+ PersistentRegionLock::AssertLocked();
275
+ const void* old_value = GetValue();
276
+ if (IsValid(old_value)) {
277
+ PersistentRegion& region = this->GetPersistentRegion(old_value);
278
+ if (IsValid(ptr) && (&region == &this->GetPersistentRegion(ptr))) {
279
+ SetValue(ptr);
280
+ this->CheckPointer(ptr);
281
+ return;
282
+ }
283
+ region.FreeNode(GetNode());
284
+ SetNode(nullptr);
285
+ }
286
+ SetValue(ptr);
287
+ if (!IsValid(ptr)) return;
288
+ SetNode(this->GetPersistentRegion(ptr).AllocateNode(this, &Trace));
289
+ this->CheckPointer(ptr);
290
+ }
291
+
292
+ void ClearFromGC() const {
293
+ if (IsValid(GetValue())) {
294
+ WeaknessPolicy::GetPersistentRegion(GetValue()).FreeNode(GetNode());
295
+ PersistentBase::ClearFromGC();
296
+ }
297
+ }
298
+
299
+ friend class cppgc::Visitor;
300
+ };
301
+
302
+ template <typename T, typename LocationPolicy, typename CheckingPolicy>
303
+ struct IsWeak<
304
+ BasicCrossThreadPersistent<T, internal::WeakCrossThreadPersistentPolicy,
305
+ LocationPolicy, CheckingPolicy>>
306
+ : std::true_type {};
307
+
308
+ } // namespace internal
309
+
310
+ namespace subtle {
311
+
312
+ /**
313
+ * **DO NOT USE: Has known caveats, see below.**
314
+ *
315
+ * CrossThreadPersistent allows retaining objects from threads other than the
316
+ * thread the owning heap is operating on.
317
+ *
318
+ * Known caveats:
319
+ * - Does not protect the heap owning an object from terminating.
320
+ * - Reaching transitively through the graph is unsupported as objects may be
321
+ * moved concurrently on the thread owning the object.
322
+ */
323
+ template <typename T>
324
+ using CrossThreadPersistent = internal::BasicCrossThreadPersistent<
325
+ T, internal::StrongCrossThreadPersistentPolicy>;
326
+
327
+ /**
328
+ * **DO NOT USE: Has known caveats, see below.**
329
+ *
330
+ * CrossThreadPersistent allows weakly retaining objects from threads other than
331
+ * the thread the owning heap is operating on.
332
+ *
333
+ * Known caveats:
334
+ * - Does not protect the heap owning an object from terminating.
335
+ * - Reaching transitively through the graph is unsupported as objects may be
336
+ * moved concurrently on the thread owning the object.
337
+ */
338
+ template <typename T>
339
+ using WeakCrossThreadPersistent = internal::BasicCrossThreadPersistent<
340
+ T, internal::WeakCrossThreadPersistentPolicy>;
341
+
342
+ } // namespace subtle
343
+ } // namespace cppgc
344
+
345
+ #endif // INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_