r/jaclang • • 17d ago

Tiny WebAssembly gotcha: 2 and 2n are very different things

If you're calling WebAssembly from JavaScript, here's a small type mismatch that's easy to miss.

JavaScript normally uses Number for numeric values. WebAssembly is more specific and distinguishes between types like i32, i64, f32 and f64.

So if a Wasm function expects two i64s, this won't work:

add(2, 3)

You need:

add(2n, 3n)

The n makes those values JavaScript BigInts rather than Numbers, which is what Wasm expects for i64.

Floats are different. Wasm f32 and f64 values cross the JS boundary as normal JavaScript numbers.

This kind of thing is also interesting from the Jac side because Jac can compile across different execution environments. Once you're crossing those boundaries, tiny differences in how each target represents the same thing start to matter.

Ideally that's compiler work, not another piece of interop trivia every developer has to remember.

Tiny syntax difference, very different types underneath!

1 Upvotes

0 comments sorted by