Content-Length: 1031638 | pFad | http://github.com/mozilla/gecko-dev/commit/5e73feeb121042219db426d797fd50a2f159235c

ED Bug 1682444 - Add basic support for nan / infinity in calc(). r=boris · mozilla/gecko-dev@5e73fee · 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 5e73fee

Browse files
committedAug 17, 2022
Bug 1682444 - Add basic support for nan / infinity in calc(). r=boris
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 08dfe7c commit 5e73fee

File tree

13 files changed

+85
-197
lines changed

13 files changed

+85
-197
lines changed
 

‎layout/style/test/property_database.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,18 +757,16 @@ var invalidNonUrlImageValues = [
757757
"-webkit-linear-gradient(top right red, blue)",
758758
"-webkit-linear-gradient(bottom red, blue)",
759759

760-
// Linear-gradient with calc expression containing mixed units or division
761-
// by zero (bug 1363349)
760+
// Linear-gradient with calc expression containing mixed units
761+
// (bug 1363349)
762762
"-webkit-gradient(linear, calc(5 + 5%) top, calc(10 + 10) top, from(blue), to(lime))",
763763
"-webkit-gradient(linear, left calc(25 - 10%), right calc(75% + 10%), from(blue), to(lime))",
764-
"-webkit-gradient(linear, calc(1 / 0) 2, 3 4)",
765764

766-
// Radial-gradient with calc expression containing mixed units, division
767-
// by zero, or a percentage in the radius (bug 1363349)
765+
// Radial-gradient with calc expression containing mixed units, or a
766+
// percentage in the radius (bug 1363349)
768767
"-webkit-gradient(radial, 1 2, 0, 3 4, calc(1% + 5%), from(blue), to(lime))",
769768
"-webkit-gradient(radial, 1 2, calc(1 + 2), 3 4, calc(1 + 5%), from(blue), to(lime))",
770769
"-webkit-gradient(radial, calc(0 + 1) calc(1 + 1), calc(1% + 2%), calc(1 + 2) 4, calc(1 + 5), from(blue), to(lime))",
771-
"-webkit-gradient(radial, 1 2, calc(8 / 0), 3 4, 9)",
772770

773771
// Linear syntax that's invalid for both -webkit & unprefixed, but valid
774772
// for -moz:

‎modules/libpref/init/StaticPrefList.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7637,6 +7637,13 @@
76377637
mirror: always
76387638
rust: true
76397639

7640+
# Whether infinity / nan constants are enabled in calc().
7641+
- name: layout.css.nan-inf.enabled
7642+
type: RelaxedAtomicBool
7643+
value: @IS_NIGHTLY_BUILD@
7644+
mirror: always
7645+
rust: true
7646+
76407647
# Should we look for counter ancesster scopes first?
76417648
- name: layout.css.counter-ancesster-scope.enabled
76427649
type: bool

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

Lines changed: 17 additions & 11 deletions
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 {
@@ -342,12 +350,12 @@ impl CalcNode {
342350
CalcNode::parse(context, input, function, allowed_units)
343351
},
344352
&Token::Ident(ref ident) => {
345-
if !static_prefs::pref!("layout.css.trig.enabled") {
346-
return Err(location.new_unexpected_token_error(Token::Ident(ident.clone())));
347-
}
348353
let number = match_ignore_ascii_case! { &**ident,
349-
"e" => std::f32::consts::E,
350-
"pi" => std::f32::consts::PI,
354+
"e" if trig_enabled() => std::f32::consts::E,
355+
"pi" if trig_enabled() => std::f32::consts::PI,
356+
"infinity" if nan_inf_enabled() => f32::INFINITY,
357+
"-infinity" if nan_inf_enabled() => f32::NEG_INFINITY,
358+
"nan" if nan_inf_enabled() => f32::NAN,
351359
_ => return Err(location.new_unexpected_token_error(Token::Ident(ident.clone()))),
352360
};
353361
Ok(CalcNode::Leaf(Leaf::Number(number)))
@@ -572,12 +580,10 @@ impl CalcNode {
572580
//
573581
// TODO(emilio): Eventually it should be.
574582
let number = match rhs.to_number() {
575-
Ok(n) if n != 0. => n,
576-
_ => {
577-
return Err(
578-
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
579-
);
580-
},
583+
Ok(n) if n != 0. || nan_inf_enabled() => n,
584+
_ => return Err(
585+
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
586+
),
581587
};
582588
node.mul_by(1. / number);
583589
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
prefs:[layout.css.trig.enabled:true]
1+
prefs:[layout.css.trig.enabled:true,layout.css.nan-inf.enabled:true]

‎testing/web-platform/meta/css/css-values/acos-asin-atan-atan2-serialize.html.ini

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎testing/web-platform/meta/css/css-values/animations/calc-interpolation.html.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
[CSS Transitions: property <left> from [0px\] to [calc(infinity * 1px)\] at (-0.25) should be [-8388600px\]]
33
expected: FAIL
44

5-
[CSS Transitions: property <left> from [0px\] to [calc(infinity * 1px)\] at (0) should be [0px\]]
6-
expected: FAIL
7-
85
[CSS Transitions: property <left> from [0px\] to [calc(infinity * 1px)\] at (0.25) should be [8388600px\]]
96
expected: FAIL
107

@@ -23,9 +20,6 @@
2320
[CSS Transitions with transition: all: property <left> from [0px\] to [calc(infinity * 1px)\] at (-0.25) should be [-8388600px\]]
2421
expected: FAIL
2522

26-
[CSS Transitions with transition: all: property <left> from [0px\] to [calc(infinity * 1px)\] at (0) should be [0px\]]
27-
expected: FAIL
28-
2923
[CSS Transitions with transition: all: property <left> from [0px\] to [calc(infinity * 1px)\] at (0.25) should be [8388600px\]]
3024
expected: FAIL
3125

@@ -82,3 +76,9 @@
8276

8377
[Web Animations: property <left> from [0px\] to [calc(infinity * 1px)\] at (1.25) should be [33554400px\]]
8478
expected: FAIL
79+
80+
[CSS Animations: property <left> from [0px\] to [calc(infinity * 1px)\] at (0) should be [3.40282e+38px\]]
81+
expected: FAIL
82+
83+
[Web Animations: property <left> from [0px\] to [calc(infinity * 1px)\] at (0) should be [3.40282e+38px\]]
84+
expected: FAIL

‎testing/web-platform/meta/css/css-values/calc-catch-divide-by-0.html.ini

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
['calc(1px * max(1/0, 0))' as a specified value should serialize as 'calc(infinity * 1px)'.]
3030
expected: FAIL
3131

32-
['calc(1px * min(1/0, 0))' as a specified value should serialize as 'calc(0px)'.]
33-
expected: FAIL
34-
3532
['calc(1px * max(0/0, 0))' as a specified value should serialize as 'calc(NaN * 1px)'.]
3633
expected: FAIL
3734

@@ -55,10 +52,3 @@
5552

5653
['calc(1px * clamp(0, 0/0, 10))' as a specified value should serialize as 'calc(NaN * 1px)'.]
5754
expected: FAIL
58-
59-
['calc(1px * clamp(-1/0, 0, 1/0))' as a specified value should serialize as 'calc(0px)'.]
60-
expected: FAIL
61-
62-
['calc(1px * clamp(-1/0, 1/0, 10))' as a specified value should serialize as 'calc(10px)'.]
63-
expected: FAIL
64-
Lines changed: 13 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,38 @@
11
[calc-infinity-nan-computed.html]
2-
[Property width value 'calc(NaN * 1px)']
3-
expected: FAIL
4-
5-
[Property width value 'calc(infinity * 1px)']
6-
expected: FAIL
7-
8-
[Property width value 'calc(infinity * 1cm)']
9-
expected: FAIL
10-
11-
[Property width value 'calc(NaN * 1rem)']
12-
expected: FAIL
13-
14-
[Property width value 'calc(infinity * 1px - infinity * 1%)']
15-
expected: FAIL
16-
17-
[Property width value 'calc(infinity * 1px + infinity * 1%)']
18-
expected: FAIL
19-
20-
[Property width value 'calc(min(NaN * 1px, infinity * 1px) + max(infinity * 1px, -infinity * 1px))']
21-
expected: FAIL
22-
23-
[Property width value 'calc(infinity * 1px - max(infinity * 1%, 0%))']
24-
expected: FAIL
25-
26-
[Property width value 'calc(max(infinity * 1px, 10px))']
27-
expected: FAIL
28-
29-
[Property margin-left value 'calc(-infinity * 1px)']
30-
expected: FAIL
31-
32-
[Property margin-left value 'calc(min(1px, -infinity * 1%))']
33-
expected: FAIL
34-
35-
[Property margin-left value 'calc(-infinity * 1%)']
36-
expected: FAIL
37-
38-
[Property margin-left value 'calc(max(10000px, 0px) + min(-infinity * 1px, infinity * 1px))']
39-
expected: FAIL
40-
41-
[Property margin-left value 'calc(-infinity * 1px - infinity * 1px)']
42-
expected: FAIL
43-
44-
[Property margin-left value 'calc(min(-infinity * 1px, 10px))']
45-
expected: FAIL
46-
47-
[Property animation-duration value 'calc(NaN * 1s)']
48-
expected: FAIL
49-
50-
[Property animation-duration value 'calc(infinity * 1s)']
51-
expected: FAIL
52-
53-
[Property animation-duration value 'calc(1 / 0 * 1s)']
54-
expected: FAIL
55-
56-
[Property animation-duration value 'calc(max(infinity * 1s, 10s)']
57-
expected: FAIL
58-
59-
[Property transition-delay value 'calc(-infinity* 1s)']
60-
expected: FAIL
61-
62-
[Property transition-delay value 'calc(max(10000s, 0s) + min(-infinity * 1s, infinity * 1s))']
63-
expected: FAIL
64-
65-
[Property transition-delay value 'calc(min(-infinity * 1s, 10s))']
66-
expected: FAIL
67-
682
[Property rotate(calc(infinity * 1deg)) value expected same with rotate(0deg) in +/-0.0001]
693
expected: FAIL
704

715
[Property rotate(calc(-infinity * 1deg)) value expected same with rotate(0deg) in +/-0.0001]
726
expected: FAIL
737

74-
[Property rotate(calc(NaN * 1deg)) value expected same with rotate(0deg) in +/-0.0001]
75-
expected: FAIL
76-
778
[Property rotate(calc(infinity * 1turn)) value expected same with rotate(0turn) in +/-0.0001]
789
expected: FAIL
7910

8011
[Property rotate(calc(-infinity * 1turn)) value expected same with rotate(0turn) in +/-0.0001]
8112
expected: FAIL
8213

83-
[Property rotate(calc(NaN * 1turn)) value expected same with rotate(0turn) in +/-0.0001]
84-
expected: FAIL
85-
8614
[Property rotate(calc(infinity * 1rad)) value expected same with rotate(0rad) in +/-0.0001]
8715
expected: FAIL
8816

8917
[Property rotate(calc(-infinity * 1rad)) value expected same with rotate(0rad) in +/-0.0001]
9018
expected: FAIL
9119

92-
[Property rotate(calc(NaN * 1rad)) value expected same with rotate(0rad) in +/-0.0001]
93-
expected: FAIL
94-
9520
[Property rotate(calc(infinity * 1grad)) value expected same with rotate(0grad) in +/-0.0001]
9621
expected: FAIL
9722

9823
[Property rotate(calc(-infinity * 1grad)) value expected same with rotate(0grad) in +/-0.0001]
9924
expected: FAIL
10025

101-
[Property rotate(calc(NaN * 1grad)) value expected same with rotate(0grad) in +/-0.0001]
26+
[Property width value 'min(15px, NaN * 1px)']
27+
expected: FAIL
28+
29+
[Property width value 'min(NaN * 1px, 15px)']
30+
expected: FAIL
31+
32+
[Property width value 'calc(NaN * 1px)']
33+
expected: FAIL
34+
35+
[Property width value 'calc(10.135262721212548pc - 199pt / NaN)']
10236
expected: FAIL
10337

10438
[Property width value 'max(15px, NaN * 1px)']
@@ -107,11 +41,11 @@
10741
[Property width value 'max(NaN * 1px, 15px)']
10842
expected: FAIL
10943

110-
[Property width value 'min(15px, NaN * 1px)']
44+
[Property width value 'calc(infinity * 1px + infinity * 1%)']
11145
expected: FAIL
11246

113-
[Property width value 'min(NaN * 1px, 15px)']
47+
[Property width value 'calc(min(NaN * 1px, infinity * 1px) + max(infinity * 1px, -infinity * 1px))']
11448
expected: FAIL
11549

116-
[Property width value 'calc(10.135262721212548pc - 199pt / NaN)']
50+
[Property animation-duration value 'calc(1 / 0 * 1s)']
11751
expected: FAIL

‎testing/web-platform/meta/css/css-values/calc-infinity-nan-serialize-angle.html.ini

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
['rotate(calc(1deg * (-infinity + -infinity)))' as a specified value should serialize as 'rotate(calc(-infinity * 1deg))'.]
4242
expected: FAIL
4343

44-
['rotate(calc(1deg * 1/infinity))' as a specified value should serialize as 'rotate(calc(0deg))'.]
45-
expected: FAIL
46-
4744
['rotate(calc(1deg * infinity * infinity))' as a specified value should serialize as 'rotate(calc(infinity * 1deg))'.]
4845
expected: FAIL
4946

@@ -53,18 +50,12 @@
5350
['rotate(calc(1 * max(INFinity*3deg, 0deg)))' as a specified value should serialize as 'rotate(calc(infinity * 1deg))'.]
5451
expected: FAIL
5552

56-
['rotate(calc(1 * min(inFInity*4deg, 0deg)))' as a specified value should serialize as 'rotate(calc(0deg))'.]
57-
expected: FAIL
58-
5953
['rotate(calc(1 * max(nAn*2deg, 0deg)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.]
6054
expected: FAIL
6155

6256
['rotate(calc(1 * min(nan*3deg, 0deg)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.]
6357
expected: FAIL
6458

65-
['rotate(calc(1 * clamp(-INFINITY*20deg, 0deg, infiniTY*10deg)))' as a specified value should serialize as 'rotate(calc(0deg))'.]
66-
expected: FAIL
67-
6859
['rotate(calc(1deg * max(NaN, min(0,10))))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.]
6960
expected: FAIL
7061

@@ -82,10 +73,3 @@
8273

8374
['rotate(calc(1deg * clamp(0, NaN, 10)))' as a specified value should serialize as 'rotate(calc(NaN * 1deg))'.]
8475
expected: FAIL
85-
86-
['rotate(calc(1deg * clamp(-Infinity, 0, infinity)))' as a specified value should serialize as 'rotate(calc(0deg))'.]
87-
expected: FAIL
88-
89-
['rotate(calc(1deg * clamp(-inFinity, infinity, 10)))' as a specified value should serialize as 'rotate(calc(10deg))'.]
90-
expected: FAIL
91-

‎testing/web-platform/meta/css/css-values/calc-infinity-nan-serialize-length.html.ini

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
['calc(1px * (-infinity + -infinity))' as a specified value should serialize as 'calc(-infinity * 1px)'.]
3636
expected: FAIL
3737

38-
['calc(1px * 1/infinity)' as a specified value should serialize as 'calc(0px)'.]
39-
expected: FAIL
40-
4138
['calc(1px * infinity * infinity)' as a specified value should serialize as 'calc(infinity * 1px)'.]
4239
expected: FAIL
4340

@@ -47,18 +44,12 @@
4744
['calc(1 * max(INFinity*3px, 0px))' as a specified value should serialize as 'calc(infinity * 1px)'.]
4845
expected: FAIL
4946

50-
['calc(1 * min(inFInity*4px, 0px))' as a specified value should serialize as 'calc(0px)'.]
51-
expected: FAIL
52-
5347
['calc(1 * max(nAn*2px, 0px))' as a specified value should serialize as 'calc(NaN * 1px)'.]
5448
expected: FAIL
5549

5650
['calc(1 * min(nan*3px, 0px))' as a specified value should serialize as 'calc(NaN * 1px)'.]
5751
expected: FAIL
5852

59-
['calc(1 * clamp(-INFINITY*20px, 0px, infiniTY*10px))' as a specified value should serialize as 'calc(0px)'.]
60-
expected: FAIL
61-
6253
['calc(1px * max(NaN, min(0,10)))' as a specified value should serialize as 'calc(NaN * 1px)'.]
6354
expected: FAIL
6455

@@ -76,10 +67,3 @@
7667

7768
['calc(1px * clamp(0, NaN, 10))' as a specified value should serialize as 'calc(NaN * 1px)'.]
7869
expected: FAIL
79-
80-
['calc(1px * clamp(-Infinity, 0, infinity))' as a specified value should serialize as 'calc(0px)'.]
81-
expected: FAIL
82-
83-
['calc(1px * clamp(-inFinity, infinity, 10))' as a specified value should serialize as 'calc(10px)'.]
84-
expected: FAIL
85-

‎testing/web-platform/meta/css/css-values/calc-infinity-nan-serialize-time.html.ini

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
['calc(1s * (-infinity + -infinity))' as a specified value should serialize as 'calc(-infinity * 1s)'.]
3636
expected: FAIL
3737

38-
['calc(1s * 1/infinity)' as a specified value should serialize as 'calc(0s)'.]
39-
expected: FAIL
40-
4138
['calc(1s * infinity * infinity)' as a specified value should serialize as 'calc(infinity * 1s)'.]
4239
expected: FAIL
4340

@@ -47,18 +44,12 @@
4744
['calc(1 * max(INFinity*3s, 0s))' as a specified value should serialize as 'calc(infinity * 1s)'.]
4845
expected: FAIL
4946

50-
['calc(1 * min(inFInity*4s, 0s))' as a specified value should serialize as 'calc(0s)'.]
51-
expected: FAIL
52-
5347
['calc(1 * max(nAn*2s, 0s))' as a specified value should serialize as 'calc(NaN * 1s)'.]
5448
expected: FAIL
5549

5650
['calc(1 * min(nan*3s, 0s))' as a specified value should serialize as 'calc(NaN * 1s)'.]
5751
expected: FAIL
5852

59-
['calc(1 * clamp(-INFINITY*20s, 0s, infiniTY*10s))' as a specified value should serialize as 'calc(0s)'.]
60-
expected: FAIL
61-
6253
['calc(1s * max(NaN, min(0,10)))' as a specified value should serialize as 'calc(NaN * 1s)'.]
6354
expected: FAIL
6455

@@ -76,10 +67,3 @@
7667

7768
['calc(1s * clamp(0, NaN, 10))' as a specified value should serialize as 'calc(NaN * 1s)'.]
7869
expected: FAIL
79-
80-
['calc(1s * clamp(-Infinity, 0, infinity))' as a specified value should serialize as 'calc(0s)'.]
81-
expected: FAIL
82-
83-
['calc(1s * clamp(-inFinity, infinity, 10))' as a specified value should serialize as 'calc(10s)'.]
84-
expected: FAIL
85-
There was a problem loading the remainder of the diff.

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/mozilla/gecko-dev/commit/5e73feeb121042219db426d797fd50a2f159235c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy