Skip to content

Commit 8db3a13

Browse files
committed
Don't stop calculating field values when a Calculate callback throws
It fixes #18561.
1 parent c60c0d1 commit 8db3a13

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/scripting_api/event.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
import {
17+
serializeError,
1718
USERACTIVATION_CALLBACKID,
1819
USERACTIVATION_MAXTIME_VALIDITY,
1920
} from "./app_utils.js";
@@ -344,7 +345,15 @@ class EventDispatcher {
344345
event.value = null;
345346
const target = this._objects[targetId];
346347
let savedValue = target.obj._getValue();
347-
this.runActions(source, target, event, "Calculate");
348+
try {
349+
this.runActions(source, target, event, "Calculate");
350+
} catch (error) {
351+
const fieldId = target.obj._id;
352+
const serializedError = serializeError(error);
353+
serializedError.value = `Error when calculating value for field "${fieldId}"\n${serializedError.value}`;
354+
this._externalCall("send", [serializedError]);
355+
continue;
356+
}
348357
if (!event.rc) {
349358
continue;
350359
}

test/integration/scripting_spec.mjs

+38
Original file line numberDiff line numberDiff line change
@@ -2510,4 +2510,42 @@ describe("Interaction", () => {
25102510
);
25112511
});
25122512
});
2513+
2514+
describe("Calculate field value even if one callback throws", () => {
2515+
let pages;
2516+
let otherPages;
2517+
2518+
beforeAll(async () => {
2519+
otherPages = await Promise.all(
2520+
global.integrationSessions.map(async session =>
2521+
session.browser.newPage()
2522+
)
2523+
);
2524+
pages = await loadAndWait("issue18561.pdf", getSelector("24R"));
2525+
});
2526+
2527+
afterAll(async () => {
2528+
await closePages(pages);
2529+
await Promise.all(otherPages.map(page => page.close()));
2530+
});
2531+
2532+
it("must check that the product are null", async () => {
2533+
await Promise.all(
2534+
pages.map(async ([browserName, page], i) => {
2535+
await waitForScripting(page);
2536+
2537+
const inputSelector = getSelector("24R");
2538+
await page.click(inputSelector);
2539+
await page.type(inputSelector, "123");
2540+
await page.click(getSelector("25R"));
2541+
await page.waitForFunction(
2542+
`${getQuerySelector("28R")}.value !== "0"`
2543+
);
2544+
2545+
const text = await page.$eval(getSelector("28R"), el => el.value);
2546+
expect(text).withContext(`In ${browserName}`).toEqual("12300");
2547+
})
2548+
);
2549+
});
2550+
});
25132551
});

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,4 @@
660660
!issue18099_reduced.pdf
661661
!file_pdfjs_test.pdf
662662
!issue18536.pdf
663+
!issue18561.pdf

test/pdfs/issue18561.pdf

6.88 KB
Binary file not shown.

0 commit comments

Comments
 (0)