Can't return `Number` values as `u64`
Describe the Bug
When creating bindings to a function with a u64 return value, the returned value is assumed to be of type BigInt in the generated bindings. It seems like it would be possible to get Number values containing integers between 2^32 and 2^53-1 as an integer type directly in the bindings, but it doesn't appear to be possible currently.
I couldn't find any documentation explicitly saying "use f64 if you want integers over u32 and convert on the Rust side if you need, it's the same size anyway" (I may have just missed it), but that seems to be the approach that's been taken eg for Date.now() in js_sys.
Steps to Reproduce
- Create a simple alternative binding to
Date.now()expecting au64and a test that calls it:
#[wasm_bindgen]
extern "C" {
pub type Date;
#[wasm_bindgen(static_method_of = Date)]
pub fn now() -> u64;
}
#[cfg(test)]
pub mod tests {
use super::Date;
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
pub fn u64_now() {
Date::now();
}
}
- Run
wasm-pack test --node
Expected Behavior
A binding is produced that can handle a Number or BigInt return value
Actual Behavior
Test fails with
wasm-bindgen: imported JS function that was not marked as `catch` threw an error: expected a bigint argument, found number
That seems sensible to me, I'm happy to review a PR.