mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Consolidate magic number representing max unsigned long
This commit is contained in:
parent
9cccd98254
commit
4dc8fd76ec
4 changed files with 15 additions and 4 deletions
|
@ -12,6 +12,7 @@ use dom::bindings::js::{JS, MutNullableHeap};
|
||||||
use dom::bindings::js::{LayoutJS, Root, RootedReference};
|
use dom::bindings::js::{LayoutJS, Root, RootedReference};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::element::{AttributeMutation, Element};
|
use dom::element::{AttributeMutation, Element};
|
||||||
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use dom::virtualmethods::vtable_for;
|
use dom::virtualmethods::vtable_for;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use std::borrow::ToOwned;
|
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
|
// https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long
|
||||||
pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
|
pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
|
||||||
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
|
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
|
||||||
let result = if result > 2147483647 {
|
let result = if result > UNSIGNED_LONG_MAX {
|
||||||
default
|
default
|
||||||
} else {
|
} else {
|
||||||
result
|
result
|
||||||
|
@ -63,7 +64,7 @@ impl AttrValue {
|
||||||
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero
|
// 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 {
|
pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue {
|
||||||
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
|
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
|
default
|
||||||
} else {
|
} else {
|
||||||
result
|
result
|
||||||
|
|
|
@ -146,8 +146,9 @@ macro_rules! make_uint_setter(
|
||||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||||
fn $attr(&self, value: u32) {
|
fn $attr(&self, value: u32) {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||||
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let value = if value > 2147483647 {
|
let value = if value > UNSIGNED_LONG_MAX {
|
||||||
$default
|
$default
|
||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
|
@ -167,10 +168,11 @@ macro_rules! make_limited_uint_setter(
|
||||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||||
fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult {
|
fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||||
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let value = if value == 0 {
|
let value = if value == 0 {
|
||||||
return Err($crate::dom::bindings::error::Error::IndexSize);
|
return Err($crate::dom::bindings::error::Error::IndexSize);
|
||||||
} else if value > 2147483647 {
|
} else if value > UNSIGNED_LONG_MAX {
|
||||||
$default
|
$default
|
||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
|
|
|
@ -332,6 +332,7 @@ pub mod urlhelper;
|
||||||
pub mod urlsearchparams;
|
pub mod urlsearchparams;
|
||||||
pub mod userscripts;
|
pub mod userscripts;
|
||||||
pub mod validitystate;
|
pub mod validitystate;
|
||||||
|
pub mod values;
|
||||||
pub mod virtualmethods;
|
pub mod virtualmethods;
|
||||||
pub mod webglactiveinfo;
|
pub mod webglactiveinfo;
|
||||||
pub mod webglbuffer;
|
pub mod webglbuffer;
|
||||||
|
|
7
components/script/dom/values.rs
Normal file
7
components/script/dom/values.rs
Normal file
|
@ -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;
|
Loading…
Add table
Add a link
Reference in a new issue