Files
scriptc/tests/corpus/4876-array-buffer-inspect.ts
T
Chris Tate 4f44241543 Clarify stream consumer support details
- Describe the consumers' Node Readable scope in the compatibility data
- Renumber the new corpus programs to avoid shared prefixes
2026-10-13 09:13:49 -05:00

28 lines
1.0 KiB
TypeScript

// ArrayBuffer and SharedArrayBuffer inspection: Node's formatArrayBuffer
// `[Uint8Contents]: <hex pairs>` entry (the first 100 bytes, then
// `... N more byte(s)`) plus the byteLength entry inside the class
// braces, breaking onto lines past the 80-column budget, nested in
// objects and arrays, `[ArrayBuffer]` beyond the depth limit, and the
// backing buffer of a non-byte typed array.
import { inspect } from "node:util";
for (const n of [0, 1, 3, 16, 17, 18, 19, 20, 24, 100, 101, 102, 300]) {
const ab = new ArrayBuffer(n);
const view = new Uint8Array(ab);
for (let i = 0; i < n; i++) view[i] = (i * 37) & 255;
console.log(n, ab);
}
const small = new ArrayBuffer(2);
console.log({ a: small, b: [small] });
console.log({ deep: { deeper: { deepest: { ab: small } } } });
console.log([new ArrayBuffer(40), 1]);
console.log(inspect(small));
console.log(`${inspect({ x: new ArrayBuffer(4) })}`);
console.log(new SharedArrayBuffer(3));
const f64 = new Float64Array(2);
f64[0] = 1.5;
console.log(f64.buffer);