mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Improve support of limited unsigned long attributes
This commit is contained in:
parent
15c4372a8b
commit
fedad2af1f
15 changed files with 106 additions and 483 deletions
|
@ -39,7 +39,7 @@ macro_rules! make_bool_getter(
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! make_uint_getter(
|
||||
( $attr:ident, $htmlname:expr ) => (
|
||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||
fn $attr(self) -> u32 {
|
||||
use dom::element::{Element, AttributeHandlers};
|
||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||
|
@ -47,9 +47,12 @@ macro_rules! make_uint_getter(
|
|||
use std::ascii::AsciiExt;
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||
element.get_uint_attribute(&Atom::from_slice($htmlname))
|
||||
element.get_uint_attribute(&Atom::from_slice($htmlname), $default)
|
||||
}
|
||||
);
|
||||
($attr:ident, $htmlname:expr) => {
|
||||
make_uint_getter!($attr, $htmlname, 0);
|
||||
};
|
||||
($attr:ident) => {
|
||||
make_uint_getter!($attr, to_lower!(stringify!($attr)));
|
||||
}
|
||||
|
@ -153,15 +156,51 @@ macro_rules! make_bool_setter(
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! make_uint_setter(
|
||||
( $attr:ident, $htmlname:expr ) => (
|
||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||
fn $attr(self, value: u32) {
|
||||
use dom::element::{Element, AttributeHandlers};
|
||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||
let value = if value > 2147483647 {
|
||||
$default
|
||||
} else {
|
||||
value
|
||||
};
|
||||
let element: JSRef<Element> = ElementCast::from_ref(self);
|
||||
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
||||
element.set_uint_attribute(&Atom::from_slice($htmlname), value)
|
||||
}
|
||||
);
|
||||
($attr:ident, $htmlname:expr) => {
|
||||
make_uint_setter!($attr, $htmlname, 0);
|
||||
};
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! make_limited_uint_setter(
|
||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||
fn $attr(self, value: u32) -> $crate::dom::bindings::error::ErrorResult {
|
||||
use dom::element::AttributeHandlers;
|
||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||
use string_cache::Atom;
|
||||
let value = if value == 0 {
|
||||
return Err($crate::dom::bindings::error::Error::IndexSize);
|
||||
} else if value > 2147483647 {
|
||||
$default
|
||||
} else {
|
||||
value
|
||||
};
|
||||
let element = ElementCast::from_ref(self);
|
||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||
element.set_uint_attribute(&Atom::from_slice($htmlname), value);
|
||||
Ok(())
|
||||
}
|
||||
);
|
||||
($attr:ident, $htmlname:expr) => {
|
||||
make_limited_uint_setter!($attr, $htmlname, 1);
|
||||
};
|
||||
($attr:ident) => {
|
||||
make_limited_uint_setter!($attr, to_lower!(stringify!($attr)));
|
||||
};
|
||||
);
|
||||
|
||||
/// For use on non-jsmanaged types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue