Skip to content

Commit

Permalink
Fix returning negative i64 values on web target
Browse files Browse the repository at this point in the history
  • Loading branch information
kajacx committed Apr 20, 2023
1 parent 14ae368 commit 75ddc65
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/api/src/js/as_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,11 @@ pub trait AsJs: Sized {
pub fn param_from_js(ty: &Type, js_val: &JsValue) -> Value {
match ty {
Type::I32 => Value::I32(js_val.as_f64().unwrap() as _),
Type::I64 => {
let number = js_val.as_f64().map(|f| f as i64).unwrap_or_else(|| {
if js_val.is_bigint() {
// To support BigInt
let big_num: u128 = js_sys::BigInt::from(js_val.clone()).try_into().unwrap();
big_num as i64
} else {
(js_sys::Number::from(js_val.clone()).as_f64().unwrap()) as i64
}
});
Value::I64(number)
}
Type::I64 => Value::I64(if js_val.is_bigint() {
js_val.clone().try_into().unwrap()
} else {
js_val.as_f64().unwrap() as _
}),
Type::F32 => Value::F32(js_val.as_f64().unwrap() as _),
Type::F64 => Value::F64(js_val.as_f64().unwrap()),
Type::V128 => {
Expand Down

0 comments on commit 75ddc65

Please sign in to comment.