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

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 (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -0,0 +1,884 @@
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_LOCAL_HANDLE_H_
6
+ #define INCLUDE_V8_LOCAL_HANDLE_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include <type_traits>
11
+ #include <vector>
12
+
13
+ #include "v8-handle-base.h" // NOLINT(build/include_directory)
14
+ #include "v8-internal.h" // NOLINT(build/include_directory)
15
+
16
+ namespace v8 {
17
+
18
+ template <class T>
19
+ class LocalBase;
20
+ template <class T>
21
+ class Local;
22
+ template <class T>
23
+ class LocalVector;
24
+ template <class F>
25
+ class MaybeLocal;
26
+
27
+ template <class T>
28
+ class Eternal;
29
+ template <class T>
30
+ class Global;
31
+
32
+ template <class T>
33
+ class NonCopyablePersistentTraits;
34
+ template <class T>
35
+ class PersistentBase;
36
+ template <class T, class M = NonCopyablePersistentTraits<T>>
37
+ class Persistent;
38
+
39
+ class TracedReferenceBase;
40
+ template <class T>
41
+ class BasicTracedReference;
42
+ template <class F>
43
+ class TracedReference;
44
+
45
+ class ArrayBuffer;
46
+ class Boolean;
47
+ class Context;
48
+ class EscapableHandleScope;
49
+ template <class F>
50
+ class FunctionCallbackInfo;
51
+ class Isolate;
52
+ class Object;
53
+ template <class F1, class F2, class F3>
54
+ class PersistentValueMapBase;
55
+ class Primitive;
56
+ class Private;
57
+ template <class F>
58
+ class PropertyCallbackInfo;
59
+ template <class F>
60
+ class ReturnValue;
61
+ class String;
62
+ template <class F>
63
+ class Traced;
64
+ class TypecheckWitness;
65
+ class Utils;
66
+ class Uint32;
67
+ class Value;
68
+
69
+ namespace debug {
70
+ class ConsoleCallArguments;
71
+ }
72
+
73
+ namespace internal {
74
+ template <typename T>
75
+ class CustomArguments;
76
+ template <typename T>
77
+ class LocalUnchecked;
78
+ class SamplingHeapProfiler;
79
+ } // namespace internal
80
+
81
+ namespace api_internal {
82
+ // Called when ToLocalChecked is called on an empty Local.
83
+ V8_EXPORT void ToLocalEmpty();
84
+
85
+ #ifdef V8_ENABLE_CHECKS
86
+ template <typename T, typename V = Value>
87
+ void TypeCheckLocal(V* value) {
88
+ // If `T` does not provide a `Cast` method we cannot check anything.
89
+ if constexpr (requires { T::Cast(value); }) {
90
+ // TODO(419454582): Remove all these exceptions.
91
+ if (std::is_same_v<Array, T> && value->IsArgumentsObject()) return;
92
+ if (std::is_same_v<ArrayBuffer, T> && value->IsSharedArrayBuffer()) return;
93
+ if (std::is_same_v<Object, T> && value->IsNull()) return;
94
+ if (std::is_same_v<Object, T> && value->IsString()) return;
95
+ if (std::is_same_v<Object, T> && value->IsUndefined()) return;
96
+ if (std::is_same_v<Uint32, T> && value->IsInt32()) return;
97
+ if (std::is_same_v<Object, T> && value->IsNumber()) return;
98
+ // Execute the actual check (part of the cast).
99
+ T::Cast(value);
100
+ }
101
+ }
102
+ #endif
103
+ } // namespace api_internal
104
+
105
+ /**
106
+ * A stack-allocated class that governs a number of local handles.
107
+ * After a handle scope has been created, all local handles will be
108
+ * allocated within that handle scope until either the handle scope is
109
+ * deleted or another handle scope is created. If there is already a
110
+ * handle scope and a new one is created, all allocations will take
111
+ * place in the new handle scope until it is deleted. After that,
112
+ * new handles will again be allocated in the original handle scope.
113
+ *
114
+ * After the handle scope of a local handle has been deleted the
115
+ * garbage collector will no longer track the object stored in the
116
+ * handle and may deallocate it. The behavior of accessing a handle
117
+ * for which the handle scope has been deleted is undefined.
118
+ */
119
+ class V8_EXPORT V8_NODISCARD HandleScope {
120
+ public:
121
+ V8_INLINE explicit HandleScope(Isolate* isolate);
122
+
123
+ V8_INLINE ~HandleScope();
124
+
125
+ /**
126
+ * Counts the number of allocated handles.
127
+ */
128
+ static int NumberOfHandles(Isolate* isolate);
129
+
130
+ V8_INLINE Isolate* GetIsolate() const { return isolate_; }
131
+
132
+ HandleScope(const HandleScope&) = delete;
133
+ void operator=(const HandleScope&) = delete;
134
+
135
+ static internal::Address* CreateHandleForCurrentIsolate(
136
+ internal::Address value);
137
+
138
+ protected:
139
+ V8_INLINE HandleScope() = default;
140
+
141
+ V8_INLINE void Initialize(Isolate* isolate);
142
+
143
+ V8_INLINE static internal::Address* CreateHandle(Isolate* i_isolate,
144
+ internal::Address value);
145
+
146
+ private:
147
+ // Extend the HandleScope making room for more handles. Not inlined.
148
+ static internal::Address* Extend(Isolate* isolate);
149
+ // Delete any extensions in HandleScope destructor. Not called unless there
150
+ // are extensions. Not inlined.
151
+ void DeleteExtensions(Isolate* isolate);
152
+
153
+ #ifdef V8_ENABLE_CHECKS
154
+ // Non-inlined asserts on HandleScope constructor.
155
+ void DoInitializeAsserts(Isolate* isolate);
156
+ // Non-inlined assert for HandleScope destructor.
157
+ void AssertScopeLevelsMatch();
158
+ // Non-inlined asserts for HandleScope destructor. Also zaps the slots
159
+ // if this is enabled.
160
+ void DoCloseScopeAsserts(int before, internal::Address* limit,
161
+ internal::HandleScopeData* current);
162
+ #endif
163
+
164
+ // Declaring operator new and delete as deleted is not spec compliant.
165
+ // Therefore declare them private instead to disable dynamic alloc
166
+ void* operator new(size_t size);
167
+ void* operator new[](size_t size);
168
+ void operator delete(void*, size_t);
169
+ void operator delete[](void*, size_t);
170
+
171
+ Isolate* isolate_;
172
+ internal::Address* prev_next_;
173
+ internal::Address* prev_limit_;
174
+ #ifdef V8_ENABLE_CHECKS
175
+ int scope_level_ = 0;
176
+ #endif
177
+
178
+ // LocalBase<T>::New uses CreateHandle with an Isolate* parameter.
179
+ template <typename T>
180
+ friend class LocalBase;
181
+
182
+ // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
183
+ // a HeapObject in their shortcuts.
184
+ friend class Object;
185
+ friend class Context;
186
+ };
187
+
188
+ HandleScope::HandleScope(Isolate* v8_isolate) { Initialize(v8_isolate); }
189
+
190
+ void HandleScope::Initialize(Isolate* v8_isolate) {
191
+ using I = internal::Internals;
192
+ internal::HandleScopeData* current = I::GetHandleScopeData(v8_isolate);
193
+ isolate_ = v8_isolate;
194
+ prev_next_ = current->next;
195
+ prev_limit_ = current->limit;
196
+ current->level++;
197
+ #ifdef V8_ENABLE_CHECKS
198
+ DoInitializeAsserts(v8_isolate);
199
+ scope_level_ = current->level;
200
+ #endif
201
+ }
202
+
203
+ HandleScope::~HandleScope() {
204
+ if (V8_UNLIKELY(isolate_ == nullptr)) return;
205
+ #ifdef V8_ENABLE_CHECKS
206
+ AssertScopeLevelsMatch();
207
+ int handle_count_before = NumberOfHandles(isolate_);
208
+ #endif
209
+
210
+ using I = internal::Internals;
211
+ internal::HandleScopeData* current = I::GetHandleScopeData(isolate_);
212
+ std::swap(current->next, prev_next_);
213
+ current->level--;
214
+ internal::Address* limit = prev_next_;
215
+ if (V8_UNLIKELY(current->limit != prev_limit_)) {
216
+ current->limit = prev_limit_;
217
+ limit = prev_limit_;
218
+ DeleteExtensions(isolate_);
219
+ }
220
+ #ifdef V8_ENABLE_CHECKS
221
+ DoCloseScopeAsserts(handle_count_before, limit, current);
222
+ #else
223
+ (void)limit; // Avoid unused variable warning.
224
+ #endif
225
+ }
226
+
227
+ internal::Address* HandleScope::CreateHandle(Isolate* v8_isolate,
228
+ internal::Address value) {
229
+ using I = internal::Internals;
230
+ internal::HandleScopeData* data = I::GetHandleScopeData(v8_isolate);
231
+ internal::Address* result = data->next;
232
+ if (V8_UNLIKELY(result == data->limit)) {
233
+ result = Extend(v8_isolate);
234
+ }
235
+ // Update the current next field, set the value in the created handle,
236
+ // and return the result.
237
+ data->next = reinterpret_cast<internal::Address*>(
238
+ reinterpret_cast<internal::Address>(result) + sizeof(internal::Address));
239
+ *result = value;
240
+ return result;
241
+ }
242
+
243
+ /**
244
+ * A base class for local handles.
245
+ * Its implementation depends on whether direct handle support is enabled.
246
+ * When it is, a local handle contains a direct pointer to the referenced
247
+ * object, otherwise it contains an indirect pointer.
248
+ */
249
+ #ifdef V8_ENABLE_DIRECT_HANDLE
250
+
251
+ template <typename T>
252
+ class LocalBase : public api_internal::DirectHandleBase {
253
+ protected:
254
+ template <class F>
255
+ friend class Local;
256
+
257
+ V8_INLINE LocalBase() = default;
258
+
259
+ V8_INLINE explicit LocalBase(internal::Address ptr) : DirectHandleBase(ptr) {
260
+ #ifdef V8_ENABLE_CHECKS
261
+ if (!IsEmpty()) api_internal::TypeCheckLocal<T>(value<Value>());
262
+ #endif
263
+ }
264
+
265
+ template <typename S>
266
+ V8_INLINE LocalBase(const LocalBase<S>& other) : DirectHandleBase(other) {}
267
+
268
+ V8_INLINE static LocalBase<T> New(Isolate* isolate, internal::Address value) {
269
+ return LocalBase<T>(value);
270
+ }
271
+
272
+ V8_INLINE static LocalBase<T> New(Isolate* isolate, T* that) {
273
+ return LocalBase<T>::New(isolate,
274
+ internal::ValueHelper::ValueAsAddress(that));
275
+ }
276
+
277
+ V8_INLINE static LocalBase<T> FromSlot(internal::Address* slot) {
278
+ if (slot == nullptr) return LocalBase<T>();
279
+ return LocalBase<T>(*slot);
280
+ }
281
+
282
+ V8_INLINE static LocalBase<T> FromRepr(
283
+ internal::ValueHelper::InternalRepresentationType repr) {
284
+ return LocalBase<T>(repr);
285
+ }
286
+ };
287
+
288
+ #else // !V8_ENABLE_DIRECT_HANDLE
289
+
290
+ template <typename T>
291
+ class LocalBase : public api_internal::IndirectHandleBase {
292
+ protected:
293
+ template <class F>
294
+ friend class Local;
295
+
296
+ V8_INLINE LocalBase() = default;
297
+
298
+ V8_INLINE explicit LocalBase(internal::Address* location)
299
+ : IndirectHandleBase(location) {
300
+ #ifdef V8_ENABLE_CHECKS
301
+ if (!IsEmpty()) api_internal::TypeCheckLocal<T>(value<Value>());
302
+ #endif
303
+ }
304
+
305
+ template <typename S>
306
+ V8_INLINE LocalBase(const LocalBase<S>& other) : IndirectHandleBase(other) {}
307
+
308
+ V8_INLINE static LocalBase<T> New(Isolate* isolate, internal::Address value) {
309
+ return LocalBase(HandleScope::CreateHandle(isolate, value));
310
+ }
311
+
312
+ V8_INLINE static LocalBase<T> New(Isolate* isolate, T* that) {
313
+ if (internal::ValueHelper::IsEmpty(that)) return LocalBase<T>();
314
+ return LocalBase<T>::New(isolate,
315
+ internal::ValueHelper::ValueAsAddress(that));
316
+ }
317
+
318
+ V8_INLINE static LocalBase<T> FromSlot(internal::Address* slot) {
319
+ return LocalBase<T>(slot);
320
+ }
321
+
322
+ V8_INLINE static LocalBase<T> FromRepr(
323
+ internal::ValueHelper::InternalRepresentationType repr) {
324
+ return LocalBase<T>(repr);
325
+ }
326
+ };
327
+
328
+ #endif // V8_ENABLE_DIRECT_HANDLE
329
+
330
+ /**
331
+ * An object reference managed by the v8 garbage collector.
332
+ *
333
+ * All objects returned from v8 have to be tracked by the garbage collector so
334
+ * that it knows that the objects are still alive. Also, because the garbage
335
+ * collector may move objects, it is unsafe to point directly to an object.
336
+ * Instead, all objects are stored in handles which are known by the garbage
337
+ * collector and updated whenever an object moves. Handles should always be
338
+ * passed by value (except in cases like out-parameters) and they should never
339
+ * be allocated on the heap.
340
+ *
341
+ * There are two types of handles: local and persistent handles.
342
+ *
343
+ * Local handles are light-weight and transient and typically used in local
344
+ * operations. They are managed by HandleScopes. That means that a HandleScope
345
+ * must exist on the stack when they are created and that they are only valid
346
+ * inside of the HandleScope active during their creation. For passing a local
347
+ * handle to an outer HandleScope, an EscapableHandleScope and its Escape()
348
+ * method must be used.
349
+ *
350
+ * Persistent handles can be used when storing objects across several
351
+ * independent operations and have to be explicitly deallocated when they're no
352
+ * longer used.
353
+ *
354
+ * It is safe to extract the object stored in the handle by dereferencing the
355
+ * handle (for instance, to extract the Object* from a Local<Object>); the value
356
+ * will still be governed by a handle behind the scenes and the same rules apply
357
+ * to these values as to their handles.
358
+ */
359
+ template <class T>
360
+ class V8_TRIVIAL_ABI Local : public LocalBase<T>,
361
+ #ifdef V8_ENABLE_LOCAL_OFF_STACK_CHECK
362
+ public api_internal::StackAllocated<true>
363
+ #else
364
+ public api_internal::StackAllocated<false>
365
+ #endif
366
+ {
367
+ public:
368
+ /**
369
+ * Default constructor: Returns an empty handle.
370
+ */
371
+ V8_INLINE Local() = default;
372
+
373
+ /**
374
+ * Constructor for handling automatic up casting.
375
+ * Ex. Local<Object> can be passed when Local<Value> is expected but not
376
+ * the other way round.
377
+ */
378
+ template <class S>
379
+ requires std::is_base_of_v<T, S>
380
+ V8_INLINE Local(Local<S> that) : LocalBase<T>(that) {}
381
+
382
+ V8_INLINE T* operator->() const { return this->template value<T>(); }
383
+
384
+ V8_INLINE T* operator*() const { return this->operator->(); }
385
+
386
+ /**
387
+ * Checks whether two handles are equal or different.
388
+ * They are equal iff they are both empty or they are both non-empty and the
389
+ * objects to which they refer are physically equal.
390
+ *
391
+ * If both handles refer to JS objects, this is the same as strict
392
+ * non-equality. For primitives, such as numbers or strings, a `false` return
393
+ * value does not indicate that the values aren't equal in the JavaScript
394
+ * sense. Use `Value::StrictEquals()` to check primitives for equality.
395
+ */
396
+
397
+ template <class S>
398
+ V8_INLINE bool operator==(const Local<S>& that) const {
399
+ return internal::HandleHelper::EqualHandles(*this, that);
400
+ }
401
+
402
+ template <class S>
403
+ V8_INLINE bool operator==(const PersistentBase<S>& that) const {
404
+ return internal::HandleHelper::EqualHandles(*this, that);
405
+ }
406
+
407
+ template <class S>
408
+ V8_INLINE bool operator!=(const Local<S>& that) const {
409
+ return !operator==(that);
410
+ }
411
+
412
+ template <class S>
413
+ V8_INLINE bool operator!=(const Persistent<S>& that) const {
414
+ return !operator==(that);
415
+ }
416
+
417
+ /**
418
+ * Cast a handle to a subclass, e.g. Local<Value> to Local<Object>.
419
+ * This is only valid if the handle actually refers to a value of the
420
+ * target type or if the handle is empty.
421
+ */
422
+ template <class S>
423
+ V8_INLINE static Local<T> Cast(Local<S> that) {
424
+ #ifdef V8_ENABLE_CHECKS
425
+ // If we're going to perform the type check then we have to check
426
+ // that the handle isn't empty before doing the checked cast.
427
+ if (that.IsEmpty()) return Local<T>();
428
+ T::Cast(that.template value<S>());
429
+ #endif
430
+ return Local<T>(LocalBase<T>(that));
431
+ }
432
+
433
+ /**
434
+ * Calling this is equivalent to Local<S>::Cast().
435
+ * In particular, this is only valid if the handle actually refers to a value
436
+ * of the target type or if the handle is empty.
437
+ */
438
+ template <class S>
439
+ V8_INLINE Local<S> As() const {
440
+ return Local<S>::Cast(*this);
441
+ }
442
+
443
+ /**
444
+ * Create a local handle for the content of another handle.
445
+ * The referee is kept alive by the local handle even when
446
+ * the original handle is destroyed/disposed.
447
+ */
448
+ V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that) {
449
+ return New(isolate, that.template value<T, true>());
450
+ }
451
+
452
+ V8_INLINE static Local<T> New(Isolate* isolate,
453
+ const PersistentBase<T>& that) {
454
+ return New(isolate, that.template value<T, true>());
455
+ }
456
+
457
+ V8_INLINE static Local<T> New(Isolate* isolate,
458
+ const BasicTracedReference<T>& that) {
459
+ return New(isolate, that.template value<T, true>());
460
+ }
461
+
462
+ private:
463
+ friend class TracedReferenceBase;
464
+ friend class Utils;
465
+ template <class F>
466
+ friend class Eternal;
467
+ template <class F>
468
+ friend class Global;
469
+ template <class F>
470
+ friend class Local;
471
+ template <class F>
472
+ friend class MaybeLocal;
473
+ template <class F, class M>
474
+ friend class Persistent;
475
+ template <class F>
476
+ friend class FunctionCallbackInfo;
477
+ template <class F>
478
+ friend class PropertyCallbackInfo;
479
+ friend class String;
480
+ friend class Object;
481
+ friend class Context;
482
+ friend class Isolate;
483
+ friend class Private;
484
+ template <class F>
485
+ friend class internal::CustomArguments;
486
+ friend Local<Primitive> Undefined(Isolate* isolate);
487
+ friend Local<Primitive> Null(Isolate* isolate);
488
+ friend Local<Boolean> True(Isolate* isolate);
489
+ friend Local<Boolean> False(Isolate* isolate);
490
+ friend class HandleScope;
491
+ friend class EscapableHandleScope;
492
+ friend class InternalEscapableScope;
493
+ template <class F1, class F2, class F3>
494
+ friend class PersistentValueMapBase;
495
+ template <class F>
496
+ friend class ReturnValue;
497
+ template <class F>
498
+ friend class Traced;
499
+ friend class internal::SamplingHeapProfiler;
500
+ friend class internal::HandleHelper;
501
+ friend class debug::ConsoleCallArguments;
502
+ friend class internal::LocalUnchecked<T>;
503
+
504
+ explicit Local(no_checking_tag do_not_check)
505
+ : LocalBase<T>(), StackAllocated(do_not_check) {}
506
+ explicit Local(const Local<T>& other, no_checking_tag do_not_check)
507
+ : LocalBase<T>(other), StackAllocated(do_not_check) {}
508
+
509
+ V8_INLINE explicit Local(const LocalBase<T>& other) : LocalBase<T>(other) {}
510
+
511
+ V8_INLINE static Local<T> FromRepr(
512
+ internal::ValueHelper::InternalRepresentationType repr) {
513
+ return Local<T>(LocalBase<T>::FromRepr(repr));
514
+ }
515
+
516
+ V8_INLINE static Local<T> FromSlot(internal::Address* slot) {
517
+ return Local<T>(LocalBase<T>::FromSlot(slot));
518
+ }
519
+
520
+ #ifdef V8_ENABLE_DIRECT_HANDLE
521
+ friend class TypecheckWitness;
522
+
523
+ V8_INLINE static Local<T> FromAddress(internal::Address ptr) {
524
+ return Local<T>(LocalBase<T>(ptr));
525
+ }
526
+ #endif // V8_ENABLE_DIRECT_HANDLE
527
+
528
+ V8_INLINE static Local<T> New(Isolate* isolate, internal::Address value) {
529
+ return Local<T>(LocalBase<T>::New(isolate, value));
530
+ }
531
+
532
+ V8_INLINE static Local<T> New(Isolate* isolate, T* that) {
533
+ return Local<T>(LocalBase<T>::New(isolate, that));
534
+ }
535
+
536
+ // Unsafe cast, should be avoided.
537
+ template <class S>
538
+ V8_INLINE Local<S> UnsafeAs() const {
539
+ return Local<S>(LocalBase<S>(*this));
540
+ }
541
+ };
542
+
543
+ namespace internal {
544
+ // A local variant that is suitable for off-stack allocation.
545
+ // Used internally by LocalVector<T>. Not to be used directly!
546
+ template <typename T>
547
+ class V8_TRIVIAL_ABI LocalUnchecked : public Local<T> {
548
+ public:
549
+ LocalUnchecked() : Local<T>(Local<T>::do_not_check) {}
550
+
551
+ #if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
552
+ // In this case, the check is also enforced in the copy constructor and we
553
+ // need to suppress it.
554
+ LocalUnchecked(
555
+ const LocalUnchecked& other) noexcept // NOLINT(runtime/explicit)
556
+ : Local<T>(other, Local<T>::do_not_check) {}
557
+ LocalUnchecked& operator=(const LocalUnchecked&) noexcept = default;
558
+ #endif
559
+
560
+ // Implicit conversion from Local.
561
+ LocalUnchecked(const Local<T>& other) noexcept // NOLINT(runtime/explicit)
562
+ : Local<T>(other, Local<T>::do_not_check) {}
563
+ };
564
+
565
+ #ifdef V8_ENABLE_DIRECT_HANDLE
566
+ // Off-stack allocated direct locals must be registered as strong roots.
567
+ // For off-stack indirect locals, this is not necessary.
568
+
569
+ template <typename T>
570
+ class StrongRootAllocator<LocalUnchecked<T>> : public StrongRootAllocatorBase {
571
+ public:
572
+ using value_type = LocalUnchecked<T>;
573
+ static_assert(std::is_standard_layout_v<value_type>);
574
+ static_assert(sizeof(value_type) == sizeof(Address));
575
+
576
+ template <typename HeapOrIsolateT>
577
+ explicit StrongRootAllocator(HeapOrIsolateT* heap_or_isolate)
578
+ : StrongRootAllocatorBase(heap_or_isolate) {}
579
+ template <typename U>
580
+ StrongRootAllocator(const StrongRootAllocator<U>& other) noexcept
581
+ : StrongRootAllocatorBase(other) {}
582
+
583
+ value_type* allocate(size_t n) {
584
+ return reinterpret_cast<value_type*>(allocate_impl(n));
585
+ }
586
+ void deallocate(value_type* p, size_t n) noexcept {
587
+ return deallocate_impl(reinterpret_cast<Address*>(p), n);
588
+ }
589
+ };
590
+ #endif // V8_ENABLE_DIRECT_HANDLE
591
+ } // namespace internal
592
+
593
+ template <typename T>
594
+ class LocalVector {
595
+ private:
596
+ using element_type = internal::LocalUnchecked<T>;
597
+
598
+ #ifdef V8_ENABLE_DIRECT_HANDLE
599
+ using allocator_type = internal::StrongRootAllocator<element_type>;
600
+
601
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
602
+ return allocator_type(isolate);
603
+ }
604
+ #else
605
+ using allocator_type = std::allocator<element_type>;
606
+
607
+ static allocator_type make_allocator(Isolate* isolate) noexcept {
608
+ return allocator_type();
609
+ }
610
+ #endif // V8_ENABLE_DIRECT_HANDLE
611
+
612
+ using vector_type = std::vector<element_type, allocator_type>;
613
+
614
+ public:
615
+ using value_type = Local<T>;
616
+ using reference = value_type&;
617
+ using const_reference = const value_type&;
618
+ using size_type = size_t;
619
+ using difference_type = ptrdiff_t;
620
+ using iterator =
621
+ internal::WrappedIterator<typename vector_type::iterator, Local<T>>;
622
+ using const_iterator =
623
+ internal::WrappedIterator<typename vector_type::const_iterator,
624
+ const Local<T>>;
625
+
626
+ explicit LocalVector(Isolate* isolate) : backing_(make_allocator(isolate)) {}
627
+ LocalVector(Isolate* isolate, size_t n)
628
+ : backing_(n, make_allocator(isolate)) {}
629
+ explicit LocalVector(Isolate* isolate, std::initializer_list<Local<T>> init)
630
+ : backing_(make_allocator(isolate)) {
631
+ if (init.size() == 0) return;
632
+ backing_.reserve(init.size());
633
+ backing_.insert(backing_.end(), init.begin(), init.end());
634
+ }
635
+
636
+ iterator begin() noexcept { return iterator(backing_.begin()); }
637
+ const_iterator begin() const noexcept {
638
+ return const_iterator(backing_.begin());
639
+ }
640
+ iterator end() noexcept { return iterator(backing_.end()); }
641
+ const_iterator end() const noexcept { return const_iterator(backing_.end()); }
642
+
643
+ size_t size() const noexcept { return backing_.size(); }
644
+ bool empty() const noexcept { return backing_.empty(); }
645
+ void reserve(size_t n) { backing_.reserve(n); }
646
+ void shrink_to_fit() { backing_.shrink_to_fit(); }
647
+
648
+ Local<T>& operator[](size_t n) { return backing_[n]; }
649
+ const Local<T>& operator[](size_t n) const { return backing_[n]; }
650
+
651
+ Local<T>& at(size_t n) { return backing_.at(n); }
652
+ const Local<T>& at(size_t n) const { return backing_.at(n); }
653
+
654
+ Local<T>& front() { return backing_.front(); }
655
+ const Local<T>& front() const { return backing_.front(); }
656
+ Local<T>& back() { return backing_.back(); }
657
+ const Local<T>& back() const { return backing_.back(); }
658
+
659
+ Local<T>* data() noexcept { return backing_.data(); }
660
+ const Local<T>* data() const noexcept { return backing_.data(); }
661
+
662
+ iterator insert(const_iterator pos, const Local<T>& value) {
663
+ return iterator(backing_.insert(pos.base(), value));
664
+ }
665
+
666
+ template <typename InputIt>
667
+ iterator insert(const_iterator pos, InputIt first, InputIt last) {
668
+ return iterator(backing_.insert(pos.base(), first, last));
669
+ }
670
+
671
+ iterator insert(const_iterator pos, std::initializer_list<Local<T>> init) {
672
+ return iterator(backing_.insert(pos.base(), init.begin(), init.end()));
673
+ }
674
+
675
+ LocalVector<T>& operator=(std::initializer_list<Local<T>> init) {
676
+ backing_.clear();
677
+ backing_.reserve(init.size());
678
+ backing_.insert(backing_.end(), init.begin(), init.end());
679
+ return *this;
680
+ }
681
+
682
+ void push_back(const Local<T>& x) { backing_.push_back(x); }
683
+ void pop_back() { backing_.pop_back(); }
684
+
685
+ template <typename... Args>
686
+ void emplace_back(Args&&... args) {
687
+ backing_.push_back(value_type{std::forward<Args>(args)...});
688
+ }
689
+
690
+ void clear() noexcept { backing_.clear(); }
691
+ void resize(size_t n) { backing_.resize(n); }
692
+ void swap(LocalVector<T>& other) { backing_.swap(other.backing_); }
693
+
694
+ friend bool operator==(const LocalVector<T>& x, const LocalVector<T>& y) {
695
+ return x.backing_ == y.backing_;
696
+ }
697
+ friend bool operator!=(const LocalVector<T>& x, const LocalVector<T>& y) {
698
+ return x.backing_ != y.backing_;
699
+ }
700
+ friend bool operator<(const LocalVector<T>& x, const LocalVector<T>& y) {
701
+ return x.backing_ < y.backing_;
702
+ }
703
+ friend bool operator>(const LocalVector<T>& x, const LocalVector<T>& y) {
704
+ return x.backing_ > y.backing_;
705
+ }
706
+ friend bool operator<=(const LocalVector<T>& x, const LocalVector<T>& y) {
707
+ return x.backing_ <= y.backing_;
708
+ }
709
+ friend bool operator>=(const LocalVector<T>& x, const LocalVector<T>& y) {
710
+ return x.backing_ >= y.backing_;
711
+ }
712
+
713
+ private:
714
+ vector_type backing_;
715
+ };
716
+
717
+ #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
718
+ // Handle is an alias for Local for historical reasons.
719
+ template <class T>
720
+ using Handle = Local<T>;
721
+ #endif
722
+
723
+ /**
724
+ * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether
725
+ * the Local<> is empty before it can be used.
726
+ *
727
+ * If an API method returns a MaybeLocal<>, the API method can potentially fail
728
+ * either because an exception is thrown, or because an exception is pending,
729
+ * e.g. because a previous API call threw an exception that hasn't been caught
730
+ * yet, or because a TerminateExecution exception was thrown. In that case, an
731
+ * empty MaybeLocal is returned.
732
+ */
733
+ template <class T>
734
+ class MaybeLocal {
735
+ public:
736
+ /**
737
+ * Default constructor: Returns an empty handle.
738
+ */
739
+ V8_INLINE MaybeLocal() = default;
740
+ /**
741
+ * Implicitly construct MaybeLocal from Local.
742
+ */
743
+ template <class S>
744
+ requires std::is_base_of_v<T, S>
745
+ V8_INLINE MaybeLocal(Local<S> that) : local_(that) {}
746
+ /**
747
+ * Implicitly up-cast MaybeLocal<S> to MaybeLocal<T> if T is a base of S.
748
+ */
749
+ template <class S>
750
+ requires std::is_base_of_v<T, S>
751
+ V8_INLINE MaybeLocal(MaybeLocal<S> that) : local_(that.local_) {}
752
+
753
+ V8_INLINE bool IsEmpty() const { return local_.IsEmpty(); }
754
+
755
+ /**
756
+ * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty,
757
+ * |false| is returned and |out| is assigned with nullptr.
758
+ */
759
+ template <class S>
760
+ V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
761
+ *out = local_;
762
+ return !IsEmpty();
763
+ }
764
+
765
+ /**
766
+ * Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty,
767
+ * V8 will crash the process.
768
+ */
769
+ V8_INLINE Local<T> ToLocalChecked() {
770
+ if (V8_UNLIKELY(IsEmpty())) api_internal::ToLocalEmpty();
771
+ return local_;
772
+ }
773
+
774
+ /**
775
+ * Converts this MaybeLocal<> to a Local<>, using a default value if this
776
+ * MaybeLocal<> is empty.
777
+ */
778
+ template <class S>
779
+ V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
780
+ return IsEmpty() ? default_value : Local<S>(local_);
781
+ }
782
+
783
+ /**
784
+ * Cast a handle to a subclass, e.g. MaybeLocal<Value> to MaybeLocal<Object>.
785
+ * This is only valid if the handle actually refers to a value of the target
786
+ * type or if the handle is empty.
787
+ */
788
+ template <class S>
789
+ V8_INLINE static MaybeLocal<T> Cast(MaybeLocal<S> that) {
790
+ return MaybeLocal<T>{Local<T>::Cast(that.local_)};
791
+ }
792
+
793
+ /**
794
+ * Calling this is equivalent to MaybeLocal<S>::Cast().
795
+ * In particular, this is only valid if the handle actually refers to a value
796
+ * of the target type or if the handle is empty.
797
+ */
798
+ template <class S>
799
+ V8_INLINE MaybeLocal<S> As() const {
800
+ return MaybeLocal<S>::Cast(*this);
801
+ }
802
+
803
+ private:
804
+ Local<T> local_;
805
+
806
+ template <typename S>
807
+ friend class MaybeLocal;
808
+ };
809
+
810
+ /**
811
+ * A HandleScope which first allocates a handle in the current scope
812
+ * which will be later filled with the escape value.
813
+ */
814
+ class V8_EXPORT V8_NODISCARD EscapableHandleScopeBase : public HandleScope {
815
+ public:
816
+ explicit EscapableHandleScopeBase(Isolate* isolate);
817
+ V8_INLINE ~EscapableHandleScopeBase() = default;
818
+
819
+ EscapableHandleScopeBase(const EscapableHandleScopeBase&) = delete;
820
+ void operator=(const EscapableHandleScopeBase&) = delete;
821
+ void* operator new(size_t size) = delete;
822
+ void* operator new[](size_t size) = delete;
823
+ void operator delete(void*, size_t) = delete;
824
+ void operator delete[](void*, size_t) = delete;
825
+
826
+ protected:
827
+ /**
828
+ * Pushes the value into the previous scope and returns a handle to it.
829
+ * Cannot be called twice.
830
+ */
831
+ internal::Address* EscapeSlot(internal::Address* escape_value);
832
+
833
+ private:
834
+ internal::Address* escape_slot_;
835
+ };
836
+
837
+ class V8_EXPORT V8_NODISCARD EscapableHandleScope
838
+ : public EscapableHandleScopeBase {
839
+ public:
840
+ explicit EscapableHandleScope(Isolate* isolate)
841
+ : EscapableHandleScopeBase(isolate) {}
842
+ V8_INLINE ~EscapableHandleScope() = default;
843
+ template <class T>
844
+ V8_INLINE Local<T> Escape(Local<T> value) {
845
+ #ifdef V8_ENABLE_DIRECT_HANDLE
846
+ return value;
847
+ #else
848
+ if (value.IsEmpty()) return value;
849
+ return Local<T>::FromSlot(EscapeSlot(value.slot()));
850
+ #endif
851
+ }
852
+
853
+ template <class T>
854
+ V8_INLINE MaybeLocal<T> EscapeMaybe(MaybeLocal<T> value) {
855
+ return Escape(value.FromMaybe(Local<T>()));
856
+ }
857
+ };
858
+
859
+ /**
860
+ * A SealHandleScope acts like a handle scope in which no handle allocations
861
+ * are allowed. It can be useful for debugging handle leaks.
862
+ * Handles can be allocated within inner normal HandleScopes.
863
+ */
864
+ class V8_EXPORT V8_NODISCARD SealHandleScope {
865
+ public:
866
+ explicit SealHandleScope(Isolate* isolate);
867
+ ~SealHandleScope();
868
+
869
+ SealHandleScope(const SealHandleScope&) = delete;
870
+ void operator=(const SealHandleScope&) = delete;
871
+ void* operator new(size_t size) = delete;
872
+ void* operator new[](size_t size) = delete;
873
+ void operator delete(void*, size_t) = delete;
874
+ void operator delete[](void*, size_t) = delete;
875
+
876
+ private:
877
+ internal::Isolate* const i_isolate_;
878
+ internal::Address* prev_limit_;
879
+ int prev_sealed_level_;
880
+ };
881
+
882
+ } // namespace v8
883
+
884
+ #endif // INCLUDE_V8_LOCAL_HANDLE_H_