JavaScript's BigInt in WebAssembly!


JavaScript’s Number type is a float64 and is limited to 53 bits of actual value (as specified by IEEE 754).

Wasm offers a 64 bits integer type, there’s currently no efficient way to represent this type in JavaScript, which can be limiting.

JavaScript recently introduced the BigInt object, allowing the representation of arbitrary length integers.


The BigInt interpretation inevitably introduce an overhead, however the conversions happen only at the JavaScript boundaries. The i64 is then used directly in Wasm, which has no overhead.

Under the hood - v8

You can see the CL I made here:


Note that, currently it's only supported when:

A SpiderMonkey (Firefox) is also work-in-progress.

Returning a 64 bits integer from WebAssembly

  (func export 'fn') (result i64)
    (i64.const 66)


exports.fn().constructor ===
exports.fn() ===

Passing from JavaScript and returning from WebAssembly a 64 bits integer

  (func (export 'fn') (param i64) (result i64)
    (get_local 0)


exports.fn(0n) ===
exports.fn(-0n) ===
exports.fn(123n) ===
exports.fn(-123n) ===

Reach out

Say hello: [email protected].

Ping me on Twitter: @svensauleau.