tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 4ffd8e22b972b14290b03be2bf2e1c26f135910e
parent e1b9fef07cb392e04268d75e35594db458f30b4d
Author: Daniil Sakhapov <sakhapov@chromium.org>
Date:   Fri,  3 Oct 2025 08:59:53 +0000

Bug 1991112 [wpt PR 55096] - Fix category calculation for complex-typed expressions, a=testonly

Automatic update from web-platform-tests
Fix category calculation for complex-typed expressions

Category can only be determined for a math node if a final sum of all
powers is either 0 (then it's a number), or 1 (then it's that 1 type).
But there has been a problem that powers weren't summed up in abs
values, leading to e.g. (1px / 1Hz) resulting in number, since the final
sum ended up being 0. So, this CL reworks category calculation code a
bit by checking that if we have more than one non-null type powers, the
category should be kCalcIntermediate.

But there is still a problem left with kPercent and percent_hint:
Currently, we don't supply percent hint context (info about what
percents in an expression would be resolved against, e.g. kCalcLength),
we rather check at a call side that category of a parsed expression is
the same as we expect. But we can end up in situation like: (1% * 1%) /
1px - which would have two powers (+2 for percent, -1 for length). To
solve this, this CL does a trick in which if we have only two non-null
type powers, once of which is percent, we simulate ApplyPercentHint to
the expression in Category() call. With this, we don't need to supply
the percent hint context info, but solve the problem of not knowing it.
Note also that this solves CSSOM problem, since there we don't know
percent hint context at all during parse time.

Also this CL adds printing for CSSMathType to ease future debugging.

Fixed: 445824614
Change-Id: I4fd179efea371a93ce671027b2e66e9ef564d1c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6973396
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Daniil Sakhapov <sakhapov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1521219}

--

wpt-commits: 7b33a197aab26b0e3c662836968be4380b2bee0d
wpt-pr: 55096

Diffstat:
Atesting/web-platform/tests/css/css-values/typed-arithmetic-different-categories-crash.html | 8++++++++
Mtesting/web-platform/tests/css/css-values/typed_arithmetic.html | 21+++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/testing/web-platform/tests/css/css-values/typed-arithmetic-different-categories-crash.html b/testing/web-platform/tests/css/css-values/typed-arithmetic-different-categories-crash.html @@ -0,0 +1,8 @@ +<!DOCTYPE html> +<title>CSS Values Test: typed arithmetic with different categories crash</title> +<link rel="help" href="https://issues.chromium.org/issues/445824614"> +<style> + body { + stroke-dasharray: calc(0.5px * 2 / -4500000000kHz); + } +</style> diff --git a/testing/web-platform/tests/css/css-values/typed_arithmetic.html b/testing/web-platform/tests/css/css-values/typed_arithmetic.html @@ -5,6 +5,7 @@ <script src="/resources/testharnessreport.js"></script> <script src="/css/support/numeric-testcommon.js"></script> <script src="/css/support/computed-testcommon.js"></script> +<script src="../support/parsing-testcommon.js"></script> <style> :root { font-size: 10px; @@ -41,6 +42,26 @@ test_math_used("calc(10em / 1rem)", "10", {"prop": "z-index"}); test_math_used("calc(10em / 1px)", "100", {"prop": "z-index"}); test_math_used("calc(1px / 10em * NaN)", "0", {"prop": "z-index"}); +// 10% -> 1px; 1px / 1px -> 1. +test_math_used("calc(10% / 1px)", "1", {"prop": "line-height"}); +// 1% * 100% / 10% -> 10%. +test_math_used("calc(1% * 100% / 10%)", "10%", {"prop": "line-height"}); +// 10% / 10% -> 1. +test_math_used("calc(10% / 10%)", "1", {"prop": "line-height"}); +// 10% -> 1px; 1% -> 0.1px; 1px / 0.1px / 1px -> 10px. +test_math_used("calc((10% * 1%) / 1px)", "10px"); +// 10% -> 1px; 1px * 1px / 1px * 10deg / 1deg / 10px -> 1. +test_math_used("calc(10% * 10% / 1px * 10deg / 1deg / 10px)", "1", {"prop": "line-height"}); +// 10% -> 1px; 1px * 1px / 1px * 1deg / 1deg -> 1px. +test_math_used("calc(10% * 10% / 1px * 1deg / 1deg)", "1px", {"prop": "line-height"}); +// 1px * 2deg / 1deg -> 2px. +test_math_used("calc(1px * 2deg / 1deg)", "2px", {"prop": "line-height"}); +// 1px * 3deg / 1deg / 1px -> 3. +test_math_used("calc(1px * 3deg / 1deg / 1px)", "3", {"prop": "line-height"}); + +test_invalid_value("width", "calc((1% * 1deg) / 1px)"); +test_invalid_value("width", "calc((1% * 1% * 1%) / 1px)"); + testComputedValueGreaterOrLowerThan("width", "calc(1px * 10em / 0em)", REALLY_LARGE); testComputedValueGreaterOrLowerThan("width", "calc(1px / 1px * 10em * infinity)", REALLY_LARGE); testComputedValueGreaterOrLowerThan("margin-left", "calc(1px * 10em / -0em)", REALLY_LARGE_NEGATIVE);