diff options
-rw-r--r-- | components/script/dom/attr.rs | 5 | ||||
-rw-r--r-- | components/script/dom/macros.rs | 6 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 1 | ||||
-rw-r--r-- | components/script/dom/values.rs | 7 |
4 files changed, 15 insertions, 4 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index c597a0a4204..465ed0f4042 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -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 diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 0583fc7edd7..5d843ce5e26 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -146,8 +146,9 @@ macro_rules! make_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(&self, value: u32) { use dom::bindings::codegen::InheritTypes::ElementCast; + use dom::values::UNSIGNED_LONG_MAX; use string_cache::Atom; - let value = if value > 2147483647 { + let value = if value > UNSIGNED_LONG_MAX { $default } else { value @@ -167,10 +168,11 @@ macro_rules! make_limited_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult { use dom::bindings::codegen::InheritTypes::ElementCast; + use dom::values::UNSIGNED_LONG_MAX; use string_cache::Atom; let value = if value == 0 { return Err($crate::dom::bindings::error::Error::IndexSize); - } else if value > 2147483647 { + } else if value > UNSIGNED_LONG_MAX { $default } else { value diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 279270deea2..c5437e136cc 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -332,6 +332,7 @@ pub mod urlhelper; pub mod urlsearchparams; pub mod userscripts; pub mod validitystate; +pub mod values; pub mod virtualmethods; pub mod webglactiveinfo; pub mod webglbuffer; diff --git a/components/script/dom/values.rs b/components/script/dom/values.rs new file mode 100644 index 00000000000..95bea039a97 --- /dev/null +++ b/components/script/dom/values.rs @@ -0,0 +1,7 @@ +/* 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/. */ + +// https://html.spec.whatwg.org/multipage#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long +// https://html.spec.whatwg.org/multipage#limited-to-only-non-negative-numbers-greater-than-zero +pub const UNSIGNED_LONG_MAX: u32 = 2147483647; |