Skip to content

Commit

Permalink
Don't stop calculating field values when a Calculate callback throws
Browse files Browse the repository at this point in the history
It fixes #18561.
  • Loading branch information
calixteman committed Aug 5, 2024
1 parent c60c0d1 commit 8db3a13
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/scripting_api/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

import {
serializeError,
USERACTIVATION_CALLBACKID,
USERACTIVATION_MAXTIME_VALIDITY,
} from "./app_utils.js";
Expand Down Expand Up @@ -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;
}
Expand Down
38 changes: 38 additions & 0 deletions test/integration/scripting_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,4 +2510,42 @@ describe("Interaction", () => {
);
});
});

describe("Calculate field value even if one callback throws", () => {
let pages;
let otherPages;

beforeAll(async () => {
otherPages = await Promise.all(
global.integrationSessions.map(async session =>
session.browser.newPage()
)
);
pages = await loadAndWait("issue18561.pdf", getSelector("24R"));
});

afterAll(async () => {
await closePages(pages);
await Promise.all(otherPages.map(page => page.close()));
});

it("must check that the product are null", 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 !== "0"`
);

const text = await page.$eval(getSelector("28R"), el => el.value);
expect(text).withContext(`In ${browserName}`).toEqual("12300");
})
);
});
});
});
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,4 @@
!issue18099_reduced.pdf
!file_pdfjs_test.pdf
!issue18536.pdf
!issue18561.pdf
Binary file added test/pdfs/issue18561.pdf
Binary file not shown.

0 comments on commit 8db3a13

Please sign in to comment.