From ea0ac134dbe1af2847201be88f1703ea196b51ea Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:29:13 +0200 Subject: [PATCH 1/9] js-sys: Add extends attributes for js_sys::Uint8Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 852d49f1..7bdcc9d0 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2539,6 +2539,7 @@ extern { // Uint8Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Uint8Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index e3b6292a..ac9dcaba 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -1,7 +1,26 @@ use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; +use wasm_bindgen::JsCast; use js_sys::*; +macro_rules! each { + ($m:ident) => ( + $m!(Uint8Array); + ) +} + +macro_rules! test_inheritence { + ($arr:ident) => ({ + let arr = $arr::new(&JsValue::undefined()); + assert!(arr.is_instance_of::()); + assert!(arr.is_instance_of::()); + }) +} +#[wasm_bindgen_test] +fn inheritence() { + each!(test_inheritence); +} + macro_rules! each { ($m:ident) => ( $m!(Uint8Array); From 2979618842f15144e119e32da0f3a00e7604deea Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:31:49 +0200 Subject: [PATCH 2/9] js-sys: Add extends attributes for js_sys::UInt8ClampedArray --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 7bdcc9d0..93b0923a 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2592,6 +2592,7 @@ extern "C" { // Uint8ClampedArray #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Uint8ClampedArray; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index ac9dcaba..458feca8 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -6,13 +6,14 @@ use js_sys::*; macro_rules! each { ($m:ident) => ( $m!(Uint8Array); + $m!(Uint8ClampedArray); ) } macro_rules! test_inheritence { ($arr:ident) => ({ let arr = $arr::new(&JsValue::undefined()); - assert!(arr.is_instance_of::()); + assert!(arr.is_instance_of::<$arr>()); assert!(arr.is_instance_of::()); }) } From e58e231fdf8de5923836500753c59878205f658f Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:32:14 +0200 Subject: [PATCH 3/9] js-sys: Add extends attributes for js_sys::UInt16Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 93b0923a..427c3c17 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2647,6 +2647,7 @@ extern "C" { // Uint16Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Uint16Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 458feca8..7dbfe61c 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -7,6 +7,7 @@ macro_rules! each { ($m:ident) => ( $m!(Uint8Array); $m!(Uint8ClampedArray); + $m!(Uint16Array); ) } From b80090d3954df9f97b1dc039a8614152600bd7bc Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:32:34 +0200 Subject: [PATCH 4/9] js-sys: Add extends attributes for js_sys::UInt32Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 427c3c17..3490fbee 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2700,6 +2700,7 @@ extern "C" { // Uint32Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Uint32Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 7dbfe61c..5387213e 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -8,6 +8,7 @@ macro_rules! each { $m!(Uint8Array); $m!(Uint8ClampedArray); $m!(Uint16Array); + $m!(Uint32Array); ) } From 17ef5f970238ca443ddc840a05511a0ad815dc3c Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:34:26 +0200 Subject: [PATCH 5/9] js-sys: Add extends attributes for js_sys::Int8Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 3490fbee..4034a9c7 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -914,6 +914,7 @@ extern { // Int8Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Int8Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 5387213e..151dad8a 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -9,6 +9,7 @@ macro_rules! each { $m!(Uint8ClampedArray); $m!(Uint16Array); $m!(Uint32Array); + $m!(Int8Array); ) } From 2d737c5634b7d7e058f57344002fea0ea72e1f49 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:34:43 +0200 Subject: [PATCH 6/9] js-sys: Add extends attributes for js_sys::Int16Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 4034a9c7..461a1125 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -967,6 +967,7 @@ extern "C" { // Int16Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Int16Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 151dad8a..d57f5364 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -10,6 +10,7 @@ macro_rules! each { $m!(Uint16Array); $m!(Uint32Array); $m!(Int8Array); + $m!(Int16Array); ) } From 10bc69a8cd796dfb13f6c6a64eacb21b3a335b21 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:34:59 +0200 Subject: [PATCH 7/9] js-sys: Add extends attributes for js_sys::Int32Array --- crates/js-sys/src/lib.rs | 1 + crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 461a1125..f8aff6b1 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -1020,6 +1020,7 @@ extern "C" { // Int32Array #[wasm_bindgen] extern "C" { + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Int32Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index d57f5364..751ec1bf 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -11,6 +11,7 @@ macro_rules! each { $m!(Uint32Array); $m!(Int8Array); $m!(Int16Array); + $m!(Int32Array); ) } From d9fbc48daac43b8d16277812a18aa4504cb060b2 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:38:33 +0200 Subject: [PATCH 8/9] js-sys: Add extends attributes for js_sys::Float32Array --- crates/js-sys/src/lib.rs | 2 +- crates/js-sys/tests/wasm/TypedArray.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index f8aff6b1..c913a59f 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -684,7 +684,7 @@ extern "C" { #[wasm_bindgen] extern "C" { // TODO Uncomment this once TypedArray is added: - // #[wasm_bindgen(extends = Object, extends = TypedArray)] + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Float32Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 751ec1bf..4a99cb2e 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -12,6 +12,7 @@ macro_rules! each { $m!(Int8Array); $m!(Int16Array); $m!(Int32Array); + $m!(Float32Array); ) } From af9ecac296990221b4dc3cdcae488f3fc0ae12be Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 14 Aug 2018 19:39:02 +0200 Subject: [PATCH 9/9] js-sys: Add extends attributes for js_sys::Float64Array address review comments add review comments --- crates/js-sys/src/lib.rs | 4 +--- crates/js-sys/tests/wasm/TypedArray.rs | 16 ++-------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index c913a59f..6375708b 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -683,7 +683,6 @@ extern "C" { // Float32Array #[wasm_bindgen] extern "C" { - // TODO Uncomment this once TypedArray is added: #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Float32Array; @@ -737,8 +736,7 @@ extern "C" { // Float64Array #[wasm_bindgen] extern "C" { - // TODO Uncomment this once TypedArray is added: - // #[wasm_bindgen(extends = Object, extends = TypedArray)] + #[wasm_bindgen(extends = Object)] #[derive(Clone, Debug)] pub type Float64Array; diff --git a/crates/js-sys/tests/wasm/TypedArray.rs b/crates/js-sys/tests/wasm/TypedArray.rs index 4a99cb2e..5c1e88fc 100644 --- a/crates/js-sys/tests/wasm/TypedArray.rs +++ b/crates/js-sys/tests/wasm/TypedArray.rs @@ -13,6 +13,7 @@ macro_rules! each { $m!(Int16Array); $m!(Int32Array); $m!(Float32Array); + $m!(Float64Array); ) } @@ -20,6 +21,7 @@ macro_rules! test_inheritence { ($arr:ident) => ({ let arr = $arr::new(&JsValue::undefined()); assert!(arr.is_instance_of::<$arr>()); + let _: &Object = arr.as_ref(); assert!(arr.is_instance_of::()); }) } @@ -28,20 +30,6 @@ fn inheritence() { each!(test_inheritence); } -macro_rules! each { - ($m:ident) => ( - $m!(Uint8Array); - $m!(Uint8ClampedArray); - $m!(Uint16Array); - $m!(Uint32Array); - $m!(Int8Array); - $m!(Int16Array); - $m!(Int32Array); - $m!(Float32Array); - $m!(Float64Array); - ) -} - macro_rules! test_undefined { ($arr:ident) => ({ let arr = $arr::new(&JsValue::undefined());