diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2014-10-07 19:49:43 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2014-10-07 19:49:43 +0530 |
commit | 98d1ddfcd36e92307211925e55a7c6e475167371 (patch) | |
tree | 3d896ae4d8e7655ab9c3a703f6e12fa6fd0670e1 /components/script/dom/macros.rs | |
parent | ae946a9b762d66f01f669ff526eff5c0eaaa3404 (diff) | |
download | servo-98d1ddfcd36e92307211925e55a7c6e475167371.tar.gz servo-98d1ddfcd36e92307211925e55a7c6e475167371.zip |
Add setter macros, improve getter macros
Diffstat (limited to 'components/script/dom/macros.rs')
-rw-r--r-- | components/script/dom/macros.rs | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index e9b25a6999a..40b150da6c8 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -4,43 +4,92 @@ #[macro_export] macro_rules! make_getter( - ( $attr:ident ) => ( + ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + #[allow(unused_imports)] use std::ascii::StrAsciiExt; let element: JSRef<Element> = ElementCast::from_ref(self); - element.get_string_attribute(stringify!($attr).to_ascii_lower().as_slice()) + element.get_string_attribute($htmlname) } ); + ($attr:ident) => { + make_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + } ) #[macro_export] macro_rules! make_bool_getter( - ( $attr:ident ) => ( + ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> bool { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + #[allow(unused_imports)] use std::ascii::StrAsciiExt; let element: JSRef<Element> = ElementCast::from_ref(self); - element.has_attribute(stringify!($attr).to_ascii_lower().as_slice()) + element.has_attribute($htmlname) } ); + ($attr:ident) => { + make_bool_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + } ) #[macro_export] macro_rules! make_uint_getter( - ( $attr:ident ) => ( + ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> u32 { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; + #[allow(unused_imports)] use std::ascii::StrAsciiExt; let element: JSRef<Element> = ElementCast::from_ref(self); - element.get_uint_attribute(stringify!($attr).to_ascii_lower().as_slice()) + element.get_uint_attribute($htmlname) } ); + ($attr:ident) => { + make_uint_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + } ) +// concat_idents! doesn't work for function name positions, so +// we have to specify both the content name and the HTML name here +#[macro_export] +macro_rules! make_setter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self, value: DOMString) { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: JSRef<Element> = ElementCast::from_ref(self); + element.set_string_attribute($htmlname, value) + } + ); +) + +#[macro_export] +macro_rules! make_bool_setter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self, value: bool) { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: JSRef<Element> = ElementCast::from_ref(self); + element.set_bool_attribute($htmlname, value) + } + ); +) + +#[macro_export] +macro_rules! make_uint_setter( + ( $attr:ident, $htmlname:expr ) => ( + fn $attr(self, value: u32) { + use dom::element::{Element, AttributeHandlers}; + use dom::bindings::codegen::InheritTypes::ElementCast; + let element: JSRef<Element> = ElementCast::from_ref(self); + element.set_uint_attribute($htmlname, value) + } + ); +) /// For use on non-jsmanaged types /// Use #[jstraceable] on JS managed types |