Content-Length: 363624 | pFad | http://github.com/servo/servo/commit/cc09c2ffb14d02c1884d15190d466eb4c2d5e700

E2 style: Add basic support for nan / infinity in calc() · servo/servo@cc09c2f · GitHub
Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc09c2f

Browse files
emiliomrobinson
authored andcommittedOct 2, 2023
style: Add basic support for nan / infinity in calc()
Fix some tests to: * Not assume `double` precision. * Account for recent working group resolution with regards to NaN: w3c/csswg-drafts#7067 (comment) Not sure I caught all, but normalizing to 0 was already our existing behavior. This feature needs more work before it can be enabled more generally, so make it nightly-only, for now. Also, it's unclear per spec what the serialization for infinity*1s or so should be. Right now we serialize to <very-big-number>s, which seems reasonable, but some tests (but not others!) expect different behavior. I left those untouched for now. Differential Revision: https://phabricator.services.mozilla.com/D154883
1 parent dd849de commit cc09c2f

File tree

1 file changed

+17
-11
lines changed
  • components/style/values/specified

1 file changed

+17
-11
lines changed
 

‎components/style/values/specified/calc.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ use std::fmt::{self, Write};
2020
use style_traits::values::specified::AllowedNumericType;
2121
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
2222

23+
fn trig_enabled() -> bool {
24+
static_prefs::pref!("layout.css.trig.enabled")
25+
}
26+
27+
fn nan_inf_enabled() -> bool {
28+
static_prefs::pref!("layout.css.nan-inf.enabled")
29+
}
30+
2331
//github.com/ The name of the mathematical function that we're parsing.
2432
#[derive(Clone, Copy, Debug, Parse)]
2533
pub enum MathFunction {
@@ -349,12 +357,12 @@ impl CalcNode {
349357
CalcNode::parse(context, input, function, allowed_units)
350358
},
351359
&Token::Ident(ref ident) => {
352-
if !trig_enabled() {
353-
return Err(location.new_unexpected_token_error(Token::Ident(ident.clone())));
354-
}
355360
let number = match_ignore_ascii_case! { &**ident,
356-
"e" => std::f32::consts::E,
357-
"pi" => std::f32::consts::PI,
361+
"e" if trig_enabled() => std::f32::consts::E,
362+
"pi" if trig_enabled() => std::f32::consts::PI,
363+
"infinity" if nan_inf_enabled() => f32::INFINITY,
364+
"-infinity" if nan_inf_enabled() => f32::NEG_INFINITY,
365+
"nan" if nan_inf_enabled() => f32::NAN,
358366
_ => return Err(location.new_unexpected_token_error(Token::Ident(ident.clone()))),
359367
};
360368
Ok(CalcNode::Leaf(Leaf::Number(number)))
@@ -579,12 +587,10 @@ impl CalcNode {
579587
//
580588
// TODO(emilio): Eventually it should be.
581589
let number = match rhs.to_number() {
582-
Ok(n) if n != 0. => n,
583-
_ => {
584-
return Err(
585-
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
586-
);
587-
},
590+
Ok(n) if n != 0. || nan_inf_enabled() => n,
591+
_ => return Err(
592+
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
593+
),
588594
};
589595
node.mul_by(1. / number);
590596
},

0 commit comments

Comments
 (0)
Failed to load comments.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/servo/servo/commit/cc09c2ffb14d02c1884d15190d466eb4c2d5e700

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy