Skip to content

fix: make the BigInt size bounds within JavaScriptCore's 2^20-bit cap - #108

Open
vibdev wants to merge 1 commit into
anomalyco:devfrom
vibdev:fix/bigint-bound-javascriptcore
Open

vibdev wants to merge 1 commit into
anomalyco:devfrom
vibdev:fix/bigint-bound-javascriptcore

Conversation

@vibdev

@vibdev vibdev commented Nov 27, 2026

Copy link
Copy Markdown

Fixes #100

Not sure how much you are targeting JavaScriptCore, but ran into this issue myself as well.

/runtime/limits.ts made 1n << BigInt(MAX_BIGINT_BITS) when it loaded, to compare against. Turns our 2^(2^20) is one bit more than JavaScriptCore allows a BigInt. This was causing issues when running ps in Safari.
RangeError: Out of memory: BigInt generated from this operation is too big.

The bounds are now the largest values that fit, ±(2^(2^20) − 1), compared with <=/>=. The range is the same, and both are still made once. They're made with BigInt.asUintN(MAX_BIGINT_BITS, -1n): building the value with + or * also throws in JavaScriptCore, which sizes the result for a carry before computing it.

Checked in Playwright's WebKit (WebKit 26.0) and in Chrome by bundling src/ for the browser:

on dev, WebKit: the import throws the RangeError above
with this change, WebKit: the import succeeds and 2n ** 64n runs; 2n ** 1048576n and 1n << 1048576n give RangeError:

There's no new test. Bun's JavaScriptCore allows the extra bit (1n << BigInt(2 ** 20) works in bun -e), so a test under bun test would pass before and after this change.

If you do want webkit fixes I did notice one more that I didn't slip in here: arithmetic whose result could cross 2^20 bits, like max + 1n or max * 2n with max at the limit, throws JavaScriptCore's own RangeError from inside the operation, before checkBigIntSize runs. That error ends the run as an ExecutionFailure instead of reaching the program's catch. I can follow up on it separately if that's useful.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing psychoscript throws RangeError in Safari (WebKit/JavaScriptCore)

1 participant