rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.83k stars 1.08k forks source link

Add support for i128 and u128 #4222

Closed RunDevelopment closed 1 week ago

RunDevelopment commented 4 weeks ago

Fixes #2822

This adds WASM ABI support for i128 and u128. Both are split into 2 u64 and passed as such in the ABI.

The following types can now be used in argument and return positions: i128, u128, Option<i128>, and Option<u128>. Return positions can also use Result<i128, E> and Result<u128, E>.

It's important to note that Result<Option<i128>, E> is not supported. This is because the WasmAbi trait supports at most 4 primitives, but Result<Option<i128>, E> would require 5 primitives (2 for i128, 1 for the option tag, 1 for the result tag, and 1 for the error variant value). Future Result<Option<T>, E> ABI optimizations (either combining the result and option tag into one primitive, or raising the number of supported primitives to 5) will make Result<Option<i128>, E> possible, but this should be a separate PR IMO.


Related to #4201.

daxpedda commented 1 week ago

Converting to draft until #4246 is resolved.

RunDevelopment commented 1 week ago

Converting to draft until #4246 is resolved.

Either that, or I just use BigInt(value) everywhere for now. If we decide to bigint literals in #4246 later, I can just make another PR to change it later. Grepping for BigInt( isn't hard.

daxpedda commented 1 week ago

Converting to draft until #4246 is resolved.

Either that, or I just use BigInt(value) everywhere for now. If we decide to bigint literals in #4246 later, I can just make another PR to change it later. Grepping for BigInt( isn't hard.

Yep, please go ahead and just use the constructor!