mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
* feat: add static BigInt support * fix: prevent BigInt width overflow on WASI * fix: harden BigInt formatting sizes * test: record BigInt WASI parity baseline
29 lines
1016 B
TypeScript
29 lines
1016 B
TypeScript
import assert from "node:assert/strict";
|
|
|
|
function show(label: string, fn: () => void): void {
|
|
try {
|
|
fn();
|
|
} catch (error) {
|
|
if (error instanceof Error) console.log(label, error.name, error.message);
|
|
}
|
|
}
|
|
|
|
show("parse", () => { BigInt("12x"); });
|
|
show("number", () => { BigInt(1.5); });
|
|
show("divide", () => { 1n / 0n; });
|
|
show("power", () => { 2n ** -1n; });
|
|
show("radix", () => { (1n).toString(1); });
|
|
show("width", () => { BigInt.asUintN(-1, 1n); });
|
|
|
|
show("unsigned", () => { Buffer.alloc(8).writeBigUInt64BE(-1n); });
|
|
show("signed", () => { Buffer.alloc(8).writeBigInt64BE(1n << 63n); });
|
|
show("buffer-size", () => { Buffer.alloc(4).readBigUInt64BE(); });
|
|
show("buffer-offset", () => { Buffer.alloc(8).writeBigInt64BE(1n, 2); });
|
|
|
|
const view = new DataView(new ArrayBuffer(8));
|
|
show("dataview", () => { view.getBigInt64(1); });
|
|
|
|
show("assert-equal", () => { assert.equal(1n, 2n); });
|
|
show("assert-deep", () => { assert.deepEqual(1n, 2n); });
|
|
show("assert-not", () => { assert.notEqual(1n, 1n); });
|