mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +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
|
@ -54,8 +54,25 @@ impl AttrValue {
|
|||
AttrValue::TokenList(tokens, atoms)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long
|
||||
pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
|
||||
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
|
||||
let result = if result > 2147483647 {
|
||||
default
|
||||
} else {
|
||||
result
|
||||
};
|
||||
AttrValue::UInt(string, result)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero
|
||||
pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue {
|
||||
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
|
||||
let result = if result == 0 || result > 2147483647 {
|
||||
default
|
||||
} else {
|
||||
result
|
||||
};
|
||||
AttrValue::UInt(string, result)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue