diff --git a/src/components/script/dom/macros.rs b/src/components/script/dom/macros.rs new file mode 100644 index 00000000000..bfc5d99ec97 --- /dev/null +++ b/src/components/script/dom/macros.rs @@ -0,0 +1,47 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#![macro_escape] + +#[macro_export] +macro_rules! make_getters( + ( $($attr:ident),+ ) => ( + $( + fn $attr(&self) -> DOMString { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: &JSRef = ElementCast::from_ref(self); + element.get_string_attribute(stringify!($attr)) + } + )+ + ); +) + +#[macro_export] +macro_rules! make_bool_getters( + ( $($attr:ident),+ ) => ( + $( + fn $attr(&self) -> bool { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: &JSRef = ElementCast::from_ref(self); + element.has_attribute(stringify!($attr)) + } + )+ + ); +) + +#[macro_export] +macro_rules! make_uint_getters( + ( $($attr:ident),+ ) => ( + $( + fn $attr(&self) -> u32 { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: &JSRef = ElementCast::from_ref(self); + element.get_uint_attribute(stringify!($attr)) + } + )+ + ); +) \ No newline at end of file diff --git a/src/components/script/script.rs b/src/components/script/script.rs index 513286fae8e..f912dec518f 100644 --- a/src/components/script/script.rs +++ b/src/components/script/script.rs @@ -73,6 +73,7 @@ pub mod dom { #[path="bindings/codegen/InterfaceTypes.rs"] pub mod types; + pub mod macros; pub mod attr; pub mod attrlist;