webidl: add support for typedefs

This commit is contained in:
R. Andrew Ohana
2018-06-11 18:35:20 -07:00
parent 3710d87f3b
commit d065f4b05d
5 changed files with 58 additions and 2 deletions

View File

@@ -123,6 +123,7 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
webidl::ast::Definition::Interface(ref interface) => {
interface.webidl_parse(program, ())
}
webidl::ast::Definition::Typedef(ref typedef) => typedef.webidl_parse(program, ()),
// TODO
webidl::ast::Definition::Callback(..)
| webidl::ast::Definition::Dictionary(..)
@@ -130,8 +131,7 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
| webidl::ast::Definition::Implements(..)
| webidl::ast::Definition::Includes(..)
| webidl::ast::Definition::Mixin(..)
| webidl::ast::Definition::Namespace(..)
| webidl::ast::Definition::Typedef(..) => {
| webidl::ast::Definition::Namespace(..) => {
warn!("Unsupported WebIDL definition: {:?}", self);
Ok(())
}
@@ -156,6 +156,34 @@ impl<'a> WebidlParse<'a> for webidl::ast::Interface {
}
}
impl<'a> WebidlParse<'a> for webidl::ast::Typedef {
type Extra = ();
fn webidl_parse(&self, program: &mut backend::ast::Program, _: ()) -> Result<()> {
let dest = rust_ident(&self.name);
let src = match webidl_ty_to_syn_ty(&self.type_, TypePosition::Return) {
Some(src) => src,
None => {
warn!(
"typedef's source type is not yet supported: {:?}. Skipping typedef {:?}",
*self.type_, self
);
return Ok(());
}
};
program.type_aliases.push(backend::ast::TypeAlias {
vis: syn::Visibility::Public(syn::VisPublic {
pub_token: Default::default(),
}),
dest,
src,
});
Ok(())
}
}
impl<'a> WebidlParse<'a> for webidl::ast::NonPartialInterface {
type Extra = ();

View File

@@ -224,6 +224,8 @@ impl Event {
);
}
}
#[allow(non_camel_case_types)]
pub type DOMHighResTimeStamp = f64;
#[allow(non_upper_case_globals)]
#[wasm_custom_section = "__wasm_bindgen_unstable"]
const __WASM_BINDGEN_GENERATED_wasm_bindgen_webidl_0_2_11_0 : [ u8 ; 1299usize ] = * b"\x0F\x05\0\0{\"exports\":[],\"enums\":[],\"imports\":[{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"type\"}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopPropagation_stop_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopPropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopImmediatePropagation_stop_immediate_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopImmediatePropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_preventDefault_prevent_default_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"preventDefault\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_initEvent_init_event_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"initEvent\"}}}],\"structs\":[],\"version\":\"0.2.11 (71107b8e8)\",\"schema_version\":\"4\"}" ;

View File

@@ -10,6 +10,9 @@
* liability, trademark and document use rules apply.
*/
// TODO: don't include this here, use Performance.webidl instead
typedef double DOMHighResTimeStamp;
[Constructor(DOMString type, optional EventInit eventInitDict),
Exposed=(Window,Worker,System), ProbablyShortLivingWrapper]
interface Event {