Create macros for simplifying element attribute getters (fixes #1931)

This commit is contained in:
Manish Goregaokar 2014-08-18 20:23:19 +05:30
parent 1478fab5a5
commit 32fb907384
2 changed files with 48 additions and 0 deletions

View file

@ -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<Element> = 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<Element> = 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<Element> = ElementCast::from_ref(self);
element.get_uint_attribute(stringify!($attr))
}
)+
);
)

View file

@ -73,6 +73,7 @@ pub mod dom {
#[path="bindings/codegen/InterfaceTypes.rs"] #[path="bindings/codegen/InterfaceTypes.rs"]
pub mod types; pub mod types;
pub mod macros;
pub mod attr; pub mod attr;
pub mod attrlist; pub mod attrlist;