Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify macro for arrays #1856

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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