Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate magic number representing max unsigned long #7958

Merged
merged 1 commit into from Oct 10, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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
@@ -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
@@ -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;
@@ -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

This comment has been minimized.

Copy link
@mbrubeck

mbrubeck Oct 10, 2015

Contributor

This file needs a license header. With that fixed, r=mbrubeck.

// https://html.spec.whatwg.org/multipage#limited-to-only-non-negative-numbers-greater-than-zero
pub const UNSIGNED_LONG_MAX: u32 = 2147483647;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.