Skip to content

Commit

Permalink
simplify macro for arrays (#1856)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibaryshnikov authored and alexcrichton committed Nov 8, 2019
1 parent 3573164 commit ada615f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4657,7 +4657,7 @@ pub fn global() -> Object {
}

macro_rules! arrays {
($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident => $zero:literal,)*) => ($(
($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
Expand Down Expand Up @@ -4843,7 +4843,7 @@ macro_rules! arrays {

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

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

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

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

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

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

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

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

/// `Float64Array()`
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
Float64Array: f64 => 0.0,
Float64Array: f64,
}
2 changes: 1 addition & 1 deletion crates/js-sys/tests/wasm/JSON.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use wasm_bindgen_test::*;

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

let array = Array::from(&js_array);
Expand Down

0 comments on commit ada615f

Please sign in to comment.