@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.0

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 (137) hide show
  1. package/include/node/cppgc/allocation.h +308 -0
  2. package/include/node/cppgc/common.h +28 -0
  3. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  4. package/include/node/cppgc/custom-space.h +97 -0
  5. package/include/node/cppgc/default-platform.h +68 -0
  6. package/include/node/cppgc/explicit-management.h +100 -0
  7. package/include/node/cppgc/garbage-collected.h +114 -0
  8. package/include/node/cppgc/heap-consistency.h +309 -0
  9. package/include/node/cppgc/heap-handle.h +48 -0
  10. package/include/node/cppgc/heap-state.h +82 -0
  11. package/include/node/cppgc/heap-statistics.h +126 -0
  12. package/include/node/cppgc/heap.h +202 -0
  13. package/include/node/cppgc/internal/api-constants.h +75 -0
  14. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  15. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  16. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  17. package/include/node/cppgc/internal/caged-heap.h +64 -0
  18. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  19. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  20. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  21. package/include/node/cppgc/internal/gc-info.h +150 -0
  22. package/include/node/cppgc/internal/logging.h +50 -0
  23. package/include/node/cppgc/internal/member-storage.h +305 -0
  24. package/include/node/cppgc/internal/name-trait.h +141 -0
  25. package/include/node/cppgc/internal/persistent-node.h +219 -0
  26. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  27. package/include/node/cppgc/internal/write-barrier.h +487 -0
  28. package/include/node/cppgc/liveness-broker.h +78 -0
  29. package/include/node/cppgc/macros.h +56 -0
  30. package/include/node/cppgc/member.h +669 -0
  31. package/include/node/cppgc/name-provider.h +75 -0
  32. package/include/node/cppgc/object-size-trait.h +58 -0
  33. package/include/node/cppgc/persistent.h +376 -0
  34. package/include/node/cppgc/platform.h +174 -0
  35. package/include/node/cppgc/prefinalizer.h +75 -0
  36. package/include/node/cppgc/process-heap-statistics.h +36 -0
  37. package/include/node/cppgc/sentinel-pointer.h +39 -0
  38. package/include/node/cppgc/source-location.h +16 -0
  39. package/include/node/cppgc/tagged-member.h +114 -0
  40. package/include/node/cppgc/testing.h +106 -0
  41. package/include/node/cppgc/trace-trait.h +127 -0
  42. package/include/node/cppgc/type-traits.h +272 -0
  43. package/include/node/cppgc/visitor.h +534 -0
  44. package/include/node/js_native_api.h +634 -0
  45. package/include/node/js_native_api_types.h +244 -0
  46. package/include/node/libplatform/libplatform-export.h +29 -0
  47. package/include/node/libplatform/libplatform.h +112 -0
  48. package/include/node/libplatform/v8-tracing.h +343 -0
  49. package/include/node/node.h +1744 -0
  50. package/include/node/node_api.h +265 -0
  51. package/include/node/node_api_types.h +58 -0
  52. package/include/node/node_buffer.h +94 -0
  53. package/include/node/node_object_wrap.h +145 -0
  54. package/include/node/node_version.h +116 -0
  55. package/include/node/uv/aix.h +32 -0
  56. package/include/node/uv/bsd.h +34 -0
  57. package/include/node/uv/darwin.h +61 -0
  58. package/include/node/uv/errno.h +483 -0
  59. package/include/node/uv/linux.h +34 -0
  60. package/include/node/uv/os390.h +33 -0
  61. package/include/node/uv/posix.h +31 -0
  62. package/include/node/uv/sunos.h +44 -0
  63. package/include/node/uv/threadpool.h +37 -0
  64. package/include/node/uv/tree.h +521 -0
  65. package/include/node/uv/unix.h +509 -0
  66. package/include/node/uv/version.h +43 -0
  67. package/include/node/uv/win.h +698 -0
  68. package/include/node/uv.h +1994 -0
  69. package/include/node/v8-array-buffer.h +646 -0
  70. package/include/node/v8-callbacks.h +533 -0
  71. package/include/node/v8-container.h +183 -0
  72. package/include/node/v8-context.h +580 -0
  73. package/include/node/v8-cpp-heap-external.h +56 -0
  74. package/include/node/v8-cppgc.h +194 -0
  75. package/include/node/v8-data.h +96 -0
  76. package/include/node/v8-date.h +57 -0
  77. package/include/node/v8-debug.h +210 -0
  78. package/include/node/v8-embedder-heap.h +54 -0
  79. package/include/node/v8-embedder-state-scope.h +52 -0
  80. package/include/node/v8-exception.h +298 -0
  81. package/include/node/v8-extension.h +60 -0
  82. package/include/node/v8-external-memory-accounter.h +60 -0
  83. package/include/node/v8-external.h +73 -0
  84. package/include/node/v8-fast-api-calls.h +784 -0
  85. package/include/node/v8-forward.h +82 -0
  86. package/include/node/v8-function-callback.h +708 -0
  87. package/include/node/v8-function.h +148 -0
  88. package/include/node/v8-handle-base.h +155 -0
  89. package/include/node/v8-initialization.h +343 -0
  90. package/include/node/v8-inspector-protocol.h +13 -0
  91. package/include/node/v8-inspector.h +458 -0
  92. package/include/node/v8-internal.h +1827 -0
  93. package/include/node/v8-isolate.h +1925 -0
  94. package/include/node/v8-json.h +54 -0
  95. package/include/node/v8-local-handle.h +884 -0
  96. package/include/node/v8-locker.h +138 -0
  97. package/include/node/v8-maybe.h +185 -0
  98. package/include/node/v8-memory-span.h +273 -0
  99. package/include/node/v8-message.h +215 -0
  100. package/include/node/v8-metrics.h +273 -0
  101. package/include/node/v8-microtask-queue.h +152 -0
  102. package/include/node/v8-microtask.h +28 -0
  103. package/include/node/v8-object.h +1134 -0
  104. package/include/node/v8-persistent-handle.h +556 -0
  105. package/include/node/v8-platform.h +1552 -0
  106. package/include/node/v8-primitive-object.h +118 -0
  107. package/include/node/v8-primitive.h +1056 -0
  108. package/include/node/v8-profiler.h +1401 -0
  109. package/include/node/v8-promise.h +185 -0
  110. package/include/node/v8-proxy.h +49 -0
  111. package/include/node/v8-regexp.h +105 -0
  112. package/include/node/v8-sandbox.h +170 -0
  113. package/include/node/v8-script.h +996 -0
  114. package/include/node/v8-snapshot.h +302 -0
  115. package/include/node/v8-source-location.h +91 -0
  116. package/include/node/v8-statistics.h +246 -0
  117. package/include/node/v8-template.h +1096 -0
  118. package/include/node/v8-trace-categories.h +28 -0
  119. package/include/node/v8-traced-handle.h +420 -0
  120. package/include/node/v8-typed-array.h +386 -0
  121. package/include/node/v8-unwinder-state.h +30 -0
  122. package/include/node/v8-unwinder.h +146 -0
  123. package/include/node/v8-util.h +549 -0
  124. package/include/node/v8-value-serializer-version.h +24 -0
  125. package/include/node/v8-value-serializer.h +316 -0
  126. package/include/node/v8-value.h +674 -0
  127. package/include/node/v8-version-string.h +38 -0
  128. package/include/node/v8-version.h +20 -0
  129. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  130. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  131. package/include/node/v8-wasm.h +325 -0
  132. package/include/node/v8-weak-callback-info.h +88 -0
  133. package/include/node/v8.h +88 -0
  134. package/include/node/v8config.h +1077 -0
  135. package/lib/libc++_shared.so +0 -0
  136. package/lib/libnode.so +4 -0
  137. package/package.json +23 -3
@@ -0,0 +1,556 @@
1
+ // Copyright 2021 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_PERSISTENT_HANDLE_H_
6
+ #define INCLUDE_V8_PERSISTENT_HANDLE_H_
7
+
8
+ #include "v8-internal.h" // NOLINT(build/include_directory)
9
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
10
+ #include "v8-weak-callback-info.h" // NOLINT(build/include_directory)
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace v8 {
14
+
15
+ class Isolate;
16
+ template <class K, class V, class T>
17
+ class PersistentValueMapBase;
18
+ template <class T>
19
+ class Global;
20
+ template <class T>
21
+ class PersistentBase;
22
+ template <class K, class V, class T>
23
+ class PersistentValueMap;
24
+ class Value;
25
+
26
+ namespace api_internal {
27
+ V8_EXPORT internal::Address* Eternalize(v8::Isolate* isolate, Value* handle);
28
+ V8_EXPORT internal::Address* CopyGlobalReference(internal::Address* from);
29
+ V8_EXPORT void DisposeGlobal(internal::Address* global_handle);
30
+ V8_EXPORT void MakeWeak(internal::Address** location_addr);
31
+ V8_EXPORT void* ClearWeak(internal::Address* location);
32
+ V8_EXPORT void AnnotateStrongRetainer(internal::Address* location,
33
+ const char* label);
34
+ V8_EXPORT internal::Address* GlobalizeReference(internal::Isolate* isolate,
35
+ internal::Address value);
36
+ V8_EXPORT void MoveGlobalReference(internal::Address** from,
37
+ internal::Address** to);
38
+ } // namespace api_internal
39
+
40
+ /**
41
+ * Eternal handles are set-once handles that live for the lifetime of the
42
+ * isolate.
43
+ */
44
+ template <class T>
45
+ class Eternal : public api_internal::IndirectHandleBase {
46
+ public:
47
+ V8_INLINE Eternal() = default;
48
+
49
+ /**
50
+ * Constructor for handling automatic up casting.
51
+ */
52
+ template <class S>
53
+ requires(std::is_base_of_v<T, S>)
54
+ V8_INLINE Eternal(Isolate* isolate, Local<S> handle) {
55
+ Set(isolate, handle);
56
+ }
57
+
58
+ // Can only be safely called if already set.
59
+ V8_INLINE Local<T> Get(Isolate* isolate) const {
60
+ // The eternal handle will never go away, so as with the roots, we don't
61
+ // even need to open a handle.
62
+ return Local<T>::FromSlot(slot());
63
+ }
64
+
65
+ template <class S>
66
+ requires(std::is_base_of_v<T, S>)
67
+ void Set(Isolate* isolate, Local<S> handle) {
68
+ slot() =
69
+ api_internal::Eternalize(isolate, *handle.template UnsafeAs<Value>());
70
+ }
71
+ };
72
+
73
+ namespace api_internal {
74
+ V8_EXPORT void MakeWeak(internal::Address* location, void* data,
75
+ WeakCallbackInfo<void>::Callback weak_callback,
76
+ WeakCallbackType type);
77
+ } // namespace api_internal
78
+
79
+ /**
80
+ * An object reference that is independent of any handle scope. Where
81
+ * a Local handle only lives as long as the HandleScope in which it was
82
+ * allocated, a PersistentBase handle remains valid until it is explicitly
83
+ * disposed using Reset().
84
+ *
85
+ * A persistent handle contains a reference to a storage cell within
86
+ * the V8 engine which holds an object value and which is updated by
87
+ * the garbage collector whenever the object is moved. A new storage
88
+ * cell can be created using the constructor or PersistentBase::Reset and
89
+ * existing handles can be disposed using PersistentBase::Reset.
90
+ *
91
+ */
92
+ template <class T>
93
+ class PersistentBase : public api_internal::IndirectHandleBase {
94
+ public:
95
+ /**
96
+ * If non-empty, destroy the underlying storage cell
97
+ * IsEmpty() will return true after this call.
98
+ */
99
+ V8_INLINE void Reset();
100
+
101
+ /**
102
+ * If non-empty, destroy the underlying storage cell
103
+ * and create a new one with the contents of other if other is non empty
104
+ */
105
+ template <class S>
106
+ V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
107
+
108
+ /**
109
+ * If non-empty, destroy the underlying storage cell
110
+ * and create a new one with the contents of other if other is non empty
111
+ */
112
+ template <class S>
113
+ V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
114
+
115
+ V8_INLINE Local<T> Get(Isolate* isolate) const {
116
+ return Local<T>::New(isolate, *this);
117
+ }
118
+
119
+ template <class S>
120
+ V8_INLINE bool operator==(const PersistentBase<S>& that) const {
121
+ return internal::HandleHelper::EqualHandles(*this, that);
122
+ }
123
+
124
+ template <class S>
125
+ V8_INLINE bool operator==(const Local<S>& that) const {
126
+ return internal::HandleHelper::EqualHandles(*this, that);
127
+ }
128
+
129
+ template <class S>
130
+ V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
131
+ return !operator==(that);
132
+ }
133
+
134
+ template <class S>
135
+ V8_INLINE bool operator!=(const Local<S>& that) const {
136
+ return !operator==(that);
137
+ }
138
+
139
+ /**
140
+ * Install a finalization callback on this object.
141
+ * NOTE: There is no guarantee as to *when* or even *if* the callback is
142
+ * invoked. The invocation is performed solely on a best effort basis.
143
+ * As always, GC-based finalization should *not* be relied upon for any
144
+ * critical form of resource management!
145
+ *
146
+ * The callback is supposed to reset the handle. No further V8 API may be
147
+ * called in this callback. In case additional work involving V8 needs to be
148
+ * done, a second callback can be scheduled using
149
+ * WeakCallbackInfo<void>::SetSecondPassCallback.
150
+ */
151
+ template <typename P>
152
+ V8_INLINE void SetWeak(P* parameter,
153
+ typename WeakCallbackInfo<P>::Callback callback,
154
+ WeakCallbackType type);
155
+
156
+ /**
157
+ * Turns this handle into a weak phantom handle without finalization callback.
158
+ * The handle will be reset automatically when the garbage collector detects
159
+ * that the object is no longer reachable.
160
+ */
161
+ V8_INLINE void SetWeak();
162
+
163
+ template <typename P>
164
+ V8_INLINE P* ClearWeak();
165
+
166
+ // TODO(dcarney): remove this.
167
+ V8_INLINE void ClearWeak() { ClearWeak<void>(); }
168
+
169
+ /**
170
+ * Annotates the strong handle with the given label, which is then used by the
171
+ * heap snapshot generator as a name of the edge from the root to the handle.
172
+ * The function does not take ownership of the label and assumes that the
173
+ * label is valid as long as the handle is valid.
174
+ */
175
+ V8_INLINE void AnnotateStrongRetainer(const char* label);
176
+
177
+ /** Returns true if the handle's reference is weak. */
178
+ V8_INLINE bool IsWeak() const;
179
+
180
+ /**
181
+ * Assigns a wrapper class ID to the handle.
182
+ */
183
+ V8_INLINE void SetWrapperClassId(uint16_t class_id);
184
+
185
+ /**
186
+ * Returns the class ID previously assigned to this handle or 0 if no class ID
187
+ * was previously assigned.
188
+ */
189
+ V8_INLINE uint16_t WrapperClassId() const;
190
+
191
+ PersistentBase(const PersistentBase& other) = delete;
192
+ void operator=(const PersistentBase&) = delete;
193
+
194
+ private:
195
+ friend class Isolate;
196
+ friend class Utils;
197
+ template <class F>
198
+ friend class Local;
199
+ template <class F1, class F2>
200
+ friend class Persistent;
201
+ template <class F>
202
+ friend class Global;
203
+ template <class F>
204
+ friend class PersistentBase;
205
+ template <class F>
206
+ friend class ReturnValue;
207
+ template <class F1, class F2, class F3>
208
+ friend class PersistentValueMapBase;
209
+ friend class Object;
210
+ friend class internal::ValueHelper;
211
+
212
+ V8_INLINE PersistentBase() = default;
213
+
214
+ V8_INLINE explicit PersistentBase(internal::Address* location)
215
+ : IndirectHandleBase(location) {}
216
+
217
+ V8_INLINE static internal::Address* New(Isolate* isolate, T* that);
218
+ };
219
+
220
+ /**
221
+ * Default traits for Persistent. This class does not allow
222
+ * use of the copy constructor or assignment operator.
223
+ * At present kResetInDestructor is not set, but that will change in a future
224
+ * version.
225
+ */
226
+ template <class T>
227
+ class NonCopyablePersistentTraits {
228
+ public:
229
+ using NonCopyablePersistent = Persistent<T, NonCopyablePersistentTraits<T>>;
230
+ static const bool kResetInDestructor = false;
231
+ template <class S, class M>
232
+ V8_INLINE static void Copy(const Persistent<S, M>& source,
233
+ NonCopyablePersistent* dest) {
234
+ static_assert(sizeof(S) < 0,
235
+ "NonCopyablePersistentTraits::Copy is not instantiable");
236
+ }
237
+ };
238
+
239
+ /**
240
+ * A PersistentBase which allows copy and assignment.
241
+ *
242
+ * Copy, assignment and destructor behavior is controlled by the traits
243
+ * class M.
244
+ *
245
+ * CAVEAT: Persistent objects do not have proper destruction behavior by default
246
+ * and as such will leak the object without explicit clear. Consider using
247
+ * `v8::Global` instead which has proper destruction and move semantics.
248
+ */
249
+ template <class T, class M>
250
+ class Persistent : public PersistentBase<T> {
251
+ public:
252
+ /**
253
+ * A Persistent with no storage cell.
254
+ */
255
+ V8_INLINE Persistent() = default;
256
+
257
+ /**
258
+ * Construct a Persistent from a Local with automatic up casting.
259
+ * When the Local is non-empty, a new storage cell is created
260
+ * pointing to the same object, and no flags are set.
261
+ */
262
+ template <class S>
263
+ requires(std::is_base_of_v<T, S>)
264
+ V8_INLINE Persistent(Isolate* isolate, Local<S> that)
265
+ : PersistentBase<T>(
266
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
267
+
268
+ /**
269
+ * Construct a Persistent from a Persistent with automatic up casting.
270
+ * When the Persistent is non-empty, a new storage cell is created
271
+ * pointing to the same object, and no flags are set.
272
+ */
273
+ template <class S, class M2>
274
+ requires(std::is_base_of_v<T, S>)
275
+ V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
276
+ : PersistentBase<T>(
277
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
278
+
279
+ /**
280
+ * The copy constructors and assignment operator create a Persistent
281
+ * exactly as the Persistent constructor, but the Copy function from the
282
+ * traits class is called, allowing the setting of flags based on the
283
+ * copied Persistent.
284
+ */
285
+ V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>() {
286
+ Copy(that);
287
+ }
288
+ template <class S, class M2>
289
+ V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>() {
290
+ Copy(that);
291
+ }
292
+ V8_INLINE Persistent& operator=(const Persistent& that) {
293
+ Copy(that);
294
+ return *this;
295
+ }
296
+ template <class S, class M2>
297
+ V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) {
298
+ Copy(that);
299
+ return *this;
300
+ }
301
+
302
+ /**
303
+ * The destructor will dispose the Persistent based on the
304
+ * kResetInDestructor flags in the traits class. Since not calling dispose
305
+ * can result in a memory leak, it is recommended to always set this flag.
306
+ */
307
+ V8_INLINE ~Persistent() {
308
+ if (M::kResetInDestructor) this->Reset();
309
+ }
310
+
311
+ // TODO(dcarney): this is pretty useless, fix or remove
312
+ template <class S, class M2>
313
+ V8_INLINE static Persistent<T, M>& Cast(const Persistent<S, M2>& that) {
314
+ #ifdef V8_ENABLE_CHECKS
315
+ // If we're going to perform the type check then we have to check
316
+ // that the handle isn't empty before doing the checked cast.
317
+ if (!that.IsEmpty()) T::Cast(that.template value<S>());
318
+ #endif
319
+ return reinterpret_cast<Persistent<T, M>&>(
320
+ const_cast<Persistent<S, M2>&>(that));
321
+ }
322
+
323
+ // TODO(dcarney): this is pretty useless, fix or remove
324
+ template <class S, class M2>
325
+ V8_INLINE Persistent<S, M2>& As() const {
326
+ return Persistent<S, M2>::Cast(*this);
327
+ }
328
+
329
+ private:
330
+ friend class Isolate;
331
+ friend class Utils;
332
+ template <class F>
333
+ friend class Local;
334
+ template <class F1, class F2>
335
+ friend class Persistent;
336
+ template <class F>
337
+ friend class ReturnValue;
338
+
339
+ template <class S, class M2>
340
+ V8_INLINE void Copy(const Persistent<S, M2>& that);
341
+ };
342
+
343
+ /**
344
+ * A PersistentBase which has move semantics.
345
+ *
346
+ * Note: Persistent class hierarchy is subject to future changes.
347
+ */
348
+ template <class T>
349
+ class Global : public PersistentBase<T> {
350
+ public:
351
+ /**
352
+ * A Global with no storage cell.
353
+ */
354
+ V8_INLINE Global() = default;
355
+
356
+ /**
357
+ * Construct a Global from a Local with automatic up casting.
358
+ * When the Local is non-empty, a new storage cell is created
359
+ * pointing to the same object, and no flags are set.
360
+ */
361
+ template <class S>
362
+ requires(std::is_base_of_v<T, S>)
363
+ V8_INLINE Global(Isolate* isolate, Local<S> that)
364
+ : PersistentBase<T>(
365
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
366
+
367
+ /**
368
+ * Construct a Global from a PersistentBase with automatic up casting.
369
+ * When the Persistent is non-empty, a new storage cell is created
370
+ * pointing to the same object, and no flags are set.
371
+ */
372
+ template <class S>
373
+ requires(std::is_base_of_v<T, S>)
374
+ V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
375
+ : PersistentBase<T>(
376
+ PersistentBase<T>::New(isolate, that.template value<S>())) {}
377
+
378
+ /**
379
+ * Move constructor.
380
+ */
381
+ V8_INLINE Global(Global&& other);
382
+
383
+ V8_INLINE ~Global() { this->Reset(); }
384
+
385
+ /**
386
+ * Move via assignment.
387
+ */
388
+ template <class S>
389
+ V8_INLINE Global& operator=(Global<S>&& rhs);
390
+
391
+ /**
392
+ * Pass allows returning uniques from functions, etc.
393
+ */
394
+ Global Pass() { return static_cast<Global&&>(*this); }
395
+
396
+ /*
397
+ * For compatibility with Chromium's base::Bind (base::Passed).
398
+ */
399
+ using MoveOnlyTypeForCPP03 = void;
400
+
401
+ Global(const Global&) = delete;
402
+ void operator=(const Global&) = delete;
403
+
404
+ private:
405
+ template <class F>
406
+ friend class ReturnValue;
407
+ };
408
+
409
+ // UniquePersistent is an alias for Global for historical reason.
410
+ template <class T>
411
+ using UniquePersistent = Global<T>;
412
+
413
+ /**
414
+ * Interface for iterating through all the persistent handles in the heap.
415
+ */
416
+ class V8_EXPORT PersistentHandleVisitor {
417
+ public:
418
+ virtual ~PersistentHandleVisitor() = default;
419
+ virtual void VisitPersistentHandle(Persistent<Value>* value,
420
+ uint16_t class_id) {}
421
+ };
422
+
423
+ template <class T>
424
+ internal::Address* PersistentBase<T>::New(Isolate* isolate, T* that) {
425
+ if (internal::ValueHelper::IsEmpty(that)) return nullptr;
426
+ return api_internal::GlobalizeReference(
427
+ reinterpret_cast<internal::Isolate*>(isolate),
428
+ internal::ValueHelper::ValueAsAddress(that));
429
+ }
430
+
431
+ template <class T, class M>
432
+ template <class S, class M2>
433
+ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
434
+ static_assert(std::is_base_of_v<T, S>, "type check");
435
+ this->Reset();
436
+ if (that.IsEmpty()) return;
437
+ this->slot() = api_internal::CopyGlobalReference(that.slot());
438
+ M::Copy(that, this);
439
+ }
440
+
441
+ template <class T>
442
+ bool PersistentBase<T>::IsWeak() const {
443
+ using I = internal::Internals;
444
+ if (this->IsEmpty()) return false;
445
+ return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
446
+ }
447
+
448
+ template <class T>
449
+ void PersistentBase<T>::Reset() {
450
+ if (this->IsEmpty()) return;
451
+ api_internal::DisposeGlobal(this->slot());
452
+ this->Clear();
453
+ }
454
+
455
+ /**
456
+ * If non-empty, destroy the underlying storage cell
457
+ * and create a new one with the contents of other if other is non empty
458
+ */
459
+ template <class T>
460
+ template <class S>
461
+ void PersistentBase<T>::Reset(Isolate* isolate, const Local<S>& other) {
462
+ static_assert(std::is_base_of_v<T, S>, "type check");
463
+ Reset();
464
+ if (other.IsEmpty()) return;
465
+ this->slot() = New(isolate, *other);
466
+ }
467
+
468
+ /**
469
+ * If non-empty, destroy the underlying storage cell
470
+ * and create a new one with the contents of other if other is non empty
471
+ */
472
+ template <class T>
473
+ template <class S>
474
+ void PersistentBase<T>::Reset(Isolate* isolate,
475
+ const PersistentBase<S>& other) {
476
+ static_assert(std::is_base_of_v<T, S>, "type check");
477
+ Reset();
478
+ if (other.IsEmpty()) return;
479
+ this->slot() = New(isolate, other.template value<S>());
480
+ }
481
+
482
+ template <class T>
483
+ template <typename P>
484
+ V8_INLINE void PersistentBase<T>::SetWeak(
485
+ P* parameter, typename WeakCallbackInfo<P>::Callback callback,
486
+ WeakCallbackType type) {
487
+ using Callback = WeakCallbackInfo<void>::Callback;
488
+ #if (__GNUC__ >= 8) || defined(__clang__)
489
+ #pragma GCC diagnostic push
490
+ #pragma GCC diagnostic ignored "-Wcast-function-type"
491
+ #endif
492
+ api_internal::MakeWeak(this->slot(), parameter,
493
+ reinterpret_cast<Callback>(callback), type);
494
+ #if (__GNUC__ >= 8) || defined(__clang__)
495
+ #pragma GCC diagnostic pop
496
+ #endif
497
+ }
498
+
499
+ template <class T>
500
+ void PersistentBase<T>::SetWeak() {
501
+ api_internal::MakeWeak(&this->slot());
502
+ }
503
+
504
+ template <class T>
505
+ template <typename P>
506
+ P* PersistentBase<T>::ClearWeak() {
507
+ return reinterpret_cast<P*>(api_internal::ClearWeak(this->slot()));
508
+ }
509
+
510
+ template <class T>
511
+ void PersistentBase<T>::AnnotateStrongRetainer(const char* label) {
512
+ api_internal::AnnotateStrongRetainer(this->slot(), label);
513
+ }
514
+
515
+ template <class T>
516
+ void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
517
+ using I = internal::Internals;
518
+ if (this->IsEmpty()) return;
519
+ uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
520
+ *reinterpret_cast<uint16_t*>(addr) = class_id;
521
+ }
522
+
523
+ template <class T>
524
+ uint16_t PersistentBase<T>::WrapperClassId() const {
525
+ using I = internal::Internals;
526
+ if (this->IsEmpty()) return 0;
527
+ uint8_t* addr = reinterpret_cast<uint8_t*>(slot()) + I::kNodeClassIdOffset;
528
+ return *reinterpret_cast<uint16_t*>(addr);
529
+ }
530
+
531
+ template <class T>
532
+ Global<T>::Global(Global&& other) : PersistentBase<T>(other.slot()) {
533
+ if (!other.IsEmpty()) {
534
+ api_internal::MoveGlobalReference(&other.slot(), &this->slot());
535
+ other.Clear();
536
+ }
537
+ }
538
+
539
+ template <class T>
540
+ template <class S>
541
+ Global<T>& Global<T>::operator=(Global<S>&& rhs) {
542
+ static_assert(std::is_base_of_v<T, S>, "type check");
543
+ if (this != &rhs) {
544
+ this->Reset();
545
+ if (!rhs.IsEmpty()) {
546
+ this->slot() = rhs.slot();
547
+ api_internal::MoveGlobalReference(&rhs.slot(), &this->slot());
548
+ rhs.Clear();
549
+ }
550
+ }
551
+ return *this;
552
+ }
553
+
554
+ } // namespace v8
555
+
556
+ #endif // INCLUDE_V8_PERSISTENT_HANDLE_H_