diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index e24e783f..4e761889 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -10,6 +10,7 @@ pub struct Program { pub imports: Vec, pub enums: Vec, pub structs: Vec, + pub type_aliases: Vec, } #[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] @@ -120,6 +121,13 @@ pub enum TypeLocation { ExportRet, } +#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))] +pub struct TypeAlias { + pub vis: syn::Visibility, + pub dest: Ident, + pub src: syn::Type, +} + impl Program { pub fn push_item( &mut self, diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index de63b78f..e1ed09b7 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -59,6 +59,9 @@ impl ToTokens for ast::Program { for e in self.enums.iter() { e.to_tokens(tokens); } + for a in self.type_aliases.iter() { + a.to_tokens(tokens); + } // Generate a static which will eventually be what lives in a custom section // of the wasm executable. For now it's just a plain old static, but we'll @@ -823,3 +826,15 @@ impl ToTokens for ast::ImportStatic { }).to_tokens(into); } } + +impl ToTokens for ast::TypeAlias { + fn to_tokens(&self, into: &mut TokenStream) { + let vis = &self.vis; + let dest = &self.dest; + let src = &self.src; + (quote! { + #[allow(non_camel_case_types)] + #vis type #dest = #src; + }).to_tokens(into); + } +} diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index 2e0eee9a..86bc4edf 100755 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -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 = (); @@ -185,10 +213,12 @@ impl<'a> WebidlParse<'a> for webidl::ast::InterfaceMember { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { match *self { + webidl::ast::InterfaceMember::Attribute(ref attr) => { + attr.webidl_parse(program, self_name) + } webidl::ast::InterfaceMember::Operation(ref op) => op.webidl_parse(program, self_name), // TODO - webidl::ast::InterfaceMember::Attribute(_) - | webidl::ast::InterfaceMember::Const(_) + webidl::ast::InterfaceMember::Const(_) | webidl::ast::InterfaceMember::Iterable(_) | webidl::ast::InterfaceMember::Maplike(_) | webidl::ast::InterfaceMember::Setlike(_) => { @@ -199,6 +229,21 @@ impl<'a> WebidlParse<'a> for webidl::ast::InterfaceMember { } } +impl<'a> WebidlParse<'a> for webidl::ast::Attribute { + type Extra = &'a str; + + fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + match *self { + webidl::ast::Attribute::Regular(ref attr) => attr.webidl_parse(program, self_name), + // TODO + webidl::ast::Attribute::Static(_) | webidl::ast::Attribute::Stringifier(_) => { + warn!("Unsupported WebIDL attribute: {:?}", self); + Ok(()) + } + } + } +} + impl<'a> WebidlParse<'a> for webidl::ast::Operation { type Extra = &'a str; @@ -257,6 +302,10 @@ enum TypePosition { } fn webidl_ty_to_syn_ty(ty: &webidl::ast::Type, pos: TypePosition) -> Option { + // nullable types are not yet supported (see issue #14) + if ty.nullable { + return None; + } Some(match ty.kind { // `any` becomes `::wasm_bindgen::JsValue`. webidl::ast::TypeKind::Any => { @@ -332,6 +381,151 @@ fn simple_fn_arg(ident: Ident, ty: syn::Type) -> syn::FnArg { }) } +impl<'a> WebidlParse<'a> for webidl::ast::RegularAttribute { + type Extra = &'a str; + + fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + fn create_getter( + this: &webidl::ast::RegularAttribute, + self_name: &str, + ) -> Option { + let name = raw_ident(&this.name); + let rust_name = rust_ident(&this.name.to_snake_case()); + + let (output, ret) = match webidl_ty_to_syn_ty(&this.type_, TypePosition::Return) { + None => { + warn!("Attribute's type does not yet support reading: {:?}. Skipping getter binding for {:?}", + this.type_, this); + return None; + } + Some(ty) => ( + syn::ReturnType::Type(Default::default(), Box::new(ty.clone())), + Some(ty), + ), + }; + + let self_ty = ident_ty(rust_ident(self_name)); + let self_ref_ty = shared_ref(self_ty.clone()); + + let shim = rust_ident(&format!("__wbg_f_{}_{}_{}", name, rust_name, self_name)); + + Some(backend::ast::Import { + module: None, + version: None, + js_namespace: None, + kind: backend::ast::ImportKind::Function(backend::ast::ImportFunction { + function: backend::ast::Function { + name: name.clone(), + arguments: vec![self_ref_ty.clone()], + ret, + opts: backend::ast::BindgenAttrs { + attrs: vec![ + backend::ast::BindgenAttr::Method, + backend::ast::BindgenAttr::Getter(Some(name.clone())), + ], + }, + rust_attrs: vec![], + rust_decl: Box::new(syn::FnDecl { + fn_token: Default::default(), + generics: Default::default(), + paren_token: Default::default(), + inputs: syn::punctuated::Punctuated::from_iter(vec![simple_fn_arg( + raw_ident("self_"), + self_ref_ty, + )]), + variadic: None, + output, + }), + rust_vis: syn::Visibility::Public(syn::VisPublic { + pub_token: Default::default(), + }), + }, + rust_name, + kind: backend::ast::ImportFunctionKind::Method { + class: self_name.to_string(), + ty: self_ty, + }, + shim, + }), + }) + } + + fn create_setter( + this: &webidl::ast::RegularAttribute, + self_name: &str, + ) -> Option { + let name = raw_ident(&this.name); + let rust_attr_name = rust_ident(&this.name.to_snake_case()); + let rust_name = rust_ident(&format!("set_{}", rust_attr_name)); + + let self_ty = ident_ty(rust_ident(self_name)); + + let (inputs, arguments) = match webidl_ty_to_syn_ty(&this.type_, TypePosition::Argument) + { + None => { + warn!("Attribute's type does not yet support writing: {:?}. Skipping setter binding for {:?}", + this.type_, this); + return None; + } + Some(ty) => { + let self_ref_ty = shared_ref(self_ty.clone()); + let mut inputs = syn::punctuated::Punctuated::new(); + inputs.push(simple_fn_arg(raw_ident("self_"), self_ref_ty.clone())); + inputs.push(simple_fn_arg(rust_attr_name, ty.clone())); + (inputs, vec![self_ref_ty, ty]) + } + }; + + let shim = rust_ident(&format!("__wbg_f_{}_{}_{}", name, rust_name, self_name)); + + Some(backend::ast::Import { + module: None, + version: None, + js_namespace: None, + kind: backend::ast::ImportKind::Function(backend::ast::ImportFunction { + function: backend::ast::Function { + name: name.clone(), + arguments, + ret: None, + opts: backend::ast::BindgenAttrs { + attrs: vec![ + backend::ast::BindgenAttr::Method, + backend::ast::BindgenAttr::Setter(Some(name)), + ], + }, + rust_attrs: vec![], + rust_decl: Box::new(syn::FnDecl { + fn_token: Default::default(), + generics: Default::default(), + paren_token: Default::default(), + inputs, + variadic: None, + output: syn::ReturnType::Default, + }), + rust_vis: syn::Visibility::Public(syn::VisPublic { + pub_token: Default::default(), + }), + }, + rust_name, + kind: backend::ast::ImportFunctionKind::Method { + class: self_name.to_string(), + ty: self_ty, + }, + shim, + }), + }) + } + + create_getter(self, self_name).map(|import| program.imports.push(import)); + + if !self.read_only { + create_setter(self, self_name).map(|import| program.imports.push(import)); + } + + Ok(()) + } +} + impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation { type Extra = &'a str; diff --git a/crates/webidl/tests/expected/Event.rs b/crates/webidl/tests/expected/Event.rs index 47606de4..6cc4fd66 100644 --- a/crates/webidl/tests/expected/Event.rs +++ b/crates/webidl/tests/expected/Event.rs @@ -55,6 +55,49 @@ impl From for ::wasm_bindgen::JsValue { } #[no_mangle] #[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_eventPhase_event_phase_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn event_phase(&self) -> u16 { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_eventPhase_event_phase_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_eventPhase_event_phase_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn event_phase(&self) -> u16 { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] pub extern "C" fn __wbindgen_describe___wbg_f_stopPropagation_stop_propagation_Event() { use wasm_bindgen::describe::*; inform(FUNCTION); @@ -134,6 +177,92 @@ impl Event { } #[no_mangle] #[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_bubbles_bubbles_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn bubbles(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_bubbles_bubbles_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_bubbles_bubbles_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn bubbles(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_cancelable_cancelable_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn cancelable(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_cancelable_cancelable_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_cancelable_cancelable_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn cancelable(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] pub extern "C" fn __wbindgen_describe___wbg_f_preventDefault_prevent_default_Event() { use wasm_bindgen::describe::*; inform(FUNCTION); @@ -173,6 +302,266 @@ impl Event { } #[no_mangle] #[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_defaultPrevented_default_prevented_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn default_prevented(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_defaultPrevented_default_prevented_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_defaultPrevented_default_prevented_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn default_prevented(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_defaultPreventedByChrome_default_prevented_by_chrome_Event( +) { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn default_prevented_by_chrome(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_defaultPreventedByChrome_default_prevented_by_chrome_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_defaultPreventedByChrome_default_prevented_by_chrome_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn default_prevented_by_chrome(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_defaultPreventedByContent_default_prevented_by_content_Event( +) { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn default_prevented_by_content(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_defaultPreventedByContent_default_prevented_by_content_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_defaultPreventedByContent_default_prevented_by_content_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn default_prevented_by_content(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_composed_composed_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn composed(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_composed_composed_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_composed_composed_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn composed(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_isTrusted_is_trusted_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn is_trusted(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_isTrusted_is_trusted_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_isTrusted_is_trusted_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn is_trusted(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_timeStamp_time_stamp_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn time_stamp(&self) -> DOMHighResTimeStamp { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_timeStamp_time_stamp_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_timeStamp_time_stamp_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn time_stamp(&self) -> DOMHighResTimeStamp { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] pub extern "C" fn __wbindgen_describe___wbg_f_initEvent_init_event_Event() { use wasm_bindgen::describe::*; inform(FUNCTION); @@ -224,6 +613,96 @@ impl Event { ); } } +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_cancelBubble_cancel_bubble_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(1u32); + <&Event as WasmDescribe>::describe(); + inform(1); + ::describe(); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn cancel_bubble(&self) -> bool { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_cancelBubble_cancel_bubble_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + ) -> ::Abi; + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + __wbg_f_cancelBubble_cancel_bubble_Event(self_) + }; + ::from_abi( + _ret, + &mut ::wasm_bindgen::convert::GlobalStack::new(), + ) + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn cancel_bubble(&self) -> bool { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[no_mangle] +#[allow(non_snake_case)] +pub extern "C" fn __wbindgen_describe___wbg_f_cancelBubble_set_cancel_bubble_Event() { + use wasm_bindgen::describe::*; + inform(FUNCTION); + inform(2u32); + <&Event as WasmDescribe>::describe(); + ::describe(); + inform(0); +} +impl Event { + #[allow(bad_style)] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + pub extern "C" fn set_cancel_bubble(&self, cancel_bubble: bool) { + ::wasm_bindgen::__rt::link_this_library(); + #[wasm_import_module = "__wbindgen_placeholder__"] + extern "C" { + fn __wbg_f_cancelBubble_set_cancel_bubble_Event( + self_: <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::Abi, + cancel_bubble: ::Abi, + ) -> (); + } + unsafe { + let _ret = { + let mut __stack = ::wasm_bindgen::convert::GlobalStack::new(); + let self_ = + <&Event as ::wasm_bindgen::convert::IntoWasmAbi>::into_abi(self, &mut __stack); + let cancel_bubble = ::into_abi( + cancel_bubble, + &mut __stack, + ); + __wbg_f_cancelBubble_set_cancel_bubble_Event(self_, cancel_bubble) + }; + () + } + } + #[allow(bad_style, unused_variables)] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + pub extern "C" fn set_cancel_bubble(&self, cancel_bubble: bool) { + panic!( + "cannot call wasm-bindgen imported functions on \ + non-wasm targets" + ); + } +} +#[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\"}" ; +const __WASM_BINDGEN_GENERATED_wasm_bindgen_webidl_0_2_11_0 : [ u8 ; 4413usize ] = * b"9\x11\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_eventPhase_event_phase_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"eventPhase\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"eventPhase\"}}},{\"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_bubbles_bubbles_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"bubbles\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"bubbles\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_cancelable_cancelable_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"cancelable\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"cancelable\"}}},{\"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_defaultPrevented_default_prevented_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"defaultPrevented\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"defaultPrevented\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_defaultPreventedByChrome_default_prevented_by_chrome_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"defaultPreventedByChrome\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"defaultPreventedByChrome\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_defaultPreventedByContent_default_prevented_by_content_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"defaultPreventedByContent\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"defaultPreventedByContent\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_composed_composed_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"composed\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"composed\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_isTrusted_is_trusted_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"isTrusted\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"isTrusted\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_timeStamp_time_stamp_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"timeStamp\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"timeStamp\"}}},{\"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\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_cancelBubble_cancel_bubble_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":\"cancelBubble\",\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"cancelBubble\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_cancelBubble_set_cancel_bubble_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":\"cancelBubble\",\"class\":\"Event\",\"function\":{\"name\":\"cancelBubble\"}}}],\"structs\":[],\"version\":\"0.2.11 (71107b8e8)\",\"schema_version\":\"4\"}" ; diff --git a/crates/webidl/tests/fixtures/Event.webidl b/crates/webidl/tests/fixtures/Event.webidl index 972961e9..8dea443a 100644 --- a/crates/webidl/tests/fixtures/Event.webidl +++ b/crates/webidl/tests/fixtures/Event.webidl @@ -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 {