diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index 2df21a923..4683f9b8f 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -14,6 +14,7 @@ */ import { + serializeError, USERACTIVATION_CALLBACKID, USERACTIVATION_MAXTIME_VALIDITY, } from "./app_utils.js"; @@ -344,7 +345,15 @@ class EventDispatcher { event.value = null; const target = this._objects[targetId]; let savedValue = target.obj._getValue(); - this.runActions(source, target, event, "Calculate"); + try { + this.runActions(source, target, event, "Calculate"); + } catch (error) { + const fieldId = target.obj._id; + const serializedError = serializeError(error); + serializedError.value = `Error when calculating value for field "${fieldId}"\n${serializedError.value}`; + this._externalCall("send", [serializedError]); + continue; + } if (!event.rc) { continue; } diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index 72720058a..8b0a6002f 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2461,4 +2461,32 @@ describe("Interaction", () => { ); }); }); + + describe("Calculate field value even if one callback throws", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue18561.pdf", getSelector("24R")); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that the product is computed although a callback threw", async () => { + await Promise.all( + pages.map(async ([browserName, page], i) => { + await waitForScripting(page); + + const inputSelector = getSelector("24R"); + await page.click(inputSelector); + await page.type(inputSelector, "123"); + await page.click(getSelector("25R")); + await page.waitForFunction( + `${getQuerySelector("28R")}.value === "12300"` + ); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index b353f8d31..af276cad1 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -660,3 +660,4 @@ !issue18099_reduced.pdf !file_pdfjs_test.pdf !issue18536.pdf +!issue18561.pdf diff --git a/test/pdfs/issue18561.pdf b/test/pdfs/issue18561.pdf new file mode 100755 index 000000000..2965cdcaa Binary files /dev/null and b/test/pdfs/issue18561.pdf differ