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), its elements as a hidden @@elems array of numbers, 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§

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

Functions§

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_finalization_registry
construct_text_decoder
construct_text_encoder
construct_weakref
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_of
The element values of a typed array / Buffer (None for anything else).
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 (@@elems) or a Buffer (@@bytes); None for anything else.
instance_call
Typed-array instance methods.
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 ArrayBuffer (which carries only a byte length).
kind_of
The @@kind of a typed-array receiver (defaults to Uint8Array).
static_call
Uint8Array.from(iterable[, mapFn]) / Uint8Array.of(...items).
text_decoder_call
text_encoder_call
weakref_call