mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Bug 1336769 - Make Angle constructors return a finite value.
It is possible to input an extra large angle, e.g. rotate(9.5e+307rad), so we need to clamp it to avoid any assertion in Gecko.
This commit is contained in:
parent
299f9446e6
commit
29c87224c7
1 changed files with 4 additions and 8 deletions
|
@ -13,6 +13,7 @@ use parser::{ParserContext, Parse};
|
||||||
use self::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
use self::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
||||||
use self::url::SpecifiedUrl;
|
use self::url::SpecifiedUrl;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
use std::f32;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Mul;
|
use std::ops::Mul;
|
||||||
|
@ -232,8 +233,6 @@ pub fn parse_integer(input: &mut Parser) -> Result<Integer, ()> {
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn parse_number(input: &mut Parser) -> Result<Number, ()> {
|
pub fn parse_number(input: &mut Parser) -> Result<Number, ()> {
|
||||||
use std::f32;
|
|
||||||
|
|
||||||
match try!(input.next()) {
|
match try!(input.next()) {
|
||||||
Token::Number(ref value) => {
|
Token::Number(ref value) => {
|
||||||
Ok(Number {
|
Ok(Number {
|
||||||
|
@ -363,7 +362,7 @@ impl Angle {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn from_radians(r: f32) -> Self {
|
pub fn from_radians(r: f32) -> Self {
|
||||||
Angle {
|
Angle {
|
||||||
radians: r,
|
radians: r.min(f32::MAX).max(f32::MIN),
|
||||||
was_calc: false,
|
was_calc: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +370,7 @@ impl Angle {
|
||||||
/// Returns an `Angle` parsed from a `calc()` expression.
|
/// Returns an `Angle` parsed from a `calc()` expression.
|
||||||
pub fn from_calc(radians: CSSFloat) -> Self {
|
pub fn from_calc(radians: CSSFloat) -> Self {
|
||||||
Angle {
|
Angle {
|
||||||
radians: radians,
|
radians: radians.min(f32::MAX).max(f32::MIN),
|
||||||
was_calc: true,
|
was_calc: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,10 +405,7 @@ impl Angle {
|
||||||
_ => return Err(())
|
_ => return Err(())
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Angle {
|
Ok(Angle::from_radians(radians))
|
||||||
radians: radians,
|
|
||||||
was_calc: false,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue