From 7cd3ca02a26f604972e33e65cac84cd1be1eb9a5 Mon Sep 17 00:00:00 2001 From: teovoinea Date: Mon, 2 Jul 2018 20:35:05 -0700 Subject: [PATCH] Update with masters and fix PR changes --- crates/webidl/src/lib.rs | 24 ++++++ crates/webidl/src/util.rs | 30 +++++++ crates/webidl/tests/expected/Event.rs | 116 ++++---------------------- 3 files changed, 68 insertions(+), 102 deletions(-) diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index 950207eb..3d589cf9 100644 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -128,6 +128,10 @@ impl WebidlParse<()> for webidl::ast::Interface { impl WebidlParse<()> for webidl::ast::Typedef { fn webidl_parse(&self, program: &mut backend::ast::Program, _: ()) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + let dest = rust_ident(&self.name); let src = match webidl_ty_to_syn_ty(&self.type_, TypePosition::Return) { Some(src) => src, @@ -154,6 +158,10 @@ impl WebidlParse<()> for webidl::ast::Typedef { impl WebidlParse<()> for webidl::ast::NonPartialInterface { fn webidl_parse(&self, program: &mut backend::ast::Program, _: ()) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + program.imports.push(backend::ast::Import { module: None, version: None, @@ -293,6 +301,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::Operation { impl<'a> WebidlParse<&'a str> for webidl::ast::RegularAttribute { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + create_getter( &self.name, &self.type_, @@ -317,6 +329,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::RegularAttribute { impl<'a> WebidlParse<&'a str> for webidl::ast::StaticAttribute { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + create_getter( &self.name, &self.type_, @@ -341,6 +357,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::StaticAttribute { impl<'a> WebidlParse<&'a str> for webidl::ast::RegularOperation { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + create_basic_method( &self.arguments, self.name.as_ref(), @@ -356,6 +376,10 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::RegularOperation { impl<'a> WebidlParse<&'a str> for webidl::ast::StaticOperation { fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> { + if util::is_chrome_only(&self.extended_attributes) { + return Ok(()) + } + create_basic_method( &self.arguments, self.name.as_ref(), diff --git a/crates/webidl/src/util.rs b/crates/webidl/src/util.rs index 5b197dde..aeeb29f3 100644 --- a/crates/webidl/src/util.rs +++ b/crates/webidl/src/util.rs @@ -6,6 +6,7 @@ use heck::SnakeCase; use proc_macro2::Ident; use syn; use webidl; +use webidl::ast::ExtendedAttribute; fn shared_ref(ty: syn::Type) -> syn::Type { syn::TypeReference { @@ -285,3 +286,32 @@ pub fn create_setter( vec![backend::ast::BindgenAttr::Setter(Some(raw_ident(name)))], ) } + +/// ChromeOnly is for things that are only exposed to priveleged code in Firefox. +pub fn is_chrome_only(ext_attrs: &[Box]) -> bool { + ext_attrs.iter().any(|external_attribute| { + return match &**external_attribute { + ExtendedAttribute::ArgumentList(al) => { + println!("ArgumentList"); + al.name == "ChromeOnly" + }, + ExtendedAttribute::Identifier(i) => { + println!("Identifier"); + i.lhs == "ChromeOnly" + }, + ExtendedAttribute::IdentifierList(il) => { + println!("IdentifierList"); + il.lhs == "ChromeOnly" + }, + ExtendedAttribute::NamedArgumentList(nal) => { + println!("NamedArgumentList"); + nal.lhs_name == "ChromeOnly" + }, + ExtendedAttribute::NoArguments(webidl::ast::Other::Identifier(name)) => name == "ChromeOnly", + ExtendedAttribute::NoArguments(_na) => { + println!("NoArguments"); + false + } + }; + }) +} \ No newline at end of file diff --git a/crates/webidl/tests/expected/Event.rs b/crates/webidl/tests/expected/Event.rs index 2bcf0b3f..bc171810 100644 --- a/crates/webidl/tests/expected/Event.rs +++ b/crates/webidl/tests/expected/Event.rs @@ -99,7 +99,7 @@ impl Event { pub extern "C" fn new(type_: &str, event_init_dict: EventInit) -> Event { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -143,7 +143,7 @@ impl Event { pub extern "C" fn event_phase(&self) -> u16 { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -183,7 +183,7 @@ impl Event { pub extern "C" fn stop_propagation(&self) { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -223,7 +223,7 @@ impl Event { pub extern "C" fn stop_immediate_propagation(&self) { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -267,7 +267,7 @@ impl Event { pub extern "C" fn bubbles(&self) -> bool { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -311,7 +311,7 @@ impl Event { pub extern "C" fn cancelable(&self) -> bool { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -351,7 +351,7 @@ impl Event { pub extern "C" fn prevent_default(&self) { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -395,95 +395,7 @@ impl Event { 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)] -#[doc(hidden)] -pub extern "C" fn __wbindgen_describe___widl_f_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 __widl_f_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); - __widl_f_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)] -#[doc(hidden)] -pub extern "C" fn __wbindgen_describe___widl_f_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 __widl_f_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); - __widl_f_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" + non-wasm targets" ); } } @@ -527,7 +439,7 @@ impl Event { pub extern "C" fn composed(&self) -> bool { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -571,7 +483,7 @@ impl Event { pub extern "C" fn is_trusted(&self) -> bool { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -615,7 +527,7 @@ impl Event { pub extern "C" fn time_stamp(&self) -> DOMHighResTimeStamp { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -669,7 +581,7 @@ impl Event { pub extern "C" fn init_event(&self, type_: &str, bubbles: bool, cancelable: bool) { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -713,7 +625,7 @@ impl Event { pub extern "C" fn cancel_bubble(&self) -> bool { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } } @@ -759,7 +671,7 @@ impl Event { pub extern "C" fn set_cancel_bubble(&self, cancel_bubble: bool) { panic!( "cannot call wasm-bindgen imported functions on \ - non-wasm targets" + non-wasm targets" ); } }