Add WebIDL support for the object type

This maps to the `Object` type in the `js_sys` crate.
This commit is contained in:
Alex Crichton
2018-08-04 15:05:31 -07:00
parent 654bb9b683
commit 90579416cf
6 changed files with 59 additions and 4 deletions

View File

@ -0,0 +1,33 @@
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;
use web_sys::{DomPoint, DomPointReadOnly};
#[wasm_bindgen_test]
fn dom_point() {
let x = DomPoint::new(1.0, 2.0, 3.0, 4.0).unwrap();
assert_eq!(x.x(), 1.0);
x.set_x(1.5);
assert_eq!(x.x(), 1.5);
assert_eq!(x.y(), 2.0);
x.set_y(2.5);
assert_eq!(x.y(), 2.5);
assert_eq!(x.z(), 3.0);
x.set_z(3.5);
assert_eq!(x.z(), 3.5);
assert_eq!(x.w(), 4.0);
x.set_w(4.5);
assert_eq!(x.w(), 4.5);
}
#[wasm_bindgen_test]
fn dom_point_readonly() {
let x = DomPoint::new(1.0, 2.0, 3.0, 4.0).unwrap();
let x = DomPointReadOnly::from(JsValue::from(x));
assert_eq!(x.x(), 1.0);
assert_eq!(x.y(), 2.0);
assert_eq!(x.z(), 3.0);
assert_eq!(x.w(), 4.0);
}

View File

@ -50,3 +50,5 @@ pub mod style_element;
pub mod table_element;
pub mod title_element;
pub mod xpath_result;
pub mod dom_point;
pub mod performance;

View File

@ -1,5 +1,4 @@
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use web_sys::HtmlOptionElement;
#[wasm_bindgen_test]
@ -41,4 +40,4 @@ fn test_option_element() {
assert_eq!(option.text(), "potato", "Option should have the text we gave it.");
assert_eq!(option.index(), 0, "This should be the first option, since there are no other known options.");
}
}

View File

@ -0,0 +1,15 @@
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use web_sys::Performance;
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_name = performance)]
static PERFORMANCE: Performance;
}
#[wasm_bindgen_test]
fn to_json() {
let perf = JsValue::from(PERFORMANCE.to_json());
assert!(perf.is_object());
}