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
DataViewinstance exposes. - ELEMENT_
KINDS - The element kinds, each of which gets its own real prototype object whose
parent is the shared
%TypedArray%.prototype.Uint8Arrayleads becauseBuffer.prototypechains onto it. - PROTOTYPE_
METHODS - The methods installed on the real
Uint8Array.prototypeobject (as@proto:Uint8Array:<m>thunks), soUint8Array.prototype.slice.call(x)keeps working now that the prototype is an object rather than aBuiltinnamespace whose every property read synthesized a thunk. - STATIC_
METHODS - UINT8_
PROTOTYPE_ METHODS - The four base64/hex methods
Uint8Array.prototypeowns on its own. In the engine’s own order, whichObject.getOwnPropertyNamesreports. - 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
ArrayBufferkeeps its bytes in, so another view can share it rather than copy. - buffer_
transfer ArrayBuffer.prototype.transfer([newLength])andtransferToFixedLength.- bytes_
per_ element - Bytes per element for a typed-array kind.
- construct
new Uint8Array(...)etc.ArrayBufferis a byte container with only abyteLength.- 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. ADataViewdefaults 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/indexi, orNoneifiis out of range or not an integer index.- elem_
set ta[i] = vwrite (coerced to the kind). Returns true ifiis a valid index.- elem_
values - The element values of a typed array / Buffer as stored —
Value, notf64, so a 64-bit view keeps its BigInts.elems_ofis the numeric view of the same data and stays, becauseBufferreads 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 aValue. 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
&selfone below cannot allocate and so answersundefinedfor those two kinds. - elems_
of - The element values of a typed array / Buffer (
Nonefor anything else). - elems_
with_ host - The elements of a typed-array view, decoded with a host borrow ALREADY
held.
hostreads views from inside&selfmethods (inspect, key enumeration, iteration) where re-entering throughwith_hostwould panic on the outstanding borrow. - finalization_
registry_ call - has_
index - Whether
keyis an in-range integer index of the typed array / Bufferv.Nonewhenvis neither, so callers can fall through to their own logic. - index_
len - The number of elements
vexposes as integer-index own properties, for a typed array (its view length) or aBuffer(@@bytes);Noneotherwise. - instance_
call - is_
bigint_ kind - Whether
kindstores BigInt elements rather than Numbers. The two 64-bit views are the only ones: their elements do not fit anf64without loss, so the whole element pipeline carriesValuerather thanf64. - is_ctor
- The eleven element kinds plus the two buffer types.
- is_
detached - Whether
abhas been DETACHED — its bytes handed to another buffer bytransfer, or given away bystructuredClone’stransferoption. - kind_of
- The
@@kindof a typed-array receiver (defaults toUint8Array). - new_
array_ buffer - Allocate an
ArrayBufferofnzeroed 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 nbytes ofv’s buffer starting at itsbyteOffset + at.- view_
detached - Whether
vis a view whose backing buffer has been detached. - view_
detached_ h view_detachedfor 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
bytesintov’s buffer at itsbyteOffset + at. False when the range does not fit.