diff --git a/src/core/document.js b/src/core/document.js index b67834c96..1e32007c1 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1182,19 +1182,28 @@ class PDFDocument { } get hasJSActions() { - return shadow( - this, - "hasJSActions", - this.fieldObjects.then(fieldObjects => { - return ( - (fieldObjects !== null && - Object.values(fieldObjects).some(fieldObject => - fieldObject.some(object => object.actions !== null) - )) || - !!this.catalog.jsActions - ); - }) - ); + const promise = this.pdfManager.ensure(this, "_parseHasJSActions"); + return shadow(this, "hasJSActions", promise); + } + + /** + * @private + */ + async _parseHasJSActions() { + const [catalogJsActions, fieldObjects] = await Promise.all([ + this.pdfManager.ensureCatalog("jsActions"), + this.pdfManager.ensure(this, "fieldObjects"), + ]); + + if (catalogJsActions) { + return true; + } + if (fieldObjects) { + return Object.values(fieldObjects).some(fieldObject => + fieldObject.some(object => object.actions !== null) + ); + } + return false; } get calculationOrderIds() { diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index af9a494bf..40958ff9e 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1014,6 +1014,23 @@ describe("api", function () { .catch(done.fail); }); + it("gets hasJSActions, in document without javaScript", async function () { + const hasJSActions = await pdfDocument.hasJSActions(); + + expect(hasJSActions).toEqual(false); + }); + it("gets hasJSActions, in document with javaScript", async function () { + const loadingTask = getDocument( + buildGetDocumentParams("doc_actions.pdf") + ); + const pdfDoc = await loadingTask.promise; + const hasJSActions = await pdfDoc.hasJSActions(); + + expect(hasJSActions).toEqual(true); + + await loadingTask.destroy(); + }); + it("gets JSActions (none)", function (done) { const promise = pdfDocument.getJSActions(); promise