wasm-bindgen
wasm-bindgen copied to clipboard
web_sys::Navigator::hardware_concurrency should return u64
Probably one of those things that can be fixed only on a major version bump: right now Navigator::hardware_concurrency
returns f64
, but it should be returning u64
as per spec (https://html.spec.whatwg.org/multipage/workers.html#dom-navigator-hardwareconcurrency) and for easier consumption by the end user.
I found this via a related nit... the offset parameter for vertexAttribPointer in WebGL is a GLintptr type,
Typedef is long long
in the IDL
https://github.com/rustwasm/wasm-bindgen/blob/564ce74168904e95a7905a828488ec3029bcaad4/crates/web-sys/webidls/enabled/WebGLRenderingContext.webidl#L25
and so the generator produces bindings as both i32 and f64, (rather than i32 and u64?) https://github.com/rustwasm/wasm-bindgen/blob/564ce74168904e95a7905a828488ec3029bcaad4/crates/web-sys/src/features/gen_WebGlRenderingContext.rs#L1942-L1971
I guess an f64 can encode more of the integer space of a u64 than an i32 can, but not all of it! Interesting decision by the IDL translator, to be sure.
I guess an f64 can encode more of the integer space of a u64 than an i32 can, but not all of it!
That's sort of an unsolvable problem - even if the type on the Rust side is changed to u64
, the number still has to be temporarily converted to an f64
within the JS glue, since a WebIDL long long
argument only accepts JS numbers.