From 6f3323e2b8b4167d085be50ee04c08b78b5232ce Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Fri, 29 Jul 2022 17:08:25 +0900 Subject: [PATCH] Convert Big[Ui,I]nt64Array bindings to use [u/i]64 Using BigInt as the macro parameters leads to absurd signatures like slices of BigInt objects (can't exist). Instead, just use the numeric types. bindgen already converts them to bigint when appropriate. Closes: https://github.com/rustwasm/wasm-bindgen/issues/3009 Fixes: d6d056cd ("Add math-related intrinsics/functions for `JsValue`s (#2629)") --- crates/js-sys/src/lib.rs | 4 ++-- crates/js-sys/tests/wasm/Array.js | 5 +++-- crates/js-sys/tests/wasm/Array.rs | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index e0b1dd25a27..1f13a3fdcaf 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -5854,9 +5854,9 @@ arrays! { /// `BigInt64Array()` /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array - BigInt64Array: BigInt, + BigInt64Array: i64, /// `BigUint64Array()` /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array - BigUint64Array: BigInt, + BigUint64Array: u64, } diff --git a/crates/js-sys/tests/wasm/Array.js b/crates/js-sys/tests/wasm/Array.js index 8810bd9db88..f4d6ab71382 100644 --- a/crates/js-sys/tests/wasm/Array.js +++ b/crates/js-sys/tests/wasm/Array.js @@ -1,6 +1,7 @@ // Used for `Array.rs` tests -exports.populate_array = function(arr, start, len) { +exports.populate_array = function(arr, start, len) { + var isBigInt = typeof(arr[0]) === "bigint"; for (i = 0; i < len; i++) { - arr[i] = start + i; + arr[i] = isBigInt ? BigInt(start + i) : start + i; } }; diff --git a/crates/js-sys/tests/wasm/Array.rs b/crates/js-sys/tests/wasm/Array.rs index 9554f39f711..e498c2cc0a9 100644 --- a/crates/js-sys/tests/wasm/Array.rs +++ b/crates/js-sys/tests/wasm/Array.rs @@ -594,6 +594,15 @@ fn Int32Array_view_mut_raw() { test_array_view_mut_raw(js_sys::Int32Array::view_mut_raw, i32::from, JsValue::from); } +#[wasm_bindgen_test] +fn BigInt64Array_view_mut_raw() { + test_array_view_mut_raw( + js_sys::BigInt64Array::view_mut_raw, + i64::from, + JsValue::from, + ); +} + #[wasm_bindgen_test] fn Uint8Array_view_mut_raw() { test_array_view_mut_raw(js_sys::Uint8Array::view_mut_raw, u8::from, JsValue::from); @@ -618,6 +627,15 @@ fn Uint32Array_view_mut_raw() { test_array_view_mut_raw(js_sys::Uint32Array::view_mut_raw, u32::from, JsValue::from); } +#[wasm_bindgen_test] +fn BigUint64Array_view_mut_raw() { + test_array_view_mut_raw( + js_sys::BigUint64Array::view_mut_raw, + u64::from, + JsValue::from, + ); +} + #[wasm_bindgen_test] fn Float32Array_view_mut_raw() { test_array_view_mut_raw(js_sys::Float32Array::view_mut_raw, f32::from, JsValue::from);