Merge pull request #819 from fitzgen/webidl-interfaces-should-extend-object

webidl: All interfaces implicitly extend `Object`
This commit is contained in:
Nick Fitzgerald 2018-09-12 16:21:48 -07:00 committed by GitHub
commit 2fc499d66d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 27 additions and 3 deletions

View File

@ -15,5 +15,6 @@
extern crate wasm_bindgen;
extern crate js_sys;
use js_sys::Object;
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

View File

@ -1,6 +1,7 @@
use futures::future::Future;
use js_sys::Promise;
use js_sys::{Object, Promise};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::Event;
@ -15,6 +16,10 @@ fn event() -> impl Future<Item = (), Error = JsValue> {
JsFuture::from(new_event())
.map(Event::from)
.map(|event| {
// All DOM interfaces should inherit from `Object`.
assert!(event.is_instance_of::<Object>());
let _: &Object = event.as_ref();
// These should match `new Event`.
assert!(event.bubbles());
assert!(event.cancelable());

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/array.rs"));

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/array_buffer.rs"));

View File

@ -1,5 +1,5 @@
use wasm_bindgen_test::*;
use js_sys::Function;
use js_sys::{Function, Object};
include!(concat!(env!("OUT_DIR"), "/callbacks.rs"));

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/consts.rs"));

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/enums.rs"));

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/global.rs"));

View File

@ -1,9 +1,17 @@
use js_sys::Object;
use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
include!(concat!(env!("OUT_DIR"), "/simple.rs"));
#[wasm_bindgen_test]
fn interfaces_inherit_from_object() {
let m = Method::new(42.0).unwrap();
assert!(m.is_instance_of::<Object>());
let _: &Object = m.as_ref();
}
#[wasm_bindgen_test]
fn method() {
let pi = Method::new(3.14159).unwrap();

View File

@ -1,3 +1,4 @@
use js_sys::Object;
use wasm_bindgen_test::*;
include!(concat!(env!("OUT_DIR"), "/throws.rs"));

View File

@ -120,7 +120,10 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>)
// `AsRef` and such implementations.
for import in program.imports.iter_mut() {
if let backend::ast::ImportKind::Type(t) = &mut import.kind {
t.extends.retain(|n| filter(&n.to_string()));
t.extends.retain(|n| {
first_pass_record.builtin_idents.contains(n) ||
filter(&n.to_string())
});
}
}
@ -445,6 +448,7 @@ impl<'src> FirstPassRecord<'src> {
instanceof_shim: format!("__widl_instanceof_{}", name),
extends: self.all_superclasses(name)
.map(|name| Ident::new(&name, Span::call_site()))
.chain(Some(Ident::new("Object", Span::call_site())))
.collect(),
};
self.append_required_features_doc(&import_type, &mut doc_comment);