Add extends attributes for several types

Part of #670
This commit is contained in:
Andrew Chin 2018-08-08 22:49:06 -04:00
parent 505037ffae
commit cc8095d065
14 changed files with 118 additions and 0 deletions

View File

@ -125,6 +125,7 @@ extern "C" {
// Array
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Array;
@ -347,6 +348,7 @@ extern "C" {
// ArrayBuffer
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type ArrayBuffer;
@ -421,6 +423,7 @@ extern "C" {
// Boolean
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Boolean;
@ -440,6 +443,7 @@ extern "C" {
// DataView
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type DataView;
@ -587,6 +591,7 @@ extern "C" {
// Error
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Error;
@ -625,6 +630,8 @@ extern "C" {
// Float32Array
#[wasm_bindgen]
extern "C" {
// TODO Uncomment this once TypedArray is added:
// #[wasm_bindgen(extends = Object, extends = TypedArray)]
#[derive(Clone, Debug)]
pub type Float32Array;
@ -677,6 +684,8 @@ extern "C" {
// Float64Array
#[wasm_bindgen]
extern "C" {
// TODO Uncomment this once TypedArray is added:
// #[wasm_bindgen(extends = Object, extends = TypedArray)]
#[derive(Clone, Debug)]
pub type Float64Array;
@ -729,6 +738,7 @@ extern "C" {
// Function
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Function;
@ -1007,6 +1017,7 @@ extern "C" {
// Map
#[wasm_bindgen]
extern {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Map;
@ -1385,6 +1396,7 @@ extern "C" {
// Number.
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Number;
@ -1482,6 +1494,7 @@ extern "C" {
// Date.
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Date;
@ -2265,6 +2278,7 @@ extern {
// Set
#[wasm_bindgen]
extern {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type Set;
@ -2559,6 +2573,7 @@ extern "C" {
// WeakMap
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type WeakMap;
@ -2602,6 +2617,7 @@ extern "C" {
// WeakSet
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)]
pub type WeakSet;

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
macro_rules! js_array {
@ -286,3 +287,10 @@ fn for_each() {
assert_eq!(sum_indices_of_evens(&js_array![1, 3, 5, 7]), 0);
assert_eq!(sum_indices_of_evens(&js_array![3, 5, 7, 10]), 3);
}
#[wasm_bindgen_test]
fn array_inheritance() {
let array = js_array![0];
assert!(array.is_instance_of::<Array>());
assert!(array.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -34,3 +35,10 @@ fn slice_with_end() {
let slice = buf.slice_with_end(1, 2);
assert!(JsValue::from(slice).is_object());
}
#[wasm_bindgen_test]
fn arraybuffer_inheritance() {
let buf = ArrayBuffer::new(4);
assert!(buf.is_instance_of::<ArrayBuffer>());
assert!(buf.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -11,3 +12,10 @@ fn new_undefined() {
fn new_truely() {
assert_eq!(Boolean::new(&JsValue::from("foo")).value_of(), true);
}
#[wasm_bindgen_test]
fn boolean_inheritance() {
let b = Boolean::new(&JsValue::from(true));
assert!(b.is_instance_of::<Boolean>());
assert!(b.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -37,3 +38,16 @@ fn test() {
// TODO: figure out how to do `bytes[2]`
bytes.subarray(2, 3).for_each(&mut |x, _, _| assert_eq!(x, 42));
}
#[wasm_bindgen_test]
fn dataview_inheritance() {
let bytes = Int8Array::new(&JsValue::from(10));
// TODO: figure out how to do `bytes[2] = 2`
bytes.subarray(2, 3).fill(2, 0, 1);
let v = DataView::new(&bytes.buffer(), 2, 8);
assert!(v.is_instance_of::<DataView>());
assert!(v.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -406,3 +407,10 @@ fn value_of() {
let date = Date::new(&Date::utc(2018f64, 6f64).into());
assert_eq!(date.value_of(), 1530403200000.0);
}
#[wasm_bindgen_test]
fn date_inheritance() {
let date = Date::new(&"August 19, 1975 23:15:30".into());
assert!(date.is_instance_of::<Date>());
assert!(date.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -35,3 +36,10 @@ fn to_string() {
error.set_name("error_name_1");
assert_eq!(JsValue::from(error.to_string()), "error_name_1: error message 1");
}
#[wasm_bindgen_test]
fn error_inheritance() {
let error = Error::new("test");
assert!(error.is_instance_of::<Error>());
assert!(error.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen]
@ -60,3 +61,9 @@ fn name() {
fn to_string() {
assert!(MAX.to_string().length() > 0);
}
#[wasm_bindgen_test]
fn function_inheritance() {
assert!(MAX.is_instance_of::<Function>());
assert!(MAX.is_instance_of::<Object>());
}

View File

@ -1,4 +1,5 @@
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -86,3 +87,10 @@ fn size() {
map.set(&"bar".into(), &"baz".into());
assert_eq!(map.size(), 2);
}
#[wasm_bindgen_test]
fn map_inheritance() {
let map = Map::new();
assert!(map.is_instance_of::<Map>());
assert!(map.is_instance_of::<Object>());
}

View File

@ -2,6 +2,7 @@ use std::f64::{INFINITY, NAN};
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen_test]
@ -104,3 +105,10 @@ fn to_exponential() {
assert_eq!(Number::new(&123456.into()).to_exponential(2).unwrap(), "1.23e+5");
assert!(Number::new(&10.into()).to_exponential(101).is_err());
}
#[wasm_bindgen_test]
fn number_inheritance() {
let n = Number::new(&JsValue::from(42));
assert!(n.is_instance_of::<Number>());
assert!(n.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
fn set2vec(s: &Set) -> Vec<JsValue> {
@ -80,3 +81,10 @@ fn size() {
set.add(&3.into());
assert_eq!(set.size(), 3);
}
#[wasm_bindgen_test]
fn set_inheritance() {
let set = Set::new(&JsValue::undefined());
assert!(set.is_instance_of::<Set>());
assert!(set.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen(module = "tests/wasm/Symbol.js")]

View File

@ -1,5 +1,6 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen]
@ -50,3 +51,10 @@ fn delete() {
map.delete(&key);
assert!(!map.has(&key));
}
#[wasm_bindgen_test]
fn weakmap_inheritance() {
let map = WeakMap::new();
assert!(map.is_instance_of::<WeakMap>());
assert!(map.is_instance_of::<Object>());
}

View File

@ -1,5 +1,6 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use wasm_bindgen::JsCast;
use js_sys::*;
#[wasm_bindgen]
@ -40,3 +41,10 @@ fn delete() {
assert!(!set.has(&value));
assert!(!set.delete(&value));
}
#[wasm_bindgen_test]
fn weakset_inheritance() {
let set = WeakSet::new();
assert!(set.is_instance_of::<WeakSet>());
assert!(set.is_instance_of::<Object>());
}