mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 02:00:51 +00:00
Merge pull request #303 from teovoinea/master
Added is_chrome_only (#244)
This commit is contained in:
commit
9339a55f3e
@ -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(),
|
||||
|
@ -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<ExtendedAttribute>]) -> 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
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
@ -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);
|
||||
<bool as WasmDescribe>::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,
|
||||
) -> <bool as ::wasm_bindgen::convert::FromWasmAbi>::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_)
|
||||
};
|
||||
<bool as ::wasm_bindgen::convert::FromWasmAbi>::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);
|
||||
<bool as WasmDescribe>::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,
|
||||
) -> <bool as ::wasm_bindgen::convert::FromWasmAbi>::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_)
|
||||
};
|
||||
<bool as ::wasm_bindgen::convert::FromWasmAbi>::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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user