Skip to content

Commit

Permalink
Switch to JsValue intrinsics for i64 -> JsValue
Browse files Browse the repository at this point in the history
As of rustwasm/wasm-bindgen#3049 the builtin conversions no longer use strings, but pass numbers directly, so our custom intrinsic is no longer necessary.
  • Loading branch information
RReverser committed Sep 1, 2022
1 parent 0d5a3ec commit 07f8fd1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,4 @@ extern "C" {

#[wasm_bindgen(js_name = BigInt)]
pub fn bigint_to_i64(x: &BigInt) -> i64;

#[wasm_bindgen(js_name = BigInt)]
pub fn bigint_from_u64(x: u64) -> BigInt;

#[wasm_bindgen(js_name = BigInt)]
pub fn bigint_from_i64(x: i64) -> BigInt;
}
4 changes: 2 additions & 2 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn convert_pair(pair: JsValue) -> (Deserializer, Deserializer) {
fn bigint_to_i64(bigint: &BigInt) -> Option<i64> {
let converted_number = bindings::bigint_to_i64(bigint);
// Do a round trip check in order to make sure that no information was lost
if &bindings::bigint_from_i64(converted_number) == bigint {
if *bigint == converted_number {
Some(converted_number)
} else {
None
Expand All @@ -166,7 +166,7 @@ fn bigint_to_i64(bigint: &BigInt) -> Option<i64> {
fn bigint_to_u64(bigint: &BigInt) -> Option<u64> {
let converted_number = bindings::bigint_to_u64(bigint);
// Do a round trip check in order to make sure that no information was lost
if &bindings::bigint_from_u64(converted_number) == bigint {
if *bigint == converted_number {
Some(converted_number)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'s> ser::Serializer for &'s Serializer {

fn serialize_i64(self, v: i64) -> Result {
if self.serialize_large_number_types_as_bigints {
return Ok(bindings::bigint_from_i64(v).into());
return Ok(v.into());
}

// Note: don't try to "simplify" by using `.abs()` as it can overflow,
Expand All @@ -325,7 +325,7 @@ impl<'s> ser::Serializer for &'s Serializer {

fn serialize_u64(self, v: u64) -> Result {
if self.serialize_large_number_types_as_bigints {
return Ok(bindings::bigint_from_u64(v).into());
return Ok(v.into());
}

const MAX_SAFE_INTEGER: u64 = 9_007_199_254_740_991;
Expand Down

0 comments on commit 07f8fd1

Please sign in to comment.