-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support for u64 through JSValue::as_u64() and u64::into() -> JsValue #2350
Labels
Comments
lucacasonato
changed the title
Better support for u64 through js_sys::BigInt and JSValue::as_u64()
Better support for u64 through JSValue::as_u64() and u64::into() -> JsValue
Nov 8, 2020
Signed |
Also should be closable now that #2629 is merged. |
I don't see anything similar to Am I missing some API? If not, perhaps worth reopening this issue. |
Ping, can we reopen this? |
RReverser
added a commit
to RReverser/wasm-bindgen
that referenced
this issue
Sep 2, 2022
Adds a way to convert `JsValue` or a `BigInt` to `i64`/`u64`/`i128`/`u128` with type and range checks, returning the original `JsValue` otherwise. This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future. Fixes rustwasm#2350.
RReverser
added a commit
to RReverser/wasm-bindgen
that referenced
this issue
Sep 2, 2022
Adds a way to convert `JsValue` or a `BigInt` to `i64`/`u64`/`i128`/`u128` with type and range checks, returning the original `JsValue` otherwise. This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future. Fixes rustwasm#2350.
RReverser
added a commit
to RReverser/wasm-bindgen
that referenced
this issue
Sep 4, 2022
Adds a way to convert `JsValue` or a `BigInt` to `i64`/`u64`/`i128`/`u128` with type and range checks, returning the original `JsValue` otherwise. This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future. Fixes rustwasm#2350.
Liamolucko
pushed a commit
that referenced
this issue
Sep 4, 2022
Adds a way to convert `JsValue` or a `BigInt` to `i64`/`u64`/`i128`/`u128` with type and range checks, returning the original `JsValue` otherwise. This could be optimised a little bit further via more intrinsics, but it's good enough for the initial implementation, so leaving any optimisations for the future. Fixes #2350.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
BigInt
is now supported in stable releases of all modern browsers. Currently interfacing withBigInt
generically in wasm-bindgen with JSValue is quite painful.JSValue
is not aware ofBigInt
(and thus u64) at all.Proposed Solution
impl From<u64> for JSValue
, that can be used to cast u64 toBigInt
.JSValue::as_u64(&self) -> Option<u64>
to castBigInt
to u64.Alternatives
This solution aligns closely to current implementation of primitives handling in
JSValue
. I am not aware of alternative implementation ideas, or if this can be built on top of wasm-bindgen.The text was updated successfully, but these errors were encountered: