libv8-node 16.10.0.0-x86_64-darwin → 18.8.0.0-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libv8-node/paths.rb +1 -1
- data/lib/libv8/node/version.rb +3 -3
- data/vendor/v8/include/cppgc/allocation.h +100 -22
- data/vendor/v8/include/cppgc/cross-thread-persistent.h +114 -33
- data/vendor/v8/include/cppgc/default-platform.h +2 -10
- data/vendor/v8/include/cppgc/explicit-management.h +22 -4
- data/vendor/v8/include/cppgc/garbage-collected.h +15 -26
- data/vendor/v8/include/cppgc/heap-consistency.h +30 -0
- data/vendor/v8/include/cppgc/heap-state.h +12 -0
- data/vendor/v8/include/cppgc/heap.h +7 -2
- data/vendor/v8/include/cppgc/internal/api-constants.h +8 -0
- data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +25 -14
- data/vendor/v8/include/cppgc/internal/finalizer-trait.h +4 -1
- data/vendor/v8/include/cppgc/internal/gc-info.h +90 -10
- data/vendor/v8/include/cppgc/internal/logging.h +3 -3
- data/vendor/v8/include/cppgc/internal/name-trait.h +11 -0
- data/vendor/v8/include/cppgc/internal/persistent-node.h +73 -29
- data/vendor/v8/include/cppgc/internal/pointer-policies.h +26 -15
- data/vendor/v8/include/cppgc/internal/write-barrier.h +62 -23
- data/vendor/v8/include/cppgc/liveness-broker.h +4 -1
- data/vendor/v8/include/cppgc/member.h +7 -2
- data/vendor/v8/include/cppgc/persistent.h +38 -33
- data/vendor/v8/include/cppgc/platform.h +4 -1
- data/vendor/v8/include/cppgc/prefinalizer.h +35 -12
- data/vendor/v8/include/cppgc/testing.h +9 -2
- data/vendor/v8/include/cppgc/type-traits.h +6 -13
- data/vendor/v8/include/cppgc/visitor.h +9 -7
- data/vendor/v8/include/libplatform/libplatform.h +0 -11
- data/vendor/v8/include/libplatform/v8-tracing.h +0 -1
- data/vendor/v8/include/v8-array-buffer.h +445 -0
- data/vendor/v8/include/v8-callbacks.h +397 -0
- data/vendor/v8/include/v8-container.h +129 -0
- data/vendor/v8/include/v8-context.h +407 -0
- data/vendor/v8/include/v8-cppgc.h +21 -128
- data/vendor/v8/include/v8-data.h +80 -0
- data/vendor/v8/include/v8-date.h +43 -0
- data/vendor/v8/include/v8-debug.h +168 -0
- data/vendor/v8/include/v8-embedder-heap.h +218 -0
- data/vendor/v8/include/v8-embedder-state-scope.h +51 -0
- data/vendor/v8/include/v8-exception.h +217 -0
- data/vendor/v8/include/v8-extension.h +62 -0
- data/vendor/v8/include/v8-external.h +37 -0
- data/vendor/v8/include/v8-fast-api-calls.h +172 -24
- data/vendor/v8/include/v8-forward.h +81 -0
- data/vendor/v8/include/v8-function-callback.h +475 -0
- data/vendor/v8/include/v8-function.h +125 -0
- data/vendor/v8/include/v8-initialization.h +315 -0
- data/vendor/v8/include/v8-inspector.h +56 -28
- data/vendor/v8/include/v8-internal.h +217 -55
- data/vendor/v8/include/v8-isolate.h +1709 -0
- data/vendor/v8/include/v8-json.h +47 -0
- data/vendor/v8/include/v8-local-handle.h +455 -0
- data/vendor/v8/include/v8-locker.h +149 -0
- data/vendor/v8/include/v8-maybe.h +137 -0
- data/vendor/v8/include/v8-memory-span.h +43 -0
- data/vendor/v8/include/v8-message.h +216 -0
- data/vendor/v8/include/v8-metrics.h +69 -16
- data/vendor/v8/include/v8-microtask-queue.h +152 -0
- data/vendor/v8/include/v8-microtask.h +28 -0
- data/vendor/v8/include/v8-object.h +775 -0
- data/vendor/v8/include/v8-persistent-handle.h +590 -0
- data/vendor/v8/include/v8-platform.h +400 -17
- data/vendor/v8/include/v8-primitive-object.h +118 -0
- data/vendor/v8/include/v8-primitive.h +866 -0
- data/vendor/v8/include/v8-profiler.h +88 -13
- data/vendor/v8/include/v8-promise.h +174 -0
- data/vendor/v8/include/v8-proxy.h +50 -0
- data/vendor/v8/include/v8-regexp.h +105 -0
- data/vendor/v8/include/v8-script.h +747 -0
- data/vendor/v8/include/v8-snapshot.h +196 -0
- data/vendor/v8/include/v8-statistics.h +217 -0
- data/vendor/v8/include/v8-template.h +1079 -0
- data/vendor/v8/include/v8-traced-handle.h +420 -0
- data/vendor/v8/include/v8-typed-array.h +282 -0
- data/vendor/v8/include/v8-unwinder-state.h +4 -3
- data/vendor/v8/include/v8-unwinder.h +132 -0
- data/vendor/v8/include/v8-util.h +7 -1
- data/vendor/v8/include/v8-value-serializer-version.h +1 -1
- data/vendor/v8/include/v8-value-serializer.h +279 -0
- data/vendor/v8/include/v8-value.h +526 -0
- data/vendor/v8/include/v8-version.h +4 -4
- data/vendor/v8/include/v8-wasm.h +257 -0
- data/vendor/v8/include/v8-weak-callback-info.h +87 -0
- data/vendor/v8/include/v8.h +41 -12601
- data/vendor/v8/include/v8config.h +102 -12
- data/vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a +0 -0
- metadata +47 -5
- data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +0 -30
@@ -0,0 +1,445 @@
|
|
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-object.h" // NOLINT(build/include_directory)
|
14
|
+
#include "v8config.h" // NOLINT(build/include_directory)
|
15
|
+
|
16
|
+
namespace v8 {
|
17
|
+
|
18
|
+
class SharedArrayBuffer;
|
19
|
+
|
20
|
+
#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
|
21
|
+
// The number of required internal fields can be defined by embedder.
|
22
|
+
#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
|
23
|
+
#endif
|
24
|
+
|
25
|
+
enum class ArrayBufferCreationMode { kInternalized, kExternalized };
|
26
|
+
|
27
|
+
/**
|
28
|
+
* A wrapper around the backing store (i.e. the raw memory) of an array buffer.
|
29
|
+
* See a document linked in http://crbug.com/v8/9908 for more information.
|
30
|
+
*
|
31
|
+
* The allocation and destruction of backing stores is generally managed by
|
32
|
+
* V8. Clients should always use standard C++ memory ownership types (i.e.
|
33
|
+
* std::unique_ptr and std::shared_ptr) to manage lifetimes of backing stores
|
34
|
+
* properly, since V8 internal objects may alias backing stores.
|
35
|
+
*
|
36
|
+
* This object does not keep the underlying |ArrayBuffer::Allocator| alive by
|
37
|
+
* default. Use Isolate::CreateParams::array_buffer_allocator_shared when
|
38
|
+
* creating the Isolate to make it hold a reference to the allocator itself.
|
39
|
+
*/
|
40
|
+
class V8_EXPORT BackingStore : public v8::internal::BackingStoreBase {
|
41
|
+
public:
|
42
|
+
~BackingStore();
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Return a pointer to the beginning of the memory block for this backing
|
46
|
+
* store. The pointer is only valid as long as this backing store object
|
47
|
+
* lives.
|
48
|
+
*/
|
49
|
+
void* Data() const;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* The length (in bytes) of this backing store.
|
53
|
+
*/
|
54
|
+
size_t ByteLength() const;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Indicates whether the backing store was created for an ArrayBuffer or
|
58
|
+
* a SharedArrayBuffer.
|
59
|
+
*/
|
60
|
+
bool IsShared() const;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Prevent implicit instantiation of operator delete with size_t argument.
|
64
|
+
* The size_t argument would be incorrect because ptr points to the
|
65
|
+
* internal BackingStore object.
|
66
|
+
*/
|
67
|
+
void operator delete(void* ptr) { ::operator delete(ptr); }
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Wrapper around ArrayBuffer::Allocator::Reallocate that preserves IsShared.
|
71
|
+
* Assumes that the backing_store was allocated by the ArrayBuffer allocator
|
72
|
+
* of the given isolate.
|
73
|
+
*/
|
74
|
+
static std::unique_ptr<BackingStore> Reallocate(
|
75
|
+
v8::Isolate* isolate, std::unique_ptr<BackingStore> backing_store,
|
76
|
+
size_t byte_length);
|
77
|
+
|
78
|
+
/**
|
79
|
+
* This callback is used only if the memory block for a BackingStore cannot be
|
80
|
+
* allocated with an ArrayBuffer::Allocator. In such cases the destructor of
|
81
|
+
* the BackingStore invokes the callback to free the memory block.
|
82
|
+
*/
|
83
|
+
using DeleterCallback = void (*)(void* data, size_t length,
|
84
|
+
void* deleter_data);
|
85
|
+
|
86
|
+
/**
|
87
|
+
* If the memory block of a BackingStore is static or is managed manually,
|
88
|
+
* then this empty deleter along with nullptr deleter_data can be passed to
|
89
|
+
* ArrayBuffer::NewBackingStore to indicate that.
|
90
|
+
*
|
91
|
+
* The manually managed case should be used with caution and only when it
|
92
|
+
* is guaranteed that the memory block freeing happens after detaching its
|
93
|
+
* ArrayBuffer.
|
94
|
+
*/
|
95
|
+
static void EmptyDeleter(void* data, size_t length, void* deleter_data);
|
96
|
+
|
97
|
+
private:
|
98
|
+
/**
|
99
|
+
* See [Shared]ArrayBuffer::GetBackingStore and
|
100
|
+
* [Shared]ArrayBuffer::NewBackingStore.
|
101
|
+
*/
|
102
|
+
BackingStore();
|
103
|
+
};
|
104
|
+
|
105
|
+
#if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
|
106
|
+
// Use v8::BackingStore::DeleterCallback instead.
|
107
|
+
using BackingStoreDeleterCallback = void (*)(void* data, size_t length,
|
108
|
+
void* deleter_data);
|
109
|
+
|
110
|
+
#endif
|
111
|
+
|
112
|
+
/**
|
113
|
+
* An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
|
114
|
+
*/
|
115
|
+
class V8_EXPORT ArrayBuffer : public Object {
|
116
|
+
public:
|
117
|
+
/**
|
118
|
+
* A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory.
|
119
|
+
* The allocator is a global V8 setting. It has to be set via
|
120
|
+
* Isolate::CreateParams.
|
121
|
+
*
|
122
|
+
* Memory allocated through this allocator by V8 is accounted for as external
|
123
|
+
* memory by V8. Note that V8 keeps track of the memory for all internalized
|
124
|
+
* |ArrayBuffer|s. Responsibility for tracking external memory (using
|
125
|
+
* Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the
|
126
|
+
* embedder upon externalization and taken over upon internalization (creating
|
127
|
+
* an internalized buffer from an existing buffer).
|
128
|
+
*
|
129
|
+
* Note that it is unsafe to call back into V8 from any of the allocator
|
130
|
+
* functions.
|
131
|
+
*/
|
132
|
+
class V8_EXPORT Allocator {
|
133
|
+
public:
|
134
|
+
virtual ~Allocator() = default;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Allocate |length| bytes. Return nullptr if allocation is not successful.
|
138
|
+
* Memory should be initialized to zeroes.
|
139
|
+
*/
|
140
|
+
virtual void* Allocate(size_t length) = 0;
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Allocate |length| bytes. Return nullptr if allocation is not successful.
|
144
|
+
* Memory does not have to be initialized.
|
145
|
+
*/
|
146
|
+
virtual void* AllocateUninitialized(size_t length) = 0;
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Free the memory block of size |length|, pointed to by |data|.
|
150
|
+
* That memory is guaranteed to be previously allocated by |Allocate|.
|
151
|
+
*/
|
152
|
+
virtual void Free(void* data, size_t length) = 0;
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Reallocate the memory block of size |old_length| to a memory block of
|
156
|
+
* size |new_length| by expanding, contracting, or copying the existing
|
157
|
+
* memory block. If |new_length| > |old_length|, then the new part of
|
158
|
+
* the memory must be initialized to zeros. Return nullptr if reallocation
|
159
|
+
* is not successful.
|
160
|
+
*
|
161
|
+
* The caller guarantees that the memory block was previously allocated
|
162
|
+
* using Allocate or AllocateUninitialized.
|
163
|
+
*
|
164
|
+
* The default implementation allocates a new block and copies data.
|
165
|
+
*/
|
166
|
+
virtual void* Reallocate(void* data, size_t old_length, size_t new_length);
|
167
|
+
|
168
|
+
/**
|
169
|
+
* ArrayBuffer allocation mode. kNormal is a malloc/free style allocation,
|
170
|
+
* while kReservation is for larger allocations with the ability to set
|
171
|
+
* access permissions.
|
172
|
+
*/
|
173
|
+
enum class AllocationMode { kNormal, kReservation };
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Convenience allocator.
|
177
|
+
*
|
178
|
+
* When the sandbox is enabled, this allocator will allocate its backing
|
179
|
+
* memory inside the sandbox. Otherwise, it will rely on malloc/free.
|
180
|
+
*
|
181
|
+
* Caller takes ownership, i.e. the returned object needs to be freed using
|
182
|
+
* |delete allocator| once it is no longer in use.
|
183
|
+
*/
|
184
|
+
static Allocator* NewDefaultAllocator();
|
185
|
+
};
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Data length in bytes.
|
189
|
+
*/
|
190
|
+
size_t ByteLength() const;
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Create a new ArrayBuffer. Allocate |byte_length| bytes.
|
194
|
+
* Allocated memory will be owned by a created ArrayBuffer and
|
195
|
+
* will be deallocated when it is garbage-collected,
|
196
|
+
* unless the object is externalized.
|
197
|
+
*/
|
198
|
+
static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Create a new ArrayBuffer with an existing backing store.
|
202
|
+
* The created array keeps a reference to the backing store until the array
|
203
|
+
* is garbage collected. Note that the IsExternal bit does not affect this
|
204
|
+
* reference from the array to the backing store.
|
205
|
+
*
|
206
|
+
* In future IsExternal bit will be removed. Until then the bit is set as
|
207
|
+
* follows. If the backing store does not own the underlying buffer, then
|
208
|
+
* the array is created in externalized state. Otherwise, the array is created
|
209
|
+
* in internalized state. In the latter case the array can be transitioned
|
210
|
+
* to the externalized state using Externalize(backing_store).
|
211
|
+
*/
|
212
|
+
static Local<ArrayBuffer> New(Isolate* isolate,
|
213
|
+
std::shared_ptr<BackingStore> backing_store);
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Returns a new standalone BackingStore that is allocated using the array
|
217
|
+
* buffer allocator of the isolate. The result can be later passed to
|
218
|
+
* ArrayBuffer::New.
|
219
|
+
*
|
220
|
+
* If the allocator returns nullptr, then the function may cause GCs in the
|
221
|
+
* given isolate and re-try the allocation. If GCs do not help, then the
|
222
|
+
* function will crash with an out-of-memory error.
|
223
|
+
*/
|
224
|
+
static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
|
225
|
+
size_t byte_length);
|
226
|
+
/**
|
227
|
+
* Returns a new standalone BackingStore that takes over the ownership of
|
228
|
+
* the given buffer. The destructor of the BackingStore invokes the given
|
229
|
+
* deleter callback.
|
230
|
+
*
|
231
|
+
* The result can be later passed to ArrayBuffer::New. The raw pointer
|
232
|
+
* to the buffer must not be passed again to any V8 API function.
|
233
|
+
*/
|
234
|
+
static std::unique_ptr<BackingStore> NewBackingStore(
|
235
|
+
void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
|
236
|
+
void* deleter_data);
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Returns true if this ArrayBuffer may be detached.
|
240
|
+
*/
|
241
|
+
bool IsDetachable() const;
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Detaches this ArrayBuffer and all its views (typed arrays).
|
245
|
+
* Detaching sets the byte length of the buffer and all typed arrays to zero,
|
246
|
+
* preventing JavaScript from ever accessing underlying backing store.
|
247
|
+
* ArrayBuffer should have been externalized and must be detachable.
|
248
|
+
*/
|
249
|
+
void Detach();
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Get a shared pointer to the backing store of this array buffer. This
|
253
|
+
* pointer coordinates the lifetime management of the internal storage
|
254
|
+
* with any live ArrayBuffers on the heap, even across isolates. The embedder
|
255
|
+
* should not attempt to manage lifetime of the storage through other means.
|
256
|
+
*/
|
257
|
+
std::shared_ptr<BackingStore> GetBackingStore();
|
258
|
+
|
259
|
+
/**
|
260
|
+
* More efficient shortcut for GetBackingStore()->Data(). The returned pointer
|
261
|
+
* is valid as long as the ArrayBuffer is alive.
|
262
|
+
*/
|
263
|
+
void* Data() const;
|
264
|
+
|
265
|
+
V8_INLINE static ArrayBuffer* Cast(Value* value) {
|
266
|
+
#ifdef V8_ENABLE_CHECKS
|
267
|
+
CheckCast(value);
|
268
|
+
#endif
|
269
|
+
return static_cast<ArrayBuffer*>(value);
|
270
|
+
}
|
271
|
+
|
272
|
+
static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
|
273
|
+
static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
|
274
|
+
|
275
|
+
private:
|
276
|
+
ArrayBuffer();
|
277
|
+
static void CheckCast(Value* obj);
|
278
|
+
};
|
279
|
+
|
280
|
+
#ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
|
281
|
+
// The number of required internal fields can be defined by embedder.
|
282
|
+
#define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
|
283
|
+
#endif
|
284
|
+
|
285
|
+
/**
|
286
|
+
* A base class for an instance of one of "views" over ArrayBuffer,
|
287
|
+
* including TypedArrays and DataView (ES6 draft 15.13).
|
288
|
+
*/
|
289
|
+
class V8_EXPORT ArrayBufferView : public Object {
|
290
|
+
public:
|
291
|
+
/**
|
292
|
+
* Returns underlying ArrayBuffer.
|
293
|
+
*/
|
294
|
+
Local<ArrayBuffer> Buffer();
|
295
|
+
/**
|
296
|
+
* Byte offset in |Buffer|.
|
297
|
+
*/
|
298
|
+
size_t ByteOffset();
|
299
|
+
/**
|
300
|
+
* Size of a view in bytes.
|
301
|
+
*/
|
302
|
+
size_t ByteLength();
|
303
|
+
|
304
|
+
/**
|
305
|
+
* Copy the contents of the ArrayBufferView's buffer to an embedder defined
|
306
|
+
* memory without additional overhead that calling ArrayBufferView::Buffer
|
307
|
+
* might incur.
|
308
|
+
*
|
309
|
+
* Will write at most min(|byte_length|, ByteLength) bytes starting at
|
310
|
+
* ByteOffset of the underlying buffer to the memory starting at |dest|.
|
311
|
+
* Returns the number of bytes actually written.
|
312
|
+
*/
|
313
|
+
size_t CopyContents(void* dest, size_t byte_length);
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Returns true if ArrayBufferView's backing ArrayBuffer has already been
|
317
|
+
* allocated.
|
318
|
+
*/
|
319
|
+
bool HasBuffer() const;
|
320
|
+
|
321
|
+
V8_INLINE static ArrayBufferView* Cast(Value* value) {
|
322
|
+
#ifdef V8_ENABLE_CHECKS
|
323
|
+
CheckCast(value);
|
324
|
+
#endif
|
325
|
+
return static_cast<ArrayBufferView*>(value);
|
326
|
+
}
|
327
|
+
|
328
|
+
static const int kInternalFieldCount =
|
329
|
+
V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
|
330
|
+
static const int kEmbedderFieldCount =
|
331
|
+
V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT;
|
332
|
+
|
333
|
+
private:
|
334
|
+
ArrayBufferView();
|
335
|
+
static void CheckCast(Value* obj);
|
336
|
+
};
|
337
|
+
|
338
|
+
/**
|
339
|
+
* An instance of DataView constructor (ES6 draft 15.13.7).
|
340
|
+
*/
|
341
|
+
class V8_EXPORT DataView : public ArrayBufferView {
|
342
|
+
public:
|
343
|
+
static Local<DataView> New(Local<ArrayBuffer> array_buffer,
|
344
|
+
size_t byte_offset, size_t length);
|
345
|
+
static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
|
346
|
+
size_t byte_offset, size_t length);
|
347
|
+
V8_INLINE static DataView* Cast(Value* value) {
|
348
|
+
#ifdef V8_ENABLE_CHECKS
|
349
|
+
CheckCast(value);
|
350
|
+
#endif
|
351
|
+
return static_cast<DataView*>(value);
|
352
|
+
}
|
353
|
+
|
354
|
+
private:
|
355
|
+
DataView();
|
356
|
+
static void CheckCast(Value* obj);
|
357
|
+
};
|
358
|
+
|
359
|
+
/**
|
360
|
+
* An instance of the built-in SharedArrayBuffer constructor.
|
361
|
+
*/
|
362
|
+
class V8_EXPORT SharedArrayBuffer : public Object {
|
363
|
+
public:
|
364
|
+
/**
|
365
|
+
* Data length in bytes.
|
366
|
+
*/
|
367
|
+
size_t ByteLength() const;
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
|
371
|
+
* Allocated memory will be owned by a created SharedArrayBuffer and
|
372
|
+
* will be deallocated when it is garbage-collected,
|
373
|
+
* unless the object is externalized.
|
374
|
+
*/
|
375
|
+
static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
|
376
|
+
|
377
|
+
/**
|
378
|
+
* Create a new SharedArrayBuffer with an existing backing store.
|
379
|
+
* The created array keeps a reference to the backing store until the array
|
380
|
+
* is garbage collected. Note that the IsExternal bit does not affect this
|
381
|
+
* reference from the array to the backing store.
|
382
|
+
*
|
383
|
+
* In future IsExternal bit will be removed. Until then the bit is set as
|
384
|
+
* follows. If the backing store does not own the underlying buffer, then
|
385
|
+
* the array is created in externalized state. Otherwise, the array is created
|
386
|
+
* in internalized state. In the latter case the array can be transitioned
|
387
|
+
* to the externalized state using Externalize(backing_store).
|
388
|
+
*/
|
389
|
+
static Local<SharedArrayBuffer> New(
|
390
|
+
Isolate* isolate, std::shared_ptr<BackingStore> backing_store);
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Returns a new standalone BackingStore that is allocated using the array
|
394
|
+
* buffer allocator of the isolate. The result can be later passed to
|
395
|
+
* SharedArrayBuffer::New.
|
396
|
+
*
|
397
|
+
* If the allocator returns nullptr, then the function may cause GCs in the
|
398
|
+
* given isolate and re-try the allocation. If GCs do not help, then the
|
399
|
+
* function will crash with an out-of-memory error.
|
400
|
+
*/
|
401
|
+
static std::unique_ptr<BackingStore> NewBackingStore(Isolate* isolate,
|
402
|
+
size_t byte_length);
|
403
|
+
/**
|
404
|
+
* Returns a new standalone BackingStore that takes over the ownership of
|
405
|
+
* the given buffer. The destructor of the BackingStore invokes the given
|
406
|
+
* deleter callback.
|
407
|
+
*
|
408
|
+
* The result can be later passed to SharedArrayBuffer::New. The raw pointer
|
409
|
+
* to the buffer must not be passed again to any V8 functions.
|
410
|
+
*/
|
411
|
+
static std::unique_ptr<BackingStore> NewBackingStore(
|
412
|
+
void* data, size_t byte_length, v8::BackingStore::DeleterCallback deleter,
|
413
|
+
void* deleter_data);
|
414
|
+
|
415
|
+
/**
|
416
|
+
* Get a shared pointer to the backing store of this array buffer. This
|
417
|
+
* pointer coordinates the lifetime management of the internal storage
|
418
|
+
* with any live ArrayBuffers on the heap, even across isolates. The embedder
|
419
|
+
* should not attempt to manage lifetime of the storage through other means.
|
420
|
+
*/
|
421
|
+
std::shared_ptr<BackingStore> GetBackingStore();
|
422
|
+
|
423
|
+
/**
|
424
|
+
* More efficient shortcut for GetBackingStore()->Data(). The returned pointer
|
425
|
+
* is valid as long as the ArrayBuffer is alive.
|
426
|
+
*/
|
427
|
+
void* Data() const;
|
428
|
+
|
429
|
+
V8_INLINE static SharedArrayBuffer* Cast(Value* value) {
|
430
|
+
#ifdef V8_ENABLE_CHECKS
|
431
|
+
CheckCast(value);
|
432
|
+
#endif
|
433
|
+
return static_cast<SharedArrayBuffer*>(value);
|
434
|
+
}
|
435
|
+
|
436
|
+
static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
|
437
|
+
|
438
|
+
private:
|
439
|
+
SharedArrayBuffer();
|
440
|
+
static void CheckCast(Value* obj);
|
441
|
+
};
|
442
|
+
|
443
|
+
} // namespace v8
|
444
|
+
|
445
|
+
#endif // INCLUDE_V8_ARRAY_BUFFER_H_
|