mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Create macros for simplifying element attribute getters (fixes #1931)
This commit is contained in:
parent
1478fab5a5
commit
32fb907384
2 changed files with 48 additions and 0 deletions
47
src/components/script/dom/macros.rs
Normal file
47
src/components/script/dom/macros.rs
Normal 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))
|
||||
}
|
||||
)+
|
||||
);
|
||||
)
|
|
@ -73,6 +73,7 @@ pub mod dom {
|
|||
|
||||
#[path="bindings/codegen/InterfaceTypes.rs"]
|
||||
pub mod types;
|
||||
pub mod macros;
|
||||
|
||||
pub mod attr;
|
||||
pub mod attrlist;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue