libv8-node 15.5.1.0.beta1-arm64-darwin-21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/ext/libv8-node/.location.yml +2 -0
  3. data/ext/libv8-node/location.rb +91 -0
  4. data/ext/libv8-node/paths.rb +30 -0
  5. data/lib/libv8/node/version.rb +7 -0
  6. data/lib/libv8/node.rb +11 -0
  7. data/lib/libv8-node.rb +1 -0
  8. data/vendor/v8/include/cppgc/allocation.h +173 -0
  9. data/vendor/v8/include/cppgc/common.h +26 -0
  10. data/vendor/v8/include/cppgc/custom-space.h +62 -0
  11. data/vendor/v8/include/cppgc/default-platform.h +76 -0
  12. data/vendor/v8/include/cppgc/garbage-collected.h +116 -0
  13. data/vendor/v8/include/cppgc/heap.h +139 -0
  14. data/vendor/v8/include/cppgc/internal/api-constants.h +47 -0
  15. data/vendor/v8/include/cppgc/internal/atomic-entry-flag.h +48 -0
  16. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +67 -0
  17. data/vendor/v8/include/cppgc/internal/compiler-specific.h +38 -0
  18. data/vendor/v8/include/cppgc/internal/finalizer-trait.h +90 -0
  19. data/vendor/v8/include/cppgc/internal/gc-info.h +45 -0
  20. data/vendor/v8/include/cppgc/internal/logging.h +50 -0
  21. data/vendor/v8/include/cppgc/internal/persistent-node.h +116 -0
  22. data/vendor/v8/include/cppgc/internal/pointer-policies.h +134 -0
  23. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +30 -0
  24. data/vendor/v8/include/cppgc/internal/process-heap.h +34 -0
  25. data/vendor/v8/include/cppgc/internal/write-barrier.h +78 -0
  26. data/vendor/v8/include/cppgc/liveness-broker.h +68 -0
  27. data/vendor/v8/include/cppgc/macros.h +24 -0
  28. data/vendor/v8/include/cppgc/member.h +226 -0
  29. data/vendor/v8/include/cppgc/persistent.h +341 -0
  30. data/vendor/v8/include/cppgc/platform.h +130 -0
  31. data/vendor/v8/include/cppgc/prefinalizer.h +52 -0
  32. data/vendor/v8/include/cppgc/source-location.h +91 -0
  33. data/vendor/v8/include/cppgc/trace-trait.h +111 -0
  34. data/vendor/v8/include/cppgc/type-traits.h +109 -0
  35. data/vendor/v8/include/cppgc/visitor.h +213 -0
  36. data/vendor/v8/include/libplatform/libplatform-export.h +29 -0
  37. data/vendor/v8/include/libplatform/libplatform.h +106 -0
  38. data/vendor/v8/include/libplatform/v8-tracing.h +332 -0
  39. data/vendor/v8/include/v8-cppgc.h +226 -0
  40. data/vendor/v8/include/v8-fast-api-calls.h +388 -0
  41. data/vendor/v8/include/v8-inspector-protocol.h +13 -0
  42. data/vendor/v8/include/v8-inspector.h +327 -0
  43. data/vendor/v8/include/v8-internal.h +427 -0
  44. data/vendor/v8/include/v8-metrics.h +133 -0
  45. data/vendor/v8/include/v8-platform.h +684 -0
  46. data/vendor/v8/include/v8-profiler.h +1059 -0
  47. data/vendor/v8/include/v8-util.h +652 -0
  48. data/vendor/v8/include/v8-value-serializer-version.h +24 -0
  49. data/vendor/v8/include/v8-version-string.h +38 -0
  50. data/vendor/v8/include/v8-version.h +20 -0
  51. data/vendor/v8/include/v8-wasm-trap-handler-posix.h +31 -0
  52. data/vendor/v8/include/v8-wasm-trap-handler-win.h +28 -0
  53. data/vendor/v8/include/v8.h +12098 -0
  54. data/vendor/v8/include/v8config.h +484 -0
  55. data/vendor/v8/out.gn/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +112 -0
@@ -0,0 +1,332 @@
1
+ // Copyright 2016 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 V8_LIBPLATFORM_V8_TRACING_H_
6
+ #define V8_LIBPLATFORM_V8_TRACING_H_
7
+
8
+ #include <atomic>
9
+ #include <fstream>
10
+ #include <memory>
11
+ #include <unordered_set>
12
+ #include <vector>
13
+
14
+ #include "libplatform/libplatform-export.h"
15
+ #include "v8-platform.h" // NOLINT(build/include_directory)
16
+
17
+ namespace perfetto {
18
+ namespace trace_processor {
19
+ class TraceProcessorStorage;
20
+ }
21
+ class TracingSession;
22
+ }
23
+
24
+ namespace v8 {
25
+
26
+ namespace base {
27
+ class Mutex;
28
+ } // namespace base
29
+
30
+ namespace platform {
31
+ namespace tracing {
32
+
33
+ class TraceEventListener;
34
+
35
+ const int kTraceMaxNumArgs = 2;
36
+
37
+ class V8_PLATFORM_EXPORT TraceObject {
38
+ public:
39
+ union ArgValue {
40
+ V8_DEPRECATED("use as_uint ? true : false") bool as_bool;
41
+ uint64_t as_uint;
42
+ int64_t as_int;
43
+ double as_double;
44
+ const void* as_pointer;
45
+ const char* as_string;
46
+ };
47
+
48
+ TraceObject() = default;
49
+ ~TraceObject();
50
+ void Initialize(
51
+ char phase, const uint8_t* category_enabled_flag, const char* name,
52
+ const char* scope, uint64_t id, uint64_t bind_id, int num_args,
53
+ const char** arg_names, const uint8_t* arg_types,
54
+ const uint64_t* arg_values,
55
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
56
+ unsigned int flags, int64_t timestamp, int64_t cpu_timestamp);
57
+ void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp);
58
+ void InitializeForTesting(
59
+ char phase, const uint8_t* category_enabled_flag, const char* name,
60
+ const char* scope, uint64_t id, uint64_t bind_id, int num_args,
61
+ const char** arg_names, const uint8_t* arg_types,
62
+ const uint64_t* arg_values,
63
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
64
+ unsigned int flags, int pid, int tid, int64_t ts, int64_t tts,
65
+ uint64_t duration, uint64_t cpu_duration);
66
+
67
+ int pid() const { return pid_; }
68
+ int tid() const { return tid_; }
69
+ char phase() const { return phase_; }
70
+ const uint8_t* category_enabled_flag() const {
71
+ return category_enabled_flag_;
72
+ }
73
+ const char* name() const { return name_; }
74
+ const char* scope() const { return scope_; }
75
+ uint64_t id() const { return id_; }
76
+ uint64_t bind_id() const { return bind_id_; }
77
+ int num_args() const { return num_args_; }
78
+ const char** arg_names() { return arg_names_; }
79
+ uint8_t* arg_types() { return arg_types_; }
80
+ ArgValue* arg_values() { return arg_values_; }
81
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables() {
82
+ return arg_convertables_;
83
+ }
84
+ unsigned int flags() const { return flags_; }
85
+ int64_t ts() { return ts_; }
86
+ int64_t tts() { return tts_; }
87
+ uint64_t duration() { return duration_; }
88
+ uint64_t cpu_duration() { return cpu_duration_; }
89
+
90
+ private:
91
+ int pid_;
92
+ int tid_;
93
+ char phase_;
94
+ const char* name_;
95
+ const char* scope_;
96
+ const uint8_t* category_enabled_flag_;
97
+ uint64_t id_;
98
+ uint64_t bind_id_;
99
+ int num_args_ = 0;
100
+ const char* arg_names_[kTraceMaxNumArgs];
101
+ uint8_t arg_types_[kTraceMaxNumArgs];
102
+ ArgValue arg_values_[kTraceMaxNumArgs];
103
+ std::unique_ptr<v8::ConvertableToTraceFormat>
104
+ arg_convertables_[kTraceMaxNumArgs];
105
+ char* parameter_copy_storage_ = nullptr;
106
+ unsigned int flags_;
107
+ int64_t ts_;
108
+ int64_t tts_;
109
+ uint64_t duration_;
110
+ uint64_t cpu_duration_;
111
+
112
+ // Disallow copy and assign
113
+ TraceObject(const TraceObject&) = delete;
114
+ void operator=(const TraceObject&) = delete;
115
+ };
116
+
117
+ class V8_PLATFORM_EXPORT TraceWriter {
118
+ public:
119
+ TraceWriter() = default;
120
+ virtual ~TraceWriter() = default;
121
+ virtual void AppendTraceEvent(TraceObject* trace_event) = 0;
122
+ virtual void Flush() = 0;
123
+
124
+ static TraceWriter* CreateJSONTraceWriter(std::ostream& stream);
125
+ static TraceWriter* CreateJSONTraceWriter(std::ostream& stream,
126
+ const std::string& tag);
127
+
128
+ private:
129
+ // Disallow copy and assign
130
+ TraceWriter(const TraceWriter&) = delete;
131
+ void operator=(const TraceWriter&) = delete;
132
+ };
133
+
134
+ class V8_PLATFORM_EXPORT TraceBufferChunk {
135
+ public:
136
+ explicit TraceBufferChunk(uint32_t seq);
137
+
138
+ void Reset(uint32_t new_seq);
139
+ bool IsFull() const { return next_free_ == kChunkSize; }
140
+ TraceObject* AddTraceEvent(size_t* event_index);
141
+ TraceObject* GetEventAt(size_t index) { return &chunk_[index]; }
142
+
143
+ uint32_t seq() const { return seq_; }
144
+ size_t size() const { return next_free_; }
145
+
146
+ static const size_t kChunkSize = 64;
147
+
148
+ private:
149
+ size_t next_free_ = 0;
150
+ TraceObject chunk_[kChunkSize];
151
+ uint32_t seq_;
152
+
153
+ // Disallow copy and assign
154
+ TraceBufferChunk(const TraceBufferChunk&) = delete;
155
+ void operator=(const TraceBufferChunk&) = delete;
156
+ };
157
+
158
+ class V8_PLATFORM_EXPORT TraceBuffer {
159
+ public:
160
+ TraceBuffer() = default;
161
+ virtual ~TraceBuffer() = default;
162
+
163
+ virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0;
164
+ virtual TraceObject* GetEventByHandle(uint64_t handle) = 0;
165
+ virtual bool Flush() = 0;
166
+
167
+ static const size_t kRingBufferChunks = 1024;
168
+
169
+ static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks,
170
+ TraceWriter* trace_writer);
171
+
172
+ private:
173
+ // Disallow copy and assign
174
+ TraceBuffer(const TraceBuffer&) = delete;
175
+ void operator=(const TraceBuffer&) = delete;
176
+ };
177
+
178
+ // Options determines how the trace buffer stores data.
179
+ enum TraceRecordMode {
180
+ // Record until the trace buffer is full.
181
+ RECORD_UNTIL_FULL,
182
+
183
+ // Record until the user ends the trace. The trace buffer is a fixed size
184
+ // and we use it as a ring buffer during recording.
185
+ RECORD_CONTINUOUSLY,
186
+
187
+ // Record until the trace buffer is full, but with a huge buffer size.
188
+ RECORD_AS_MUCH_AS_POSSIBLE,
189
+
190
+ // Echo to console. Events are discarded.
191
+ ECHO_TO_CONSOLE,
192
+ };
193
+
194
+ class V8_PLATFORM_EXPORT TraceConfig {
195
+ public:
196
+ typedef std::vector<std::string> StringList;
197
+
198
+ static TraceConfig* CreateDefaultTraceConfig();
199
+
200
+ TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {}
201
+ TraceRecordMode GetTraceRecordMode() const { return record_mode_; }
202
+ const StringList& GetEnabledCategories() const {
203
+ return included_categories_;
204
+ }
205
+ bool IsSystraceEnabled() const { return enable_systrace_; }
206
+ bool IsArgumentFilterEnabled() const { return enable_argument_filter_; }
207
+
208
+ void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; }
209
+ void EnableSystrace() { enable_systrace_ = true; }
210
+ void EnableArgumentFilter() { enable_argument_filter_ = true; }
211
+
212
+ void AddIncludedCategory(const char* included_category);
213
+
214
+ bool IsCategoryGroupEnabled(const char* category_group) const;
215
+
216
+ private:
217
+ TraceRecordMode record_mode_;
218
+ bool enable_systrace_ : 1;
219
+ bool enable_argument_filter_ : 1;
220
+ StringList included_categories_;
221
+
222
+ // Disallow copy and assign
223
+ TraceConfig(const TraceConfig&) = delete;
224
+ void operator=(const TraceConfig&) = delete;
225
+ };
226
+
227
+ #if defined(_MSC_VER)
228
+ #define V8_PLATFORM_NON_EXPORTED_BASE(code) \
229
+ __pragma(warning(suppress : 4275)) code
230
+ #else
231
+ #define V8_PLATFORM_NON_EXPORTED_BASE(code) code
232
+ #endif // defined(_MSC_VER)
233
+
234
+ class V8_PLATFORM_EXPORT TracingController
235
+ : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) {
236
+ public:
237
+ TracingController();
238
+ ~TracingController() override;
239
+
240
+ #if defined(V8_USE_PERFETTO)
241
+ // Must be called before StartTracing() if V8_USE_PERFETTO is true. Provides
242
+ // the output stream for the JSON trace data.
243
+ void InitializeForPerfetto(std::ostream* output_stream);
244
+ // Provide an optional listener for testing that will receive trace events.
245
+ // Must be called before StartTracing().
246
+ void SetTraceEventListenerForTesting(TraceEventListener* listener);
247
+ #else // defined(V8_USE_PERFETTO)
248
+ // The pointer returned from GetCategoryGroupEnabled() points to a value with
249
+ // zero or more of the following bits. Used in this class only. The
250
+ // TRACE_EVENT macros should only use the value as a bool. These values must
251
+ // be in sync with macro values in TraceEvent.h in Blink.
252
+ enum CategoryGroupEnabledFlags {
253
+ // Category group enabled for the recording mode.
254
+ ENABLED_FOR_RECORDING = 1 << 0,
255
+ // Category group enabled by SetEventCallbackEnabled().
256
+ ENABLED_FOR_EVENT_CALLBACK = 1 << 2,
257
+ // Category group enabled to export events to ETW.
258
+ ENABLED_FOR_ETW_EXPORT = 1 << 3
259
+ };
260
+
261
+ // Takes ownership of |trace_buffer|.
262
+ void Initialize(TraceBuffer* trace_buffer);
263
+
264
+ // v8::TracingController implementation.
265
+ const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
266
+ uint64_t AddTraceEvent(
267
+ char phase, const uint8_t* category_enabled_flag, const char* name,
268
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
269
+ const char** arg_names, const uint8_t* arg_types,
270
+ const uint64_t* arg_values,
271
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
272
+ unsigned int flags) override;
273
+ uint64_t AddTraceEventWithTimestamp(
274
+ char phase, const uint8_t* category_enabled_flag, const char* name,
275
+ const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
276
+ const char** arg_names, const uint8_t* arg_types,
277
+ const uint64_t* arg_values,
278
+ std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
279
+ unsigned int flags, int64_t timestamp) override;
280
+ void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
281
+ const char* name, uint64_t handle) override;
282
+
283
+ static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag);
284
+ #endif // !defined(V8_USE_PERFETTO)
285
+
286
+ void AddTraceStateObserver(
287
+ v8::TracingController::TraceStateObserver* observer) override;
288
+ void RemoveTraceStateObserver(
289
+ v8::TracingController::TraceStateObserver* observer) override;
290
+
291
+ void StartTracing(TraceConfig* trace_config);
292
+ void StopTracing();
293
+
294
+ protected:
295
+ #if !defined(V8_USE_PERFETTO)
296
+ virtual int64_t CurrentTimestampMicroseconds();
297
+ virtual int64_t CurrentCpuTimestampMicroseconds();
298
+ #endif // !defined(V8_USE_PERFETTO)
299
+
300
+ private:
301
+ #if !defined(V8_USE_PERFETTO)
302
+ void UpdateCategoryGroupEnabledFlag(size_t category_index);
303
+ void UpdateCategoryGroupEnabledFlags();
304
+ #endif // !defined(V8_USE_PERFETTO)
305
+
306
+ std::unique_ptr<base::Mutex> mutex_;
307
+ std::unique_ptr<TraceConfig> trace_config_;
308
+ std::atomic_bool recording_{false};
309
+ std::unordered_set<v8::TracingController::TraceStateObserver*> observers_;
310
+
311
+ #if defined(V8_USE_PERFETTO)
312
+ std::ostream* output_stream_ = nullptr;
313
+ std::unique_ptr<perfetto::trace_processor::TraceProcessorStorage>
314
+ trace_processor_;
315
+ TraceEventListener* listener_for_testing_ = nullptr;
316
+ std::unique_ptr<perfetto::TracingSession> tracing_session_;
317
+ #else // !defined(V8_USE_PERFETTO)
318
+ std::unique_ptr<TraceBuffer> trace_buffer_;
319
+ #endif // !defined(V8_USE_PERFETTO)
320
+
321
+ // Disallow copy and assign
322
+ TracingController(const TracingController&) = delete;
323
+ void operator=(const TracingController&) = delete;
324
+ };
325
+
326
+ #undef V8_PLATFORM_NON_EXPORTED_BASE
327
+
328
+ } // namespace tracing
329
+ } // namespace platform
330
+ } // namespace v8
331
+
332
+ #endif // V8_LIBPLATFORM_V8_TRACING_H_
@@ -0,0 +1,226 @@
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_V8_CPPGC_H_
6
+ #define INCLUDE_V8_CPPGC_H_
7
+
8
+ #include "cppgc/visitor.h"
9
+ #include "v8-internal.h" // NOLINT(build/include_directory)
10
+ #include "v8.h" // NOLINT(build/include_directory)
11
+
12
+ namespace v8 {
13
+
14
+ class Isolate;
15
+ template <typename T>
16
+ class JSMember;
17
+
18
+ namespace internal {
19
+
20
+ class JSMemberBaseExtractor;
21
+
22
+ class V8_EXPORT JSMemberBase {
23
+ public:
24
+ /**
25
+ * Returns true if the reference is empty, i.e., has not been assigned
26
+ * object.
27
+ */
28
+ bool IsEmpty() const { return val_ == nullptr; }
29
+
30
+ /**
31
+ * Clears the reference. IsEmpty() will return true after this call.
32
+ */
33
+ inline void Reset();
34
+
35
+ private:
36
+ static internal::Address* New(v8::Isolate* isolate,
37
+ internal::Address* object_slot,
38
+ internal::Address** this_slot);
39
+ static void Delete(internal::Address* object);
40
+ static void Copy(const internal::Address* const* from_slot,
41
+ internal::Address** to_slot);
42
+ static void Move(internal::Address** from_slot, internal::Address** to_slot);
43
+
44
+ JSMemberBase() = default;
45
+
46
+ JSMemberBase(v8::Isolate* isolate, internal::Address* object_slot)
47
+ : val_(New(isolate, object_slot, &val_)) {}
48
+
49
+ inline JSMemberBase& CopyImpl(const JSMemberBase& other);
50
+ inline JSMemberBase& MoveImpl(JSMemberBase&& other);
51
+
52
+ // val_ points to a GlobalHandles node.
53
+ internal::Address* val_ = nullptr;
54
+
55
+ template <typename T>
56
+ friend class v8::JSMember;
57
+ friend class v8::internal::JSMemberBaseExtractor;
58
+ };
59
+
60
+ JSMemberBase& JSMemberBase::CopyImpl(const JSMemberBase& other) {
61
+ if (this != &other) {
62
+ Reset();
63
+ if (!other.IsEmpty()) {
64
+ Copy(&other.val_, &val_);
65
+ }
66
+ }
67
+ return *this;
68
+ }
69
+
70
+ JSMemberBase& JSMemberBase::MoveImpl(JSMemberBase&& other) {
71
+ if (this != &other) {
72
+ // No call to Reset() as Move() will conditionally reset itself when needed,
73
+ // and otherwise reuse the internal meta data.
74
+ Move(&other.val_, &val_);
75
+ }
76
+ return *this;
77
+ }
78
+
79
+ void JSMemberBase::Reset() {
80
+ if (IsEmpty()) return;
81
+ Delete(val_);
82
+ val_ = nullptr;
83
+ }
84
+
85
+ } // namespace internal
86
+
87
+ /**
88
+ * A traced handle without destructor that clears the handle. The handle may
89
+ * only be used in GarbageCollected objects and must be processed in a Trace()
90
+ * method.
91
+ */
92
+ template <typename T>
93
+ class V8_EXPORT JSMember : public internal::JSMemberBase {
94
+ static_assert(std::is_base_of<v8::Value, T>::value,
95
+ "JSMember only supports references to v8::Value");
96
+
97
+ public:
98
+ JSMember() = default;
99
+
100
+ template <typename U,
101
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
102
+ JSMember(Isolate* isolate, Local<U> that)
103
+ : internal::JSMemberBase(isolate,
104
+ reinterpret_cast<internal::Address*>(*that)) {}
105
+
106
+ JSMember(const JSMember& other) { CopyImpl(other); }
107
+
108
+ template <typename U,
109
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
110
+ JSMember(const JSMember<U>& other) { // NOLINT
111
+ CopyImpl(other);
112
+ }
113
+
114
+ JSMember(JSMember&& other) { MoveImpl(std::move(other)); }
115
+
116
+ template <typename U,
117
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
118
+ JSMember(JSMember<U>&& other) { // NOLINT
119
+ MoveImpl(std::move(other));
120
+ }
121
+
122
+ JSMember& operator=(const JSMember& other) { return CopyImpl(other); }
123
+
124
+ template <typename U,
125
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
126
+ JSMember& operator=(const JSMember<U>& other) {
127
+ return CopyImpl(other);
128
+ }
129
+
130
+ JSMember& operator=(JSMember&& other) { return MoveImpl(other); }
131
+
132
+ template <typename U,
133
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
134
+ JSMember& operator=(JSMember<U>&& other) {
135
+ return MoveImpl(other);
136
+ }
137
+
138
+ T* operator->() const { return reinterpret_cast<T*>(val_); }
139
+ T* operator*() const { return reinterpret_cast<T*>(val_); }
140
+
141
+ using internal::JSMemberBase::Reset;
142
+
143
+ template <typename U,
144
+ typename = std::enable_if_t<std::is_base_of<T, U>::value>>
145
+ void Set(v8::Isolate* isolate, Local<U> that) {
146
+ Reset();
147
+ val_ = New(isolate, reinterpret_cast<internal::Address*>(*that), &val_);
148
+ }
149
+ };
150
+
151
+ template <typename T1, typename T2,
152
+ typename = std::enable_if_t<std::is_base_of<T2, T1>::value ||
153
+ std::is_base_of<T1, T2>::value>>
154
+ inline bool operator==(const JSMember<T1>& lhs, const JSMember<T2>& rhs) {
155
+ v8::internal::Address* a = reinterpret_cast<v8::internal::Address*>(*lhs);
156
+ v8::internal::Address* b = reinterpret_cast<v8::internal::Address*>(*rhs);
157
+ if (a == nullptr) return b == nullptr;
158
+ if (b == nullptr) return false;
159
+ return *a == *b;
160
+ }
161
+
162
+ template <typename T1, typename T2,
163
+ typename = std::enable_if_t<std::is_base_of<T2, T1>::value ||
164
+ std::is_base_of<T1, T2>::value>>
165
+ inline bool operator!=(const JSMember<T1>& lhs, const JSMember<T2>& rhs) {
166
+ return !(lhs == rhs);
167
+ }
168
+
169
+ template <typename T1, typename T2,
170
+ typename = std::enable_if_t<std::is_base_of<T2, T1>::value ||
171
+ std::is_base_of<T1, T2>::value>>
172
+ inline bool operator==(const JSMember<T1>& lhs, const Local<T2>& rhs) {
173
+ v8::internal::Address* a = reinterpret_cast<v8::internal::Address*>(*lhs);
174
+ v8::internal::Address* b = reinterpret_cast<v8::internal::Address*>(*rhs);
175
+ if (a == nullptr) return b == nullptr;
176
+ if (b == nullptr) return false;
177
+ return *a == *b;
178
+ }
179
+
180
+ template <typename T1, typename T2,
181
+ typename = std::enable_if_t<std::is_base_of<T2, T1>::value ||
182
+ std::is_base_of<T1, T2>::value>>
183
+ inline bool operator==(const Local<T1>& lhs, const JSMember<T2> rhs) {
184
+ return rhs == lhs;
185
+ }
186
+
187
+ template <typename T1, typename T2>
188
+ inline bool operator!=(const JSMember<T1>& lhs, const T2& rhs) {
189
+ return !(lhs == rhs);
190
+ }
191
+
192
+ template <typename T1, typename T2>
193
+ inline bool operator!=(const T1& lhs, const JSMember<T2>& rhs) {
194
+ return !(lhs == rhs);
195
+ }
196
+
197
+ class JSVisitor : public cppgc::Visitor {
198
+ public:
199
+ explicit JSVisitor(cppgc::Visitor::Key key) : cppgc::Visitor(key) {}
200
+
201
+ template <typename T>
202
+ void Trace(const JSMember<T>& ref) {
203
+ if (ref.IsEmpty()) return;
204
+ Visit(ref);
205
+ }
206
+
207
+ protected:
208
+ using cppgc::Visitor::Visit;
209
+
210
+ virtual void Visit(const internal::JSMemberBase& ref) {}
211
+ };
212
+
213
+ } // namespace v8
214
+
215
+ namespace cppgc {
216
+
217
+ template <typename T>
218
+ struct TraceTrait<v8::JSMember<T>> {
219
+ static void Trace(Visitor* visitor, const v8::JSMember<T>* self) {
220
+ static_cast<v8::JSVisitor*>(visitor)->Trace(*self);
221
+ }
222
+ };
223
+
224
+ } // namespace cppgc
225
+
226
+ #endif // INCLUDE_V8_CPPGC_H_