v8  8.4.371 (node 14.19.3)
V8 is Google's open source JavaScript engine
ArrayBuffer Class Reference

#include <v8.h>

Inheritance diagram for ArrayBuffer:
Collaboration diagram for ArrayBuffer:

Data Structures

class  Allocator
 
class  Contents
 

Public Member Functions

size_t ByteLength () const
 
 V8_DEPRECATE_SOON ("Use the version that takes a BackingStore. " "See http://crbug.com/v8/9908.") static Local< ArrayBuffer > New(Isolate *isolate
 
 V8_DEPRECATE_SOON ("With v8::BackingStore externalized ArrayBuffers are " "the same as ordinary ArrayBuffers. See http://crbug.com/v8/9908.") bool IsExternal() const
 
bool IsDetachable () const
 
void Detach ()
 
 V8_DEPRECATE_SOON ("Use GetBackingStore or Detach. See http://crbug.com/v8/9908.") Contents Externalize()
 
void Externalize (const std::shared_ptr< BackingStore > &backing_store)
 
Contents GetContents ()
 
std::shared_ptr< BackingStoreGetBackingStore ()
 
- Public Member Functions inherited from Object
V8_WARN_UNUSED_RESULT Maybe< bool > Set (Local< Context > context, Local< Value > key, Local< Value > value)
 
V8_WARN_UNUSED_RESULT Maybe< bool > Set (Local< Context > context, uint32_t index, Local< Value > value)
 
V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty (Local< Context > context, Local< Name > key, Local< Value > value)
 
V8_WARN_UNUSED_RESULT Maybe< bool > CreateDataProperty (Local< Context > context, uint32_t index, Local< Value > value)
 
V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty (Local< Context > context, Local< Name > key, Local< Value > value, PropertyAttribute attributes=None)
 
V8_WARN_UNUSED_RESULT Maybe< bool > DefineProperty (Local< Context > context, Local< Name > key, PropertyDescriptor &descriptor)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueGet (Local< Context > context, Local< Value > key)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueGet (Local< Context > context, uint32_t index)
 
V8_WARN_UNUSED_RESULT Maybe< PropertyAttributeGetPropertyAttributes (Local< Context > context, Local< Value > key)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueGetOwnPropertyDescriptor (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT Maybe< bool > Has (Local< Context > context, Local< Value > key)
 
V8_WARN_UNUSED_RESULT Maybe< bool > Delete (Local< Context > context, Local< Value > key)
 
V8_WARN_UNUSED_RESULT Maybe< bool > Has (Local< Context > context, uint32_t index)
 
V8_WARN_UNUSED_RESULT Maybe< bool > Delete (Local< Context > context, uint32_t index)
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetAccessor (Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, MaybeLocal< Value > data=MaybeLocal< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
 
void SetAccessorProperty (Local< Name > name, Local< Function > getter, Local< Function > setter=Local< Function >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT)
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetNativeDataProperty (Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetLazyDataProperty (Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
 
Maybe< bool > HasPrivate (Local< Context > context, Local< Private > key)
 
Maybe< bool > SetPrivate (Local< Context > context, Local< Private > key, Local< Value > value)
 
Maybe< bool > DeletePrivate (Local< Context > context, Local< Private > key)
 
MaybeLocal< ValueGetPrivate (Local< Context > context, Local< Private > key)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ArrayGetPropertyNames (Local< Context > context)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ArrayGetPropertyNames (Local< Context > context, KeyCollectionMode mode, PropertyFilter property_filter, IndexFilter index_filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ArrayGetOwnPropertyNames (Local< Context > context)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ArrayGetOwnPropertyNames (Local< Context > context, PropertyFilter filter, KeyConversionMode key_conversion=KeyConversionMode::kKeepNumbers)
 
Local< ValueGetPrototype ()
 
V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototype (Local< Context > context, Local< Value > prototype)
 
Local< ObjectFindInstanceInPrototypeChain (Local< FunctionTemplate > tmpl)
 
V8_WARN_UNUSED_RESULT MaybeLocal< StringObjectProtoToString (Local< Context > context)
 
Local< StringGetConstructorName ()
 
Maybe< bool > SetIntegrityLevel (Local< Context > context, IntegrityLevel level)
 
int InternalFieldCount ()
 
V8_INLINE Local< ValueGetInternalField (int index)
 
void SetInternalField (int index, Local< Value > value)
 
V8_INLINE void * GetAlignedPointerFromInternalField (int index)
 
void SetAlignedPointerInInternalField (int index, void *value)
 
void SetAlignedPointerInInternalFields (int argc, int indices[], void *values[])
 
V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty (Local< Context > context, uint32_t index)
 
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealNamedProperty (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealIndexedProperty (Local< Context > context, uint32_t index)
 
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealNamedCallbackProperty (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueGetRealNamedPropertyInPrototypeChain (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT Maybe< PropertyAttributeGetRealNamedPropertyAttributesInPrototypeChain (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueGetRealNamedProperty (Local< Context > context, Local< Name > key)
 
V8_WARN_UNUSED_RESULT Maybe< PropertyAttributeGetRealNamedPropertyAttributes (Local< Context > context, Local< Name > key)
 
bool HasNamedLookupInterceptor ()
 
bool HasIndexedLookupInterceptor ()
 
int GetIdentityHash ()
 
Local< ObjectClone ()
 
Local< ContextCreationContext ()
 
bool IsCallable ()
 
bool IsConstructor ()
 
bool IsApiWrapper ()
 
bool IsUndetectable ()
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueCallAsFunction (Local< Context > context, Local< Value > recv, int argc, Local< Value > argv[])
 
V8_WARN_UNUSED_RESULT MaybeLocal< ValueCallAsConstructor (Local< Context > context, int argc, Local< Value > argv[])
 
IsolateGetIsolate ()
 
MaybeLocal< ArrayPreviewEntries (bool *is_key_value)
 
- Public Member Functions inherited from Value
V8_INLINE bool IsUndefined () const
 
V8_INLINE bool IsNull () const
 
V8_INLINE bool IsNullOrUndefined () const
 
bool IsTrue () const
 
bool IsFalse () const
 
bool IsName () const
 
V8_INLINE bool IsString () const
 
bool IsSymbol () const
 
bool IsFunction () const
 
bool IsArray () const
 
bool IsObject () const
 
bool IsBigInt () const
 
bool IsBoolean () const
 
bool IsNumber () const
 
bool IsExternal () const
 
bool IsInt32 () const
 
bool IsUint32 () const
 
bool IsDate () const
 
bool IsArgumentsObject () const
 
bool IsBigIntObject () const
 
bool IsBooleanObject () const
 
bool IsNumberObject () const
 
bool IsStringObject () const
 
bool IsSymbolObject () const
 
bool IsNativeError () const
 
bool IsRegExp () const
 
bool IsAsyncFunction () const
 
bool IsGeneratorFunction () const
 
bool IsGeneratorObject () const
 
bool IsPromise () const
 
bool IsMap () const
 
bool IsSet () const
 
bool IsMapIterator () const
 
bool IsSetIterator () const
 
bool IsWeakMap () const
 
bool IsWeakSet () const
 
bool IsArrayBuffer () const
 
bool IsArrayBufferView () const
 
bool IsTypedArray () const
 
bool IsUint8Array () const
 
bool IsUint8ClampedArray () const
 
bool IsInt8Array () const
 
bool IsUint16Array () const
 
bool IsInt16Array () const
 
bool IsUint32Array () const
 
bool IsInt32Array () const
 
bool IsFloat32Array () const
 
bool IsFloat64Array () const
 
bool IsBigInt64Array () const
 
bool IsBigUint64Array () const
 
bool IsDataView () const
 
bool IsSharedArrayBuffer () const
 
bool IsProxy () const
 
bool IsWasmModuleObject () const
 
bool IsModuleNamespaceObject () const
 
V8_WARN_UNUSED_RESULT MaybeLocal< BigIntToBigInt (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< NumberToNumber (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< StringToString (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< StringToDetailString (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< ObjectToObject (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< IntegerToInteger (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32ToUint32 (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< Int32ToInt32 (Local< Context > context) const
 
Local< BooleanToBoolean (Isolate *isolate) const
 
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32ToArrayIndex (Local< Context > context) const
 
bool BooleanValue (Isolate *isolate) const
 
V8_WARN_UNUSED_RESULT Maybe< double > NumberValue (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT Maybe< int64_t > IntegerValue (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT Maybe< uint32_t > Uint32Value (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT Maybe< int32_t > Int32Value (Local< Context > context) const
 
V8_WARN_UNUSED_RESULT Maybe< bool > Equals (Local< Context > context, Local< Value > that) const
 
bool StrictEquals (Local< Value > that) const
 
bool SameValue (Local< Value > that) const
 
Local< StringTypeOf (Isolate *)
 
Maybe< bool > InstanceOf (Local< Context > context, Local< Object > object)
 
template<class T >
ValueCast (T *value)
 

Static Public Member Functions

static Local< ArrayBufferNew (Isolate *isolate, size_t byte_length)
 
static Local< ArrayBufferNew (Isolate *isolate, std::shared_ptr< BackingStore > backing_store)
 
static std::unique_ptr< BackingStoreNewBackingStore (Isolate *isolate, size_t byte_length)
 
static std::unique_ptr< BackingStoreNewBackingStore (void *data, size_t byte_length, v8::BackingStore::DeleterCallback deleter, void *deleter_data)
 
static V8_INLINE ArrayBufferCast (Value *obj)
 
- Static Public Member Functions inherited from Object
static V8_INLINE int InternalFieldCount (const PersistentBase< Object > &object)
 
static V8_INLINE int InternalFieldCount (const TracedReferenceBase< Object > &object)
 
static V8_INLINE void * GetAlignedPointerFromInternalField (const PersistentBase< Object > &object, int index)
 
static V8_INLINE void * GetAlignedPointerFromInternalField (const TracedReferenceBase< Object > &object, int index)
 
static V8_INLINE Local< ContextCreationContext (const PersistentBase< Object > &object)
 
static Local< ObjectNew (Isolate *isolate)
 
static Local< ObjectNew (Isolate *isolate, Local< Value > prototype_or_null, Local< Name > *names, Local< Value > *values, size_t length)
 
static V8_INLINE ObjectCast (Value *obj)
 
- Static Public Member Functions inherited from Value
template<class T >
static V8_INLINE ValueCast (T *value)
 

Data Fields

void * data
 
void size_t byte_length
 
void size_t ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized)
 

Static Public Attributes

static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
 
static const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
 

Detailed Description

An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).

Definition at line 5021 of file v8.h.

Member Function Documentation

◆ ByteLength()

size_t ByteLength ( ) const

Data length in bytes.

◆ Cast()

ArrayBuffer * Cast ( v8::Value value)
static

Definition at line 11693 of file v8.h.

◆ Detach()

void Detach ( )

Detaches this ArrayBuffer and all its views (typed arrays). Detaching sets the byte length of the buffer and all typed arrays to zero, preventing JavaScript from ever accessing underlying backing store. ArrayBuffer should have been externalized and must be detachable.

◆ Externalize()

void Externalize ( const std::shared_ptr< BackingStore > &  backing_store)

Marks this ArrayBuffer external given a witness that the embedder has fetched the backing store using the new GetBackingStore() function.

With the new lifetime management of backing stores there is no need for externalizing, so this function exists only to make the transition easier.

◆ GetBackingStore()

std::shared_ptr<BackingStore> GetBackingStore ( )

Get a shared pointer to the backing store of this array buffer. This pointer coordinates the lifetime management of the internal storage with any live ArrayBuffers on the heap, even across isolates. The embedder should not attempt to manage lifetime of the storage through other means.

This function replaces both Externalize() and GetContents().

◆ GetContents()

Contents GetContents ( )

Get a pointer to the ArrayBuffer's underlying memory block without externalizing it. If the ArrayBuffer is not externalized, this pointer will become invalid as soon as the ArrayBuffer gets garbage collected.

The embedder should make sure to hold a strong reference to the ArrayBuffer while accessing this pointer.

◆ IsDetachable()

bool IsDetachable ( ) const

Returns true if this ArrayBuffer may be detached.

◆ New() [1/2]

static Local<ArrayBuffer> New ( Isolate isolate,
size_t  byte_length 
)
static

Create a new ArrayBuffer. Allocate |byte_length| bytes. Allocated memory will be owned by a created ArrayBuffer and will be deallocated when it is garbage-collected, unless the object is externalized.

◆ New() [2/2]

static Local<ArrayBuffer> New ( Isolate isolate,
std::shared_ptr< BackingStore backing_store 
)
static

Create a new ArrayBuffer with an existing backing store. The created array keeps a reference to the backing store until the array is garbage collected. Note that the IsExternal bit does not affect this reference from the array to the backing store.

In future IsExternal bit will be removed. Until then the bit is set as follows. If the backing store does not own the underlying buffer, then the array is created in externalized state. Otherwise, the array is created in internalized state. In the latter case the array can be transitioned to the externalized state using Externalize(backing_store).

◆ NewBackingStore() [1/2]

static std::unique_ptr<BackingStore> NewBackingStore ( Isolate isolate,
size_t  byte_length 
)
static

Returns a new standalone BackingStore that is allocated using the array buffer allocator of the isolate. The result can be later passed to ArrayBuffer::New.

If the allocator returns nullptr, then the function may cause GCs in the given isolate and re-try the allocation. If GCs do not help, then the function will crash with an out-of-memory error.

◆ NewBackingStore() [2/2]

static std::unique_ptr<BackingStore> NewBackingStore ( void *  data,
size_t  byte_length,
v8::BackingStore::DeleterCallback  deleter,
void *  deleter_data 
)
static

Returns a new standalone BackingStore that takes over the ownership of the given buffer. The destructor of the BackingStore invokes the given deleter callback.

The result can be later passed to ArrayBuffer::New. The raw pointer to the buffer must not be passed again to any V8 API function.

◆ V8_DEPRECATE_SOON() [1/3]

V8_DEPRECATE_SOON ( "Use GetBackingStore or Detach. See http://crbug.com/v8/9908."  )

Make this ArrayBuffer external. The pointer to underlying memory block and byte length are returned as |Contents| structure. After ArrayBuffer had been externalized, it does no longer own the memory block. The caller should take steps to free memory when it is no longer needed.

The Data pointer of ArrayBuffer::Contents must be freed using the provided deleter, which will call ArrayBuffer::Allocator::Free if the buffer was allocated with ArrayBuffer::Allocator::Allocate.

◆ V8_DEPRECATE_SOON() [2/3]

V8_DEPRECATE_SOON ( "Use the version that takes a BackingStore. " "See http://crbug.com/v8/9908."  )

Create a new ArrayBuffer over an existing memory block. The created array buffer is by default immediately in externalized state. In externalized state, the memory block will not be reclaimed when a created ArrayBuffer is garbage-collected. In internalized state, the memory block will be released using |Allocator::Free| once all ArrayBuffers referencing it are collected by the garbage collector.

◆ V8_DEPRECATE_SOON() [3/3]

V8_DEPRECATE_SOON ( "With v8::BackingStore externalized ArrayBuffers are " "the same as ordinary ArrayBuffers. See http://crbug.com/v8/9908."  ) const

Returns true if ArrayBuffer is externalized, that is, does not own its memory block.

Field Documentation

◆ byte_length

void size_t byte_length

Definition at line 5167 of file v8.h.

◆ data

void* data

Definition at line 5167 of file v8.h.

◆ kEmbedderFieldCount

const int kEmbedderFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
static

Definition at line 5278 of file v8.h.

◆ kInternalFieldCount

const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
static

Definition at line 5277 of file v8.h.

◆ mode

Definition at line 5168 of file v8.h.


The documentation for this class was generated from the following file: