Binary Data Built-ins
ArrayBuffer, SharedArrayBuffer, Atomics, DataView, and TypedArray API reference.
Executive Summary
- ArrayBuffer — raw binary data buffers with fixed-length and resizable modes, transfer semantics, and detachment
- SharedArrayBuffer — fixed-length or growable shared binary buffer, a distinct type from ArrayBuffer
- Atomics — atomic read-modify-write, wait/notify, waitAsync, and pause operations over integer TypedArray views
- DataView — endian-aware typed reads and writes over ArrayBuffer and SharedArrayBuffer storage
- TypedArrays — array-like views over buffer data with 12 element types (Int8 through Float64, BigInt64, BigUint64)
- Uint8Array encoding — Base64 and hex encoding/decoding
ArrayBuffer (Goccia.Builtins.GlobalArrayBuffer.pas, Goccia.Values.ArrayBufferValue.pas)
Implements the ECMAScript ArrayBuffer. See MDN ArrayBuffer reference for the full API.
Full standard compliance — includes resizable buffers (maxByteLength), transfer, and transferToFixedLength.
Immutable buffers — the Immutable ArrayBuffers proposal is supported: transferToImmutable([newLength]) returns a fixed-length immutable buffer, the immutable getter reports the state, an immutable buffer cannot be detached (transfer, transferToFixedLength, and transferToImmutable throw on it), and writes through a backing view are refused: TypedArray indexed assignment is silently ignored, while set, fill, sort, copyWithin, reverse, integer-index defineProperty, Atomics, DataView setters, and TextEncoder.prototype.encodeInto throw TypeError. slice, map, filter, TypedArray.from, and TypedArray.of also throw TypeError when the species or this constructor returns a view of an immutable buffer, including the source's own buffer; subarray only reads, so its result may view one. Immutable buffers also back the default export of bytes module imports.
Internally backed by a zero-initialized TBytes array. ArrayBuffer instances are cloneable via structuredClone, and so are typed arrays and DataView, each keeping its kind, byte offset and length (see Global Constants, Functions, and Error Constructors).
SharedArrayBuffer (Goccia.Values.SharedArrayBufferValue.pas)
Implements the ECMAScript SharedArrayBuffer. See MDN SharedArrayBuffer reference for the full API.
Full standard compliance. SharedArrayBuffer is a distinct type (not an instance of ArrayBuffer). It is fixed-length by default, or growable when constructed with maxByteLength (growable, maxByteLength, grow); it has no resize, transfer, or detachment. SharedArrayBuffer instances are cloneable via structuredClone.
Growing. A growable buffer keeps one data block from construction to collection, so every agent that holds it sees every other agent's writes, Atomics included, before and after a grow. The block is allocated at maxByteLength bytes when the buffer is constructed, all zero, and grow only makes more of it visible. It never allocates or moves the bytes. Memory accounting: a growable buffer is charged maxByteLength bytes against the memory limit when it is constructed, because that is what it allocates, and a fixed-length buffer is charged its byte length. A maxByteLength larger than the limit allows is a RangeError at construction, as ECMA-262's AllocateSharedArrayBuffer allows ("if it is impossible to create a new Shared Data Block value consisting of allocLength bytes").
Atomics (Goccia.Builtins.Atomics.pas)
Implements the ECMAScript Atomics namespace for integer TypedArray views.
Supported operations: add, and, compareExchange, exchange, isLockFree, load, notify, or, pause, store, sub, wait, waitAsync, and xor.
Atomic operations accept an integer TypedArray over an ArrayBuffer or a SharedArrayBuffer. wait, waitAsync, and notify require Int32Array or BigInt64Array views, and wait and waitAsync also require a SharedArrayBuffer (notify on a non-shared view returns 0).
Every waiter has one result, and notify's count agrees with it. Inside the waiter list's critical section notify claims and counts the waiters it wakes: it removes a wait waiter from the list at once, and marks a waitAsync waiter of another thread ready for its owner thread to remove. A wait decides its result in the same critical section once its suspension ends: a waiter that notify already removed returns "ok", even when its timeout passed before the wait got back into the critical section; a waiter still in the list timed out, removes itself and returns "timed-out", and no later notify counts it. waitAsync decides its timeout under the same lock.
A view that is detached or past the end of its shrunk resizable buffer is a TypeError before the index is converted. load, store, compareExchange and the read-modify-write operations convert every argument first, then check the access again (RevalidateAtomicAccess) before they touch the element, because a valueOf can resize or detach the buffer: a view that is now detached or out of bounds is a TypeError, and an element past the end of a shrunk length-tracking view is a RangeError, so nothing is read or written. V8 throws a TypeError in that last case too; ECMA-262 specifies the RangeError.
DataView (Goccia.Values.DataViewValue.pas)
Implements the ECMAScript DataView. DataView instances provide endian-aware typed reads and writes over ArrayBuffer and SharedArrayBuffer storage.
Full standard compliance — includes integer, BigInt, Float16, Float32, and Float64 getters and setters, buffer, byteLength, byteOffset, and detached/out-of-bounds buffer checks. Auto-length views over resizable ArrayBuffer instances track the current buffer length.
TypedArrays (Goccia.Values.TypedArrayValue.pas)
Implements the ECMAScript TypedArray. See MDN TypedArray reference for the full API.
Full standard compliance for the supported types. All standard constructors, static methods (from, of), instance properties, and prototype methods are available.
Supported types:
| Type | Element size | Value range |
|---|---|---|
Int8Array | 1 byte | -128 to 127 |
Uint8Array | 1 byte | 0 to 255 |
Uint8ClampedArray | 1 byte | 0 to 255 (clamped) |
Int16Array | 2 bytes | -32768 to 32767 |
Uint16Array | 2 bytes | 0 to 65535 |
Int32Array | 4 bytes | -2147483648 to 2147483647 |
Uint32Array | 4 bytes | 0 to 4294967295 |
Float16Array | 2 bytes | IEEE 754 half-precision |
Float32Array | 4 bytes | IEEE 754 single-precision |
Float64Array | 8 bytes | IEEE 754 double-precision |
BigInt64Array | 8 bytes | -2⁶³ to 2⁶³-1 (BigInt) |
BigUint64Array | 8 bytes | 0 to 2⁶⁴-1 (BigInt) |
Value encoding: Integer types use fixed-width truncation (overflow wraps). Uint8ClampedArray clamps to [0, 255] with half-to-even rounding. Float16Array rounds to IEEE 754 half precision (max finite ±65504, epsilon 2⁻¹⁰ at 1.0). Float32Array rounds to IEEE 754 single precision. Float64Array preserves full double precision. NaN is stored as 0 in integer types and as NaN in float types.
Uint8Array Base64/Hex encoding (Goccia.Values.Uint8ArrayEncoding.pas)
Uint8Array Base64/Hex encoding. These methods are available only on Uint8Array, not on other TypedArray types.
| Static method | Description |
|---|---|
Uint8Array.fromBase64(string [, options]) | Decode a base64 string to a new Uint8Array. Options: alphabet ("base64" or "base64url"), lastChunkHandling ("loose", "strict", or "stop-before-partial") |
Uint8Array.fromHex(string) | Decode a hex string (case-insensitive) to a new Uint8Array. Throws SyntaxError on odd length or invalid characters |
| Prototype method | Description |
|---|---|
u8.toBase64([options]) | Encode bytes as a base64 string. Options: alphabet ("base64" or "base64url"), omitPadding (boolean, default false) |
u8.toHex() | Encode bytes as a lowercase hex string |
u8.setFromBase64(string [, options]) | Decode base64 into this array. Returns { read, written }. Same options as fromBase64 |
u8.setFromHex(string) | Decode hex into this array. Returns { read, written } |
Related documents
- Built-in Objects — full built-in object reference
- Language Features — language syntax and semantics