From 8f9232202fcfa0505d2a3b0738ae5aba0a2abf24 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Mon, 17 Feb 2025 21:53:22 +0100 Subject: [PATCH] [JS] Skip throwing actions It fixes #19505. We were invaliding throwing actions (in setting event.rc to false) and all the event process was stopped. Now we're just dumping the exception in the console: the action is skipped and event.rc is not set else the input fields aren't updated wit KeyStroke actions. --- src/scripting_api/doc.js | 11 +++++++++-- src/scripting_api/event.js | 19 +++--------------- src/scripting_api/field.js | 12 +++++++----- test/integration/scripting_spec.mjs | 29 ++++++++++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue19505.pdf | Bin 0 -> 6528 bytes 6 files changed, 49 insertions(+), 23 deletions(-) create mode 100755 test/pdfs/issue19505.pdf diff --git a/src/scripting_api/doc.js b/src/scripting_api/doc.js index a9cbe90d8..0481f02e5 100644 --- a/src/scripting_api/doc.js +++ b/src/scripting_api/doc.js @@ -175,9 +175,16 @@ class Doc extends PDFObject { _runActions(name) { const actions = this._actions.get(name); - if (actions) { - for (const action of actions) { + if (!actions) { + return; + } + for (const action of actions) { + try { this._globalEval(action); + } catch (error) { + const serializedError = serializeError(error); + serializedError.value = `Error when executing "${name}" for document\n${serializedError.value}`; + this._send(serializedError); } } } diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index 4683f9b8f..f84d76688 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -14,7 +14,6 @@ */ import { - serializeError, USERACTIVATION_CALLBACKID, USERACTIVATION_MAXTIME_VALIDITY, } from "./app_utils.js"; @@ -311,12 +310,7 @@ class EventDispatcher { const source = this._objects[first]; globalThis.event = new Event({}); - try { - this.runCalculate(source, globalThis.event); - } catch (error) { - this._isCalculating = false; - throw error; - } + this.runCalculate(source, globalThis.event); this._isCalculating = false; } @@ -345,15 +339,8 @@ class EventDispatcher { event.value = null; const target = this._objects[targetId]; let savedValue = target.obj._getValue(); - 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; - } + this.runActions(source, target, event, "Calculate"); + if (!event.rc) { continue; } diff --git a/src/scripting_api/field.js b/src/scripting_api/field.js index 0188d4844..e484150aa 100644 --- a/src/scripting_api/field.js +++ b/src/scripting_api/field.js @@ -16,6 +16,7 @@ import { createActionsMap, FieldType, getFieldType } from "./common.js"; import { Color } from "./color.js"; import { PDFObject } from "./pdf_object.js"; +import { serializeError } from "./app_utils.js"; class Field extends PDFObject { constructor(data) { @@ -552,14 +553,15 @@ class Field extends PDFObject { } const actions = this._actions.get(eventName); - try { - for (const action of actions) { + for (const action of actions) { + try { // Action evaluation must happen in the global scope this._globalEval(action); + } catch (error) { + const serializedError = serializeError(error); + serializedError.value = `Error when executing "${eventName}" for field "${this._id}"\n${serializedError.value}`; + this._send(serializedError); } - } catch (error) { - event.rc = false; - throw error; } return true; diff --git a/test/integration/scripting_spec.mjs b/test/integration/scripting_spec.mjs index c8d3f0b14..9ada96fb5 100644 --- a/test/integration/scripting_spec.mjs +++ b/test/integration/scripting_spec.mjs @@ -2528,4 +2528,33 @@ describe("Interaction", () => { ); }); }); + + describe("Skip throwing actions (issue 19505)", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("issue19505.pdf", "[data-annotation-id='24R']"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check that date entered are in the input", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await waitForScripting(page); + + const fieldSelector = getSelector("24R"); + for (const c of "Hello World") { + await page.type(fieldSelector, c); + await waitForSandboxTrip(page); + } + + const value = await page.$eval(fieldSelector, el => el.value); + expect(value).withContext(`In ${browserName}`).toEqual("Hello World"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 71bd89464..d3f822e83 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -704,3 +704,4 @@ !issue19360.pdf !bug1019475_1.pdf !bug1019475_2.pdf +!issue19505.pdf diff --git a/test/pdfs/issue19505.pdf b/test/pdfs/issue19505.pdf new file mode 100755 index 0000000000000000000000000000000000000000..67f1628941dc7818eb9b2c5d2524360220dc89b6 GIT binary patch literal 6528 zcmeHLdsGuw8V`y{(@+(yimp0F1zeNNGm}gV5lBb@i9tkBDVmT>Ad+NaGDv(-@ljvZ zO0Cw4uBEos%CCpnp! z@A>kwa zs0>bmP(nt)srwRIt`+V`&$xwHaC3rvj&FvXxp{f|`(P)N(0FVJM+Z zkjqJwLS#v}CNUu~5mza(qy(9k(jp{*%B2J$OF$CUat)$EwFH%*p)geroZ>Lko@|gf zig6bf24n{U%z)EqM;@CGNl`AESzMwNoWU?G$kO|K0)Pg>WN_weCk;=|pe=A#HVOd{ z00eH9rAjKezx-E*yW&f&m4gh^##s znGBSWl*1DsTn)(g-G>sNi!A}jJWHzQmG9}}s;oJ`edp4xSF`sd zy_Tmg9_HkI^8Tq!Jw82h_mds1uUstJILJUerA@i?a$Q!pY-H~H%%D?^eP~>}VaGe& z+D2`!8S<+>?BK|$Ur-}94J7-$&=UVk+vJ*FE4MAZ^?YgB^hLIu>!apLKl^3F+2_`X zQoiq<)_2%h_r2n_F)>G&oF>JIXyiug#4jwvn+^=wf66&!{er!-`d$01bnLV{e^`KsCPP}J_9tA4(5 zZ|J>Qvv?t4yo$at2|+UBwgx{EkIqcqo*9Wt|0uJ0YwH|m5W$h@HG1T5O2gLpUQl+N z=ukbcU~c}>LHWxoU#y)}vD((sw7PHa)7x^cmEQj?c}4E?k`+ngU#qFBh+Uub@ziIF zirS*O78j})Gv?KORwce0_T8SSugC9=ec@2o+iO2>d;N+>(Np=uTgUbNTk0&EFF)I( zF7AT#Fm!FyxzoSVH+4;=+Y-j#{doVvubW$m7X zt?5&>*HJEOdp>f@?y?mp#rtFWjofuCW9Hn5_m2$wVfLx?n1YcD4_A(u|H41N?lPs| znX1t8X{O61OYYBj??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