Skip to main content

Module typedarray

Module typedarray 

Source
Expand description

JavaScript typed arrays (Uint8Array/Int8Array/…/Float64Array), ArrayBuffer, WeakRef, and TextEncoder/TextDecoder.

A typed array is a plain object tagged @@native = "TypedArray" carrying its kind (@@kind), a window (@@buffer/byteOffset/length) onto the bytes its ArrayBuffer owns, and the enumerable length/byteLength/BYTES_PER_ELEMENT data properties JS code reads directly. Element indexing (ta[i] get/set) is special-cased in builtins::get_property/set_property via elem_get/elem_set here, which also apply each kind’s coercion (integer wrap / clamp / float).

WeakRef holds a strong reference (deref() always returns the target) — node-js has no GC of JS objects, so this is observably correct for the express dependency tree (object-inspect/qs/side-channel only ever deref()).

Constants§

DATAVIEW_METHODS
The methods a DataView instance exposes.
ELEMENT_KINDS
The element kinds, each of which gets its own real prototype object whose parent is the shared %TypedArray%.prototype. Uint8Array leads because Buffer.prototype chains onto it.
PROTOTYPE_METHODS
The methods installed on the real Uint8Array.prototype object (as @proto:Uint8Array:<m> thunks), so Uint8Array.prototype.slice.call(x) keeps working now that the prototype is an object rather than a Builtin namespace whose every property read synthesized a thunk.
STATIC_METHODS
UINT8_PROTOTYPE_METHODS
The four base64/hex methods Uint8Array.prototype owns on its own. In the engine’s own order, which Object.getOwnPropertyNames reports.
UINT8_STATIC_METHODS
Uint8Array’s statics — the shared three plus the base64/hex pair, which no other view has.

Functions§

buffer_byte_length
An ArrayBuffer’s byte length, from its own store.
buffer_bytes_snapshot
A COPY of an ArrayBuffer’s bytes, for the callers that only read.
buffer_resize
ab.resize(n) on a resizable buffer — grows with zeros or truncates, in place, so every view over it sees the new size.
buffer_slice
ArrayBuffer.prototype.slice(begin[, end]) — a COPY of the byte range, as a new buffer. Writes to it are not seen by views over the original.
buffer_store
The heap array an ArrayBuffer keeps its bytes in, so another view can share it rather than copy.
buffer_transfer
ArrayBuffer.prototype.transfer([newLength]) and transferToFixedLength.
bytes_per_element
Bytes per element for a typed-array kind.
construct
new Uint8Array(...) etc. ArrayBuffer is a byte container with only a byteLength.
construct_dataview
new DataView(buffer[, byteOffset[, byteLength]]).
construct_finalization_registry
construct_text_decoder
construct_text_encoder
construct_weakref
dataview_call
dv.getUint16(off[, littleEndian]) and its siblings. A DataView defaults to BIG-endian, unlike a typed array, which is the whole reason it exists.
detach_buffer
Detach ab: drop its bytes and mark it, so every later read reports zero length and every method over it throws.
detached_error
The TypeError a method over a DETACHED buffer throws. Node names the method and distinguishes a view’s from a DataView’s from the buffer’s own.
elem_get
ta[i] read: the element at char/index i, or None if i is out of range or not an integer index.
elem_set
ta[i] = v write (coerced to the kind). Returns true if i is a valid index.
elem_values
The element values of a typed array / Buffer as stored — Value, not f64, so a 64-bit view keeps its BigInts. elems_of is the numeric view of the same data and stays, because Buffer reads bytes through it.
elems_display
Every element rendered for display, for util.inspect — which holds a shared borrow and so cannot allocate the BigInt a 64-bit element would need as a Value. Elements are always primitives, so a string loses nothing.
elems_mut_host
The elements of a view with a MUTABLE host borrow held, so the two 64-bit kinds can allocate their BigInts. This is the complete reader; the &self one below cannot allocate and so answers undefined for those two kinds.
elems_of
The element values of a typed array / Buffer (None for anything else).
elems_with_host
The elements of a typed-array view, decoded with a host borrow ALREADY held. host reads views from inside &self methods (inspect, key enumeration, iteration) where re-entering through with_host would panic on the outstanding borrow.
finalization_registry_call
has_index
Whether key is an in-range integer index of the typed array / Buffer v. None when v is neither, so callers can fall through to their own logic.
index_len
The number of elements v exposes as integer-index own properties, for a typed array (its view length) or a Buffer (@@bytes); None otherwise.
instance_call
is_bigint_kind
Whether kind stores BigInt elements rather than Numbers. The two 64-bit views are the only ones: their elements do not fit an f64 without loss, so the whole element pipeline carries Value rather than f64.
is_ctor
The eleven element kinds plus the two buffer types.
is_detached
Whether ab has been DETACHED — its bytes handed to another buffer by transfer, or given away by structuredClone’s transfer option.
kind_of
The @@kind of a typed-array receiver (defaults to Uint8Array).
new_array_buffer
Allocate an ArrayBuffer of n zeroed bytes.
static_call
Uint8Array.from(iterable[, mapFn]) / Uint8Array.of(...items), and the base64/hex statics.
static_methods
The statics <kind> advertises.
text_decoder_call
text_encoder_call
view_bytes
n bytes of v’s buffer starting at its byteOffset + at.
view_detached
Whether v is a view whose backing buffer has been detached.
view_detached_h
view_detached for a caller that already holds the host borrow — the iteration entry point runs under one, and re-entering aborts the process.
weakref_call
write_buffer_bytes
Overwrite an ArrayBuffer’s bytes wholesale, for a producer that computed them outside the heap.
write_view_bytes
Write bytes into v’s buffer at its byteOffset + at. False when the range does not fit.