mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 22:22:12 +00:00
This commit implements the first half of [RFC #5] where the `Deref` trait is implemented for all imported types. The target of `Deref` is either the first entry of the list of `extends` attribute or `JsValue`. All examples using `.as_ref()` with various `web-sys` types have been updated to the more ergonomic deref casts now. Additionally the `web-sys` generation of the `extends` array has been fixed slightly to explicitly list implementatoins in the hierarchy order to ensure the correct target for `Deref` is chosen. [RFC #5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
#![cfg(target_arch = "wasm32")]
|
|
|
|
extern crate futures;
|
|
extern crate js_sys;
|
|
extern crate wasm_bindgen;
|
|
extern crate wasm_bindgen_futures;
|
|
extern crate wasm_bindgen_test;
|
|
extern crate web_sys;
|
|
|
|
use wasm_bindgen::{JsValue, JsCast};
|
|
use wasm_bindgen_test::*;
|
|
|
|
wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
pub mod anchor_element;
|
|
pub mod body_element;
|
|
pub mod br_element;
|
|
pub mod button_element;
|
|
pub mod console;
|
|
pub mod div_element;
|
|
pub mod element;
|
|
pub mod event;
|
|
pub mod head_element;
|
|
pub mod headers;
|
|
pub mod heading_element;
|
|
pub mod history;
|
|
pub mod hr_element;
|
|
pub mod html_element;
|
|
pub mod html_html_element;
|
|
pub mod input_element;
|
|
//TODO: Both menu-related tests completely break in Chrome, but run fine in Firefox.
|
|
//pub mod menu_element;
|
|
//pub mod menu_item_element;
|
|
pub mod dom_point;
|
|
pub mod location;
|
|
pub mod meta_element;
|
|
pub mod meter_element;
|
|
pub mod mod_elements;
|
|
pub mod olist_element;
|
|
pub mod optgroup_element;
|
|
pub mod option_element;
|
|
pub mod options_collection;
|
|
pub mod output_element;
|
|
pub mod paragraph_element;
|
|
pub mod param_element;
|
|
pub mod performance;
|
|
pub mod pre_element;
|
|
pub mod progress_element;
|
|
pub mod quote_element;
|
|
pub mod response;
|
|
pub mod script_element;
|
|
pub mod select_element;
|
|
pub mod slot_element;
|
|
pub mod span_element;
|
|
pub mod style_element;
|
|
pub mod table_element;
|
|
pub mod title_element;
|
|
pub mod xpath_result;
|
|
pub mod indexeddb;
|
|
|
|
#[wasm_bindgen_test]
|
|
fn deref_works() {
|
|
let x = JsValue::from(3);
|
|
let x = x.unchecked_into::<web_sys::XmlHttpRequestUpload>();
|
|
let y: &web_sys::XmlHttpRequestEventTarget = &x;
|
|
drop(y);
|
|
}
|