mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-19 05:29:46 +08:00
17 lines
604 B
TypeScript
17 lines
604 B
TypeScript
// The DataView fences: `.buffer` escaping the one composed position that
|
|
// consumes it, the bigint getters outside Number(...), and a constructor
|
|
// over something that isn't a typed array's `.buffer`.
|
|
|
|
const buf = new Uint8Array(8);
|
|
const view = new DataView(buf.buffer);
|
|
|
|
// '.buffer' only compiles inside new DataView(x.buffer, ...).
|
|
const escaped = buf.buffer;
|
|
|
|
// bigint values have no representation — only Number(view.getBigUint64(...)).
|
|
const big = view.getBigUint64(0);
|
|
|
|
// The constructor wants a typed array's own '.buffer'.
|
|
const ab = new ArrayBuffer(8);
|
|
const direct = new DataView(ab);
|