Bug 1751107 Part 3 - Clamp current time for SVG elements. r=dholbert

Differential Revision: https://phabricator.services.mozilla.com/D140449
This commit is contained in:
Mathew Hodson 2022-03-11 18:13:07 +00:00
parent e03afacdd6
commit 34da4aaf3e
3 changed files with 12 additions and 1 deletions

View File

@ -200,7 +200,7 @@ void SVGSVGElement::SetCurrentTime(float seconds) {
double fMilliseconds = double(seconds) * PR_MSEC_PER_SEC;
// Round to nearest whole number before converting, to avoid precision
// errors
SMILTime lMilliseconds = int64_t(NS_round(fMilliseconds));
SMILTime lMilliseconds = SVGUtils::ClampToInt64(NS_round(fMilliseconds));
mTimedDocumentRoot->SetCurrentTime(lMilliseconds);
AnimationNeedsResample();
// Trigger synchronous sample now, to:

View File

@ -467,6 +467,15 @@ class SVGUtils final {
std::max(double(INT32_MIN), std::min(double(INT32_MAX), aVal)));
}
/**
* Convert a floating-point value to a 64-bit integer value, clamping to
* the lowest and highest integers that can be safely compared to a double.
*/
static int64_t ClampToInt64(double aVal) {
return static_cast<int64_t>(
std::clamp<double>(aVal, INT64_MIN, std::nexttoward(INT64_MAX, 0)));
}
static nscolor GetFallbackOrPaintColor(
const ComputedStyle&, StyleSVGPaint nsStyleSVG::*aFillOrStroke);

View File

@ -0,0 +1,2 @@
[end-of-time-001-crash.html]
expected: TIMEOUT