Consolidate magic number representing max unsigned long

This commit is contained in:
Corey Farwell 2015-10-10 10:24:26 -04:00
parent 9cccd98254
commit 4dc8fd76ec
4 changed files with 15 additions and 4 deletions

View file

@ -12,6 +12,7 @@ use dom::bindings::js::{JS, MutNullableHeap};
use dom::bindings::js::{LayoutJS, Root, RootedReference};
use dom::bindings::utils::{Reflector, reflect_dom_object};
use dom::element::{AttributeMutation, Element};
use dom::values::UNSIGNED_LONG_MAX;
use dom::virtualmethods::vtable_for;
use dom::window::Window;
use std::borrow::ToOwned;
@ -52,7 +53,7 @@ impl AttrValue {
// 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 {
let result = if result > UNSIGNED_LONG_MAX {
default
} else {
result
@ -63,7 +64,7 @@ impl AttrValue {
// 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 {
let result = if result == 0 || result > UNSIGNED_LONG_MAX {
default
} else {
result