Initial support for Document, EventTarget, NodeList and Iterator (#541)

* Adding document and node support

* Initial support for Document, EventTarget, NodeList and Iterator

* Add in support for output option type
This commit is contained in:
Jonathan Kingston
2018-07-24 15:00:46 +01:00
committed by Alex Crichton
parent 15d0fcfcf4
commit 4b4bed5ce2
9 changed files with 229 additions and 14 deletions

View File

@ -27,11 +27,11 @@ mod util;
use std::collections::BTreeSet;
use std::fs;
use std::io::{self, Read};
use std::iter::FromIterator;
use std::iter::{self, FromIterator};
use std::path::Path;
use backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports};
use backend::util::{ident_ty, rust_ident, wrap_import_function};
use backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function};
use failure::ResultExt;
use heck::{CamelCase, ShoutySnakeCase};
use quote::ToTokens;
@ -82,7 +82,7 @@ fn compile_ast(mut ast: backend::ast::Program) -> String {
let mut defined = BTreeSet::from_iter(
vec![
"str", "char", "bool", "JsValue", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64",
"usize", "isize", "f32", "f64", "Result", "String", "Vec",
"usize", "isize", "f32", "f64", "Result", "String", "Vec", "Option",
].into_iter()
.map(|id| proc_macro2::Ident::new(id, proc_macro2::Span::call_site())),
);
@ -401,8 +401,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::InterfaceMember {
webidl::ast::InterfaceMember::Const(cnst) => {
cnst.webidl_parse(program, first_pass, self_name)
}
webidl::ast::InterfaceMember::Iterable(iterable) => {
iterable.webidl_parse(program, first_pass, self_name)
}
// TODO
webidl::ast::InterfaceMember::Iterable(_)
| webidl::ast::InterfaceMember::Maplike(_)
| webidl::ast::InterfaceMember::Setlike(_) => {
warn!("Unsupported WebIDL interface member: {:?}", self);
@ -520,6 +522,50 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::RegularAttribute {
}
}
impl<'a> WebidlParse<&'a str> for webidl::ast::Iterable {
fn webidl_parse(
&self,
program: &mut backend::ast::Program,
first_pass: &FirstPassRecord<'_>,
self_name: &'a str,
) -> Result<()> {
if util::is_chrome_only(&self.extended_attributes) {
return Ok(());
}
/* TODO
let throws = util::throws(&self.extended_attributes);
let return_value = webidl::ast::ReturnType::NonVoid(self.value_type.clone());
let args = [];
first_pass
.create_basic_method(
&args,
Some(&"values".to_string()),
&return_value,
self_name,
false,
false, // Should be false
)
.map(wrap_import_function)
.map(|import| program.imports.push(import));
first_pass
.create_basic_method(
&args,
Some(&"keys".to_string()),
&return_value, // Should be a number
self_name,
false,
false, // Should be false
)
.map(wrap_import_function)
.map(|import| program.imports.push(import));
*/
Ok(())
}
}
impl<'a> WebidlParse<&'a str> for webidl::ast::StaticAttribute {
fn webidl_parse(
&self,