From 76dabeddb325861bc625f4e5057616eacc88f915 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 1 Feb 2026 18:20:29 +0100 Subject: [PATCH] Limit the `Math.sumPrecise` polyfill to non-MOZCENTRAL builds After https://bugzilla.mozilla.org/show_bug.cgi?id=1985121 this functionality is now guaranteed to be available in Firefox. Unfortunately general browser support is still somewhat lacking; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise#browser_compatibility Also, while unrelated, use the `MathClamp` helper in the `applyOpacity` function. --- src/display/display_utils.js | 2 +- src/shared/util.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/display/display_utils.js b/src/display/display_utils.js index e12c702a0..61fc8585f 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -799,7 +799,7 @@ class CSSConstants { } function applyOpacity(r, g, b, opacity) { - opacity = Math.min(Math.max(opacity ?? 1, 0), 1); + opacity = MathClamp(opacity ?? 1, 0, 1); const white = 255 * (1 - opacity); r = Math.round(r * opacity + white); g = Math.round(g * opacity + white); diff --git a/src/shared/util.js b/src/shared/util.js index df9138133..ccbc2f56a 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -1235,9 +1235,12 @@ function MathClamp(v, min, max) { return Math.min(Math.max(v, min), max); } -// TODO: Remove this once the `javascript.options.experimental.math_sumprecise` -// preference is removed from Firefox. -if (typeof Math.sumPrecise !== "function") { +// TODO: Remove this once `Math.sumPrecise` is generally available. +if ( + (typeof PDFJSDev === "undefined" || + PDFJSDev.test("SKIP_BABEL && !MOZCENTRAL")) && + typeof Math.sumPrecise !== "function" +) { // Note that this isn't a "proper" polyfill, but since we're only using it to // replace `Array.prototype.reduce()` invocations it should be fine. Math.sumPrecise = function (numbers) {