mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-09 23:04:02 +02:00
Use Math.sumPrecise in the scripting implementation
This adds a *very basic* non-MOZCENTRAL polyfill for now, which we should be able to remove once the next QuickJS version is released; note the pending changelog at f1139494d1/Changelog (L8)
This commit is contained in:
parent
d34a15e03f
commit
ca428aadae
@ -368,8 +368,8 @@ class AForm {
|
||||
|
||||
AFSimple_Calculate(cFunction, cFields) {
|
||||
const actions = {
|
||||
AVG: args => args.reduce((acc, value) => acc + value, 0) / args.length,
|
||||
SUM: args => args.reduce((acc, value) => acc + value, 0),
|
||||
AVG: args => Math.sumPrecise(args) / args.length,
|
||||
SUM: args => Math.sumPrecise(args),
|
||||
PRD: args => args.reduce((acc, value) => acc * value, 1),
|
||||
MIN: args => Math.min(...args),
|
||||
MAX: args => Math.max(...args),
|
||||
|
||||
@ -26,6 +26,18 @@ function serializeError(error) {
|
||||
return { command: "error", value };
|
||||
}
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
||||
// TODO: Remove this once `Math.sumPrecise` is supported in QuickJS.
|
||||
//
|
||||
// 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.
|
||||
if (typeof Math.sumPrecise !== "function") {
|
||||
Math.sumPrecise = function (numbers) {
|
||||
return numbers.reduce((a, b) => a + b, 0);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
FORMS_VERSION,
|
||||
serializeError,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user