Skip to content

Commit ada615f

Browse files
ibaryshnikovalexcrichton
authored andcommitted
simplify macro for arrays (#1856)
1 parent 3573164 commit ada615f

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/js-sys/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -4657,7 +4657,7 @@ pub fn global() -> Object {
46574657
}
46584658

46594659
macro_rules! arrays {
4660-
($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident => $zero:literal,)*) => ($(
4660+
($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
46614661
#[wasm_bindgen]
46624662
extern "C" {
46634663
#[wasm_bindgen(extends = Object)]
@@ -4843,7 +4843,7 @@ macro_rules! arrays {
48434843

48444844
/// Efficiently copies the contents of this JS typed array into a new Vec.
48454845
pub fn to_vec(&self) -> Vec<$ty> {
4846-
let mut output = vec![$zero; self.length() as usize];
4846+
let mut output = vec![$ty::default(); self.length() as usize];
48474847
self.raw_copy_to(&mut output);
48484848
output
48494849
}
@@ -4862,37 +4862,37 @@ macro_rules! arrays {
48624862
arrays! {
48634863
/// `Int8Array()`
48644864
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
4865-
Int8Array: i8 => 0,
4865+
Int8Array: i8,
48664866

48674867
/// `Int16Array()`
48684868
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
4869-
Int16Array: i16 => 0,
4869+
Int16Array: i16,
48704870

48714871
/// `Int32Array()`
48724872
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
4873-
Int32Array: i32 => 0,
4873+
Int32Array: i32,
48744874

48754875
/// `Uint8Array()`
48764876
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
4877-
Uint8Array: u8 => 0,
4877+
Uint8Array: u8,
48784878

48794879
/// `Uint8ClampedArray()`
48804880
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
4881-
Uint8ClampedArray: u8 => 0,
4881+
Uint8ClampedArray: u8,
48824882

48834883
/// `Uint16Array()`
48844884
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
4885-
Uint16Array: u16 => 0,
4885+
Uint16Array: u16,
48864886

48874887
/// `Uint32Array()`
48884888
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
4889-
Uint32Array: u32 => 0,
4889+
Uint32Array: u32,
48904890

48914891
/// `Float32Array()`
48924892
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
4893-
Float32Array: f32 => 0.0,
4893+
Float32Array: f32,
48944894

48954895
/// `Float64Array()`
48964896
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
4897-
Float64Array: f64 => 0.0,
4897+
Float64Array: f64,
48984898
}

crates/js-sys/tests/wasm/JSON.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use wasm_bindgen_test::*;
55

66
#[wasm_bindgen_test]
77
fn parse_array() {
8-
let js_array = JSON::parse("[1, 2, 3]").unwrap();;
8+
let js_array = JSON::parse("[1, 2, 3]").unwrap();
99
assert!(Array::is_array(&js_array));
1010

1111
let array = Array::from(&js_array);

0 commit comments

Comments
 (0)