@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,646 @@
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_ARRAY_BUFFER_H_
6
+ #define INCLUDE_V8_ARRAY_BUFFER_H_
7
+
8
+ #include <stddef.h>
9
+
10
+ #include <memory>
11
+
12
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
13
+ #include "v8-memory-span.h" // NOLINT(build/include_directory)
14
+ #include "v8-object.h" // NOLINT(build/include_directory)
15
+ #include "v8-platform.h" // NOLINT(build/include_directory)
16
+ #include "v8config.h" // NOLINT(build/include_directory)
17
+
18
+ namespace v8 {
19
+
20
+ class SharedArrayBuffer;
21
+
22
+ #if defined(V8_COMPRESS_POINTERS) && \
23
+ !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
24
+ class IsolateGroup;
25
+ #endif
26
+
27
+ #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
28
+ // Defined using gn arg `v8_array_buffer_internal_field_count`.
29
+ #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
30
+ #endif
31
+
32
+ enum class ArrayBufferCreationMode { kInternalized, kExternalized };
33
+ enum class BackingStoreInitializationMode { kZeroInitialized, kUninitialized };
34
+ enum class BackingStoreOnFailureMode { kReturnNull, kOutOfMemory };
35
+
36
+ /**
37
+ * A wrapper around the backing store (i.e. the raw memory) of an array buffer.
38
+ * See a document linked in http://crbug.com/v8/9908 for more information.
39
+ *
40
+ * The allocation and destruction of backing stores is generally managed by
41
+ * V8. Clients should always use standard C++ memory ownership types (i.e.
42
+ * std::unique_ptr and std::shared_ptr) to manage lifetimes of backing stores
43
+ * properly, since V8 internal objects may alias backing stores.
44
+ *
45
+ * This object does not keep the underlying |ArrayBuffer::Allocator| alive by
46
+ * default. Use Isolate::CreateParams::array_buffer_allocator_shared when
47
+ * creating the Isolate to make it hold a reference to the allocator itself.
48
+ */
49
+ class V8_EXPORT BackingStore : public v8::internal::BackingStoreBase {
50
+ public:
51
+ ~BackingStore();
52
+
53
+ /**
54
+ * Return a pointer to the beginning of the memory block for this backing
55
+ * store. The pointer is only valid as long as this backing store object
56
+ * lives.
57
+ */
58
+ void* Data() const;
59
+
60
+ /**
61
+ * The length (in bytes) of this backing store.
62
+ */
63
+ size_t ByteLength() const;
64
+
65
+ /**
66
+ * The maximum length (in bytes) that this backing store may grow to.
67
+ *
68
+ * If this backing store was created for a resizable ArrayBuffer or a growable
69
+ * SharedArrayBuffer, it is >= ByteLength(). Otherwise it is ==
70
+ * ByteLength().
71
+ */
72
+ size_t MaxByteLength() const;
73
+
74
+ /**
75
+ * Indicates whether the backing store was created for an ArrayBuffer or
76
+ * a SharedArrayBuffer.
77
+ */
78
+ bool IsShared() const;
79
+
80
+ /**
81
+ * Indicates whether the backing store is immutable.
82
+ */
83
+ bool IsImmutable() const;
84
+
85
+ /**
86
+ * Indicates whether the backing store was created for a resizable ArrayBuffer
87
+ * or a growable SharedArrayBuffer, and thus may be resized by user JavaScript
88
+ * code.
89
+ */
90
+ bool IsResizableByUserJavaScript() const;
91
+
92
+ /**
93
+ * Prevent implicit instantiation of operator delete with size_t argument.
94
+ * The size_t argument would be incorrect because ptr points to the
95
+ * internal BackingStore object.
96
+ */
97
+ void operator delete(void* ptr) { ::operator delete(ptr); }
98
+
99
+ /**
100
+ * This callback is used only if the memory block for a BackingStore cannot be
101
+ * allocated with an ArrayBuffer::Allocator. In such cases the destructor of
102
+ * the BackingStore invokes the callback to free the memory block.
103
+ */
104
+ using DeleterCallback = void (*)(void* data, size_t length,
105
+ void* deleter_data);
106
+
107
+ /**
108
+ * If the memory block of a BackingStore is static or is managed manually,
109
+ * then this empty deleter along with nullptr deleter_data can be passed to
110
+ * ArrayBuffer::NewBackingStore to indicate that.
111
+ *
112
+ * The manually managed case should be used with caution and only when it
113
+ * is guaranteed that the memory block freeing happens after detaching its
114
+ * ArrayBuffer.
115
+ */
116
+ static void EmptyDeleter(void* data, size_t length, void* deleter_data);
117
+
118
+ private:
119
+ /**
120
+ * See [Shared]ArrayBuffer::GetBackingStore and
121
+ * [Shared]ArrayBuffer::NewBackingStore.
122
+ */
123
+ BackingStore();
124
+ };
125
+
126
+ #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
127
+ // Use v8::BackingStore::DeleterCallback instead.
128
+ using BackingStoreDeleterCallback = void (*)(void* data, size_t length,
129
+ void* deleter_data);
130
+
131
+ #endif
132
+
133
+ /**
134
+ * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
135
+ */
136
+ class V8_EXPORT ArrayBuffer : public Object {
137
+ public:
138
+ /**
139
+ * A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory.
140
+ * The allocator is a global V8 setting. It has to be set via
141
+ * Isolate::CreateParams.
142
+ *
143
+ * Memory allocated through this allocator by V8 is accounted for as external
144
+ * memory by V8. Note that V8 keeps track of the memory for all internalized
145
+ * |ArrayBuffer|s. Responsibility for tracking external memory (using
146
+ * Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the
147
+ * embedder upon externalization and taken over upon internalization (creating
148
+ * an internalized buffer from an existing buffer).
149
+ *
150
+ * Note that it is unsafe to call back into V8 from any of the allocator
151
+ * functions.
152
+ */
153
+ class V8_EXPORT Allocator {
154
+ public:
155
+ virtual ~Allocator() = default;
156
+
157
+ /**
158
+ * Allocate |length| bytes. Return nullptr if allocation is not successful.
159
+ * Memory should be initialized to zeroes.
160
+ */
161
+ virtual void* Allocate(size_t length) = 0;
162
+
163
+ /**
164
+ * Allocate |length| bytes. Return nullptr if allocation is not successful.
165
+ * Memory does not have to be initialized.
166
+ */
167
+ virtual void* AllocateUninitialized(size_t length) = 0;
168
+
169
+ /**
170
+ * Free the memory block of size |length|, pointed to by |data|.
171
+ * That memory is guaranteed to be previously allocated by |Allocate|.
172
+ */
173
+ virtual void Free(void* data, size_t length) = 0;
174
+
175
+ /**
176
+ * Returns a size_t that determines the largest ArrayBuffer that can be
177
+ * allocated. Override if your Allocator is more restrictive than the
178
+ * default. Will only be called once, and the value returned will be
179
+ * cached.
180
+ * Should not return a value that is larger than kMaxByteLength.
181
+ */
182
+ virtual size_t MaxAllocationSize() const { return kMaxByteLength; }
183
+
184
+ /**
185
+ * ArrayBuffer allocation mode. kNormal is a malloc/free style allocation,
186
+ * while kReservation is for larger allocations with the ability to set
187
+ * access permissions.
188
+ */
189
+ enum class AllocationMode { kNormal, kReservation };
190
+
191
+ /**
192
+ * Returns page allocator used by this Allocator instance.
193
+ *
194
+ * When the sandbox used by Allocator it is expected that this returns
195
+ * sandbox's page allocator.
196
+ * Otherwise, it should return system page allocator.
197
+ */
198
+ virtual PageAllocator* GetPageAllocator() { return nullptr; }
199
+
200
+ #if defined(V8_COMPRESS_POINTERS) && \
201
+ !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
202
+ /**
203
+ * Convenience allocator.
204
+ *
205
+ * When the sandbox is enabled, this allocator will allocate its backing
206
+ * memory inside the sandbox that belongs to the passed isolate group.
207
+ * Otherwise, it will rely on malloc/free.
208
+ *
209
+ * Caller takes ownership, i.e. the returned object needs to be freed using
210
+ * |delete allocator| once it is no longer in use.
211
+ */
212
+ static Allocator* NewDefaultAllocator(const IsolateGroup& group);
213
+ #endif // defined(V8_COMPRESS_POINTERS) &&
214
+ // !defined(V8_COMPRESS_POINTERS_IN_SHARED_CAGE)
215
+
216
+ /**
217
+ * Convenience allocator.
218
+ *
219
+ * When the sandbox is enabled, this allocator will allocate its backing
220
+ * memory inside the default global sandbox. Otherwise, it will rely on
221
+ * malloc/free.
222
+ *
223
+ * Caller takes ownership, i.e. the returned object needs to be freed using
224
+ * |delete allocator| once it is no longer in use.
225
+ */
226
+ static Allocator* NewDefaultAllocator();
227
+ };
228
+
229
+ /**
230
+ * Data length in bytes.
231
+ */
232
+ size_t ByteLength() const;
233
+
234
+ /**
235
+ * Maximum length in bytes.
236
+ */
237
+ size_t MaxByteLength() const;
238
+
239
+ /**
240
+ * Attempt to create a new ArrayBuffer. Allocate |byte_length| bytes.
241
+ * Allocated memory will be owned by a created ArrayBuffer and
242
+ * will be deallocated when it is garbage-collected,
243
+ * unless the object is externalized. If allocation fails, the Maybe
244
+ * returned will be empty.
245
+ */
246
+ static MaybeLocal<ArrayBuffer> MaybeNew(
247
+ Isolate* isolate, size_t byte_length,
248
+ BackingStoreInitializationMode initialization_mode =
249
+ BackingStoreInitializationMode::kZeroInitialized);
250
+
251
+ /**
252
+ * Create a new ArrayBuffer. Allocate |byte_length| bytes, which are either
253
+ * zero-initialized or uninitialized. Allocated memory will be owned by a
254
+ * created ArrayBuffer and will be deallocated when it is garbage-collected,
255
+ * unless the object is externalized.
256
+ */
257
+ static Local<ArrayBuffer> New(
258
+ Isolate* isolate, size_t byte_length,
259
+ BackingStoreInitializationMode initialization_mode =
260
+ BackingStoreInitializationMode::kZeroInitialized);
261
+
262
+ /**
263
+ * Create a new ArrayBuffer with an existing backing store.
264
+ * The created array keeps a reference to the backing store until the array
265
+ * is garbage collected. Note that the IsExternal bit does not affect this
266
+ * reference from the array to the backing store.
267
+ *
268
+ * In future IsExternal bit will be removed. Until then the bit is set as
269
+ * follows. If the backing store does not own the underlying buffer, then
270
+ * the array is created in externalized state. Otherwise, the array is created
271
+ * in internalized state. In the latter case the array can be transitioned
272
+ * to the externalized state using Externalize(backing_store).
273
+ */
274
+ static Local<ArrayBuffer> New(Isolate* isolate,
275
+ std::shared_ptr<BackingStore> backing_store);
276
+
277
+ /**
278
+ * Returns a new standalone BackingStore that is allocated using the array
279
+ * buffer allocator of the isolate. The allocation can either be zero
280
+ * initialized, or uninitialized. The result can be later passed to
281
+ * ArrayBuffer::New.
282
+ *
283
+ * If the allocator returns nullptr, then the function may cause GCs in the
284
+ * given isolate and re-try the allocation.
285
+ *
286
+ * If GCs do not help and on_failure is kOutOfMemory, then the
287
+ * function will crash with an out-of-memory error.
288
+ *
289
+ * Otherwise if GCs do not help (or the allocation is too large for GCs to
290
+ * help) and on_failure is kReturnNull, then a null result is returned.
291
+ */
292
+ static std::unique_ptr<BackingStore> NewBackingStore(
293
+ Isolate* isolate, size_t byte_length,
294
+ BackingStoreInitializationMode initialization_mode =
295
+ BackingStoreInitializationMode::kZeroInitialized,
296
+ BackingStoreOnFailureMode on_failure =
297
+ BackingStoreOnFailureMode::kOutOfMemory);
298
+
299
+ /**
300
+ * Returns a new standalone BackingStore that takes over the ownership of
301
+ * the given buffer. The destructor of the BackingStore invokes the given
302
+ * deleter callback.
303
+ *
304
+ * The result can be later passed to ArrayBuffer::New. The raw pointer
305
+ * to the buffer must not be passed again to any V8 API function.
306
+ */
307
+ static std::unique_ptr<BackingStore> NewBackingStore(
308
+ void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
309
+ void* deleter_data);
310
+
311
+ /**
312
+ * Returns a new resizable standalone BackingStore that is allocated using the
313
+ * array buffer allocator of the isolate. The result can be later passed to
314
+ * ArrayBuffer::New.
315
+ *
316
+ * |byte_length| must be <= |max_byte_length|.
317
+ *
318
+ * This function is usable without an isolate. Unlike |NewBackingStore| calls
319
+ * with an isolate, GCs cannot be triggered, and there are no
320
+ * retries. Allocation failure will cause the function to crash with an
321
+ * out-of-memory error.
322
+ */
323
+ static std::unique_ptr<BackingStore> NewResizableBackingStore(
324
+ size_t byte_length, size_t max_byte_length);
325
+
326
+ /**
327
+ * Returns true if this ArrayBuffer may be detached.
328
+ */
329
+ bool IsDetachable() const;
330
+
331
+ /**
332
+ * Returns true if this ArrayBuffer has been detached.
333
+ */
334
+ bool WasDetached() const;
335
+
336
+ /**
337
+ * Returns true if this ArrayBuffer is immutable.
338
+ */
339
+ bool IsImmutable() const;
340
+
341
+ /**
342
+ * Copy up to |bytes_to_copy| bytes from this ArrayBuffer starting at
343
+ * position |source_start| to the target ArrayBuffer starting at position
344
+ * |target_start|. Nothing is copied if the source ArrayBuffer is detached,
345
+ * or if the target ArrayBuffer is detached or immutable.
346
+ * Returns the number of bytes actually copied.
347
+ */
348
+ size_t CopyArrayBufferBytes(size_t source_start, size_t bytes_to_copy,
349
+ Local<ArrayBuffer> target,
350
+ size_t target_start) const;
351
+
352
+ /**
353
+ * Detaches this ArrayBuffer and all its views (typed arrays).
354
+ * Detaching sets the byte length of the buffer and all typed arrays to zero,
355
+ * preventing JavaScript from ever accessing underlying backing store.
356
+ * ArrayBuffer should have been externalized and must be detachable.
357
+ */
358
+ V8_DEPRECATED(
359
+ "Use the version which takes a key parameter (passing a null handle is "
360
+ "ok).")
361
+ void Detach();
362
+
363
+ /**
364
+ * Detaches this ArrayBuffer and all its views (typed arrays).
365
+ * Detaching sets the byte length of the buffer and all typed arrays to zero,
366
+ * preventing JavaScript from ever accessing underlying backing store.
367
+ * ArrayBuffer should have been externalized and must be detachable. Returns
368
+ * Nothing if the key didn't pass the [[ArrayBufferDetachKey]] check,
369
+ * Just(true) otherwise.
370
+ */
371
+ V8_WARN_UNUSED_RESULT Maybe<bool> Detach(v8::Local<v8::Value> key);
372
+
373
+ /**
374
+ * Sets the ArrayBufferDetachKey.
375
+ */
376
+ void SetDetachKey(v8::Local<v8::Value> key);
377
+
378
+ /**
379
+ * Get a shared pointer to the backing store of this array buffer. This
380
+ * pointer coordinates the lifetime management of the internal storage
381
+ * with any live ArrayBuffers on the heap, even across isolates. The embedder
382
+ * should not attempt to manage lifetime of the storage through other means.
383
+ *
384
+ * The returned shared pointer will not be empty, even if the ArrayBuffer has
385
+ * been detached. Use |WasDetached| to tell if it has been detached instead.
386
+ */
387
+ std::shared_ptr<BackingStore> GetBackingStore();
388
+
389
+ /**
390
+ * More efficient shortcut for
391
+ * GetBackingStore()->IsResizableByUserJavaScript().
392
+ */
393
+ bool IsResizableByUserJavaScript() const;
394
+
395
+ /**
396
+ * More efficient shortcut for GetBackingStore()->Data(). The returned pointer
397
+ * is valid as long as the ArrayBuffer is alive.
398
+ */
399
+ void* Data() const;
400
+
401
+ V8_INLINE static ArrayBuffer* Cast(Value* value) {
402
+ #ifdef V8_ENABLE_CHECKS
403
+ CheckCast(value);
404
+ #endif
405
+ return static_cast<ArrayBuffer*>(value);
406
+ }
407
+
408
+ static constexpr int kInternalFieldCount =
409
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
410
+ static constexpr int kEmbedderFieldCount = kInternalFieldCount;
411
+
412
+ #if V8_ENABLE_SANDBOX
413
+ static constexpr size_t kMaxByteLength =
414
+ internal::kMaxSafeBufferSizeForSandbox;
415
+ #elif V8_HOST_ARCH_32_BIT
416
+ static constexpr size_t kMaxByteLength = std::numeric_limits<int>::max();
417
+ #else
418
+ // The maximum safe integer (2^53 - 1).
419
+ static constexpr size_t kMaxByteLength =
420
+ static_cast<size_t>((uint64_t{1} << 53) - 1);
421
+ #endif
422
+
423
+ private:
424
+ ArrayBuffer();
425
+ static void CheckCast(Value* obj);
426
+ friend class TypedArray;
427
+ };
428
+
429
+ #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
430
+ // Defined using gn arg `v8_array_buffer_view_internal_field_count`.
431
+ #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
432
+ #endif
433
+
434
+ /**
435
+ * A base class for an instance of one of "views" over ArrayBuffer,
436
+ * including TypedArrays and DataView (ES6 draft 15.13).
437
+ */
438
+ class V8_EXPORT ArrayBufferView : public Object {
439
+ public:
440
+ /**
441
+ * Returns underlying ArrayBuffer.
442
+ */
443
+ Local<ArrayBuffer> Buffer();
444
+ /**
445
+ * Byte offset in |Buffer|.
446
+ */
447
+ size_t ByteOffset();
448
+ /**
449
+ * Size of a view in bytes.
450
+ */
451
+ size_t ByteLength();
452
+
453
+ /**
454
+ * Copy the contents of the ArrayBufferView's buffer to an embedder defined
455
+ * memory without additional overhead that calling ArrayBufferView::Buffer
456
+ * might incur.
457
+ *
458
+ * Will write at most min(|byte_length|, ByteLength) bytes starting at
459
+ * ByteOffset of the underlying buffer to the memory starting at |dest|.
460
+ * Returns the number of bytes actually written.
461
+ */
462
+ size_t CopyContents(void* dest, size_t byte_length);
463
+
464
+ /**
465
+ * Returns the contents of the ArrayBufferView's buffer as a MemorySpan. If
466
+ * the contents are on the V8 heap, they get copied into `storage`. Otherwise
467
+ * a view into the off-heap backing store is returned. The provided storage
468
+ * should be at least as large as the maximum on-heap size of a TypedArray,
469
+ * was defined in gn with `typed_array_max_size_in_heap`. The default value is
470
+ * 64 bytes.
471
+ */
472
+ v8::MemorySpan<uint8_t> GetContents(v8::MemorySpan<uint8_t> storage);
473
+
474
+ /**
475
+ * Returns true if ArrayBufferView's backing ArrayBuffer has already been
476
+ * allocated.
477
+ */
478
+ bool HasBuffer() const;
479
+
480
+ V8_INLINE static ArrayBufferView* Cast(Value* value) {
481
+ #ifdef V8_ENABLE_CHECKS
482
+ CheckCast(value);
483
+ #endif
484
+ return static_cast<ArrayBufferView*>(value);
485
+ }
486
+
487
+ static constexpr int kInternalFieldCount =
488
+ V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
489
+ static const int kEmbedderFieldCount = kInternalFieldCount;
490
+
491
+ private:
492
+ ArrayBufferView();
493
+ static void CheckCast(Value* obj);
494
+ };
495
+
496
+ /**
497
+ * An instance of DataView constructor (ES6 draft 15.13.7).
498
+ */
499
+ class V8_EXPORT DataView : public ArrayBufferView {
500
+ public:
501
+ static Local<DataView> New(Local<ArrayBuffer> array_buffer,
502
+ size_t byte_offset, size_t length);
503
+ static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
504
+ size_t byte_offset, size_t length);
505
+ V8_INLINE static DataView* Cast(Value* value) {
506
+ #ifdef V8_ENABLE_CHECKS
507
+ CheckCast(value);
508
+ #endif
509
+ return static_cast<DataView*>(value);
510
+ }
511
+
512
+ private:
513
+ DataView();
514
+ static void CheckCast(Value* obj);
515
+ };
516
+
517
+ /**
518
+ * An instance of the built-in SharedArrayBuffer constructor.
519
+ */
520
+ class V8_EXPORT SharedArrayBuffer : public Object {
521
+ public:
522
+ /**
523
+ * Data length in bytes.
524
+ */
525
+ size_t ByteLength() const;
526
+
527
+ /**
528
+ * Maximum length in bytes.
529
+ */
530
+ size_t MaxByteLength() const;
531
+
532
+ /**
533
+ * Create a new SharedArrayBuffer. Allocate |byte_length| bytes, which are
534
+ * either zero-initialized or uninitialized. Allocated memory will be owned by
535
+ * a created SharedArrayBuffer and will be deallocated when it is
536
+ * garbage-collected, unless the object is externalized.
537
+ */
538
+ static Local<SharedArrayBuffer> New(
539
+ Isolate* isolate, size_t byte_length,
540
+ BackingStoreInitializationMode initialization_mode =
541
+ BackingStoreInitializationMode::kZeroInitialized);
542
+
543
+ /**
544
+ * Create a new SharedArrayBuffer. Allocate |byte_length| bytes, which are
545
+ * either zero-initialized or uninitialized. Allocated memory will be owned by
546
+ * a created SharedArrayBuffer and will be deallocated when it is
547
+ * garbage-collected, unless the object is externalized. If allocation
548
+ * fails, the Maybe returned will be empty.
549
+ */
550
+ static MaybeLocal<SharedArrayBuffer> MaybeNew(
551
+ Isolate* isolate, size_t byte_length,
552
+ BackingStoreInitializationMode initialization_mode =
553
+ BackingStoreInitializationMode::kZeroInitialized);
554
+
555
+ /**
556
+ * Create a new SharedArrayBuffer with an existing backing store.
557
+ * The created array keeps a reference to the backing store until the array
558
+ * is garbage collected. Note that the IsExternal bit does not affect this
559
+ * reference from the array to the backing store.
560
+ *
561
+ * In future IsExternal bit will be removed. Until then the bit is set as
562
+ * follows. If the backing store does not own the underlying buffer, then
563
+ * the array is created in externalized state. Otherwise, the array is created
564
+ * in internalized state. In the latter case the array can be transitioned
565
+ * to the externalized state using Externalize(backing_store).
566
+ */
567
+ static Local<SharedArrayBuffer> New(
568
+ Isolate* isolate, std::shared_ptr<BackingStore> backing_store);
569
+
570
+ /**
571
+ * Returns a new standalone BackingStore that is allocated using the array
572
+ * buffer allocator of the isolate. The allocation can either be zero
573
+ * initialized, or uninitialized. The result can be later passed to
574
+ * SharedArrayBuffer::New.
575
+ *
576
+ * If the allocator returns nullptr, then the function may cause GCs in the
577
+ * given isolate and re-try the allocation.
578
+ *
579
+ * If on_failure is kOutOfMemory and GCs do not help, then the function will
580
+ * crash with an out-of-memory error.
581
+ *
582
+ * Otherwise, if on_failure is kReturnNull and GCs do not help (or the
583
+ * byte_length is so large that the allocation cannot succeed), then a null
584
+ * result is returned.
585
+ */
586
+ static std::unique_ptr<BackingStore> NewBackingStore(
587
+ Isolate* isolate, size_t byte_length,
588
+ BackingStoreInitializationMode initialization_mode =
589
+ BackingStoreInitializationMode::kZeroInitialized,
590
+ BackingStoreOnFailureMode on_failure =
591
+ BackingStoreOnFailureMode::kOutOfMemory);
592
+
593
+ /**
594
+ * Returns a new standalone BackingStore that takes over the ownership of
595
+ * the given buffer. The destructor of the BackingStore invokes the given
596
+ * deleter callback.
597
+ *
598
+ * The result can be later passed to SharedArrayBuffer::New. The raw pointer
599
+ * to the buffer must not be passed again to any V8 functions.
600
+ */
601
+ static std::unique_ptr<BackingStore> NewBackingStore(
602
+ void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
603
+ void* deleter_data);
604
+
605
+ /**
606
+ * Get a shared pointer to the backing store of this array buffer. This
607
+ * pointer coordinates the lifetime management of the internal storage
608
+ * with any live ArrayBuffers on the heap, even across isolates. The embedder
609
+ * should not attempt to manage lifetime of the storage through other means.
610
+ */
611
+ std::shared_ptr<BackingStore> GetBackingStore();
612
+
613
+ /**
614
+ * More efficient shortcut for GetBackingStore()->Data(). The returned pointer
615
+ * is valid as long as the ArrayBuffer is alive.
616
+ */
617
+ void* Data() const;
618
+
619
+ /**
620
+ * Copy up to |bytes_to_copy| bytes from this SharedArrayBuffer starting at
621
+ * position |source_start| to the target SharedArrayBuffer starting at
622
+ * position |target_start|.
623
+ * Returns the number of bytes actually copied.
624
+ */
625
+ size_t CopyArrayBufferBytes(size_t source_start, size_t bytes_to_copy,
626
+ Local<SharedArrayBuffer> target,
627
+ size_t target_start) const;
628
+
629
+ V8_INLINE static SharedArrayBuffer* Cast(Value* value) {
630
+ #ifdef V8_ENABLE_CHECKS
631
+ CheckCast(value);
632
+ #endif
633
+ return static_cast<SharedArrayBuffer*>(value);
634
+ }
635
+
636
+ static constexpr int kInternalFieldCount =
637
+ V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
638
+
639
+ private:
640
+ SharedArrayBuffer();
641
+ static void CheckCast(Value* obj);
642
+ };
643
+
644
+ } // namespace v8
645
+
646
+ #endif // INCLUDE_V8_ARRAY_BUFFER_H_