Skip to content

Commit

Permalink
Convert Big[Ui,I]nt64Array bindings to use [u/i]64
Browse files Browse the repository at this point in the history
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: rustwasm#3009
Fixes: d6d056c ("Add math-related intrinsics/functions for `JsValue`s (rustwasm#2629)")
  • Loading branch information
ishitatsuyuki committed Jul 29, 2022
1 parent 59883ea commit 32f6081
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
5 changes: 3 additions & 2 deletions crates/js-sys/tests/wasm/Array.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
10 changes: 10 additions & 0 deletions crates/js-sys/tests/wasm/Array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@ 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);
Expand All @@ -618,6 +623,11 @@ 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);
Expand Down

0 comments on commit 32f6081

Please sign in to comment.