wasm-bindgen
wasm-bindgen copied to clipboard
Support regular JS numbers for incoming 64-bit integers
fixes #4113
This adds support for regular JS numbers (think typeof x === 'number'
) as values for u64
and i64
parameters. This should makes Rust APIs taking large numbers more convenient on the JS side and allows bindings for JS functions that return large numbers (e.g. Date.now()
).
For details on the number
-> bigint
conversion, see the doc comment for number_to_bigint
. Otherwise, the implementation of this PR is quite simple. The correctness of the conversion is tested in the optional_primitives
test.
The reason this PR is still a draft is that I haven't updated the code for function signature types yet. E.g. arg: u64
is still arg: bigint
in TS, even thought it should be arg: bigint | number
now. I'm waiting for #4188, because #4188 add exactly the functionality I need to implement this.