Skip to content

Commit 76dabed

Browse files
committed
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.
1 parent d25f13d commit 76dabed

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/display/display_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class CSSConstants {
799799
}
800800

801801
function applyOpacity(r, g, b, opacity) {
802-
opacity = Math.min(Math.max(opacity ?? 1, 0), 1);
802+
opacity = MathClamp(opacity ?? 1, 0, 1);
803803
const white = 255 * (1 - opacity);
804804
r = Math.round(r * opacity + white);
805805
g = Math.round(g * opacity + white);

src/shared/util.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,12 @@ function MathClamp(v, min, max) {
12351235
return Math.min(Math.max(v, min), max);
12361236
}
12371237

1238-
// TODO: Remove this once the `javascript.options.experimental.math_sumprecise`
1239-
// preference is removed from Firefox.
1240-
if (typeof Math.sumPrecise !== "function") {
1238+
// TODO: Remove this once `Math.sumPrecise` is generally available.
1239+
if (
1240+
(typeof PDFJSDev === "undefined" ||
1241+
PDFJSDev.test("SKIP_BABEL && !MOZCENTRAL")) &&
1242+
typeof Math.sumPrecise !== "function"
1243+
) {
12411244
// Note that this isn't a "proper" polyfill, but since we're only using it to
12421245
// replace `Array.prototype.reduce()` invocations it should be fine.
12431246
Math.sumPrecise = function (numbers) {

0 commit comments

Comments
 (0)