diff --git a/src/core/catalog.js b/src/core/catalog.js index 0a7491a3dc432..368725e95f58e 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -19,7 +19,6 @@ import { DocumentActionEventType, FormatError, info, - objectSize, PermissionFlag, shadow, stringToUTF8String, @@ -1111,7 +1110,7 @@ class Catalog { get openAction() { const obj = this.#catDict.get("OpenAction"); - const openAction = Object.create(null); + const openAction = new Map(); if (obj instanceof Dict) { // Convert the OpenAction dictionary into a format that works with @@ -1123,18 +1122,14 @@ class Catalog { Catalog.parseDestDictionary({ destDict, resultObj }); if (Array.isArray(resultObj.dest)) { - openAction.dest = resultObj.dest; + openAction.set("dest", resultObj.dest); } else if (resultObj.action) { - openAction.action = resultObj.action; + openAction.set("action", resultObj.action); } } else if (isValidExplicitDest(obj)) { - openAction.dest = obj; + openAction.set("dest", obj); } - return shadow( - this, - "openAction", - objectSize(openAction) > 0 ? openAction : null - ); + return shadow(this, "openAction", openAction.size ? openAction : null); } /** diff --git a/src/display/api.js b/src/display/api.js index 7fc4810d80157..a6cfbd4f38c6b 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -829,9 +829,9 @@ class PDFDocumentProxy { } /** - * @returns {Promise} A promise that is resolved with an {Array} - * containing the destination, or `null` when no open action is present - * in the PDF. + * @returns {Promise} A promise that is resolved with a {Map} + * containing a destination or action, or `null` when no open action is + * present in the PDF. */ getOpenAction() { return this._transport.getOpenAction(); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 123beddfbc041..f2be495743d17 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1774,11 +1774,9 @@ describe("api", function () { it("gets non-default open action (with destination)", async function () { const openAction = await pdfDocument.getOpenAction(); - expect(openAction.dest).toEqual([ - { num: 15, gen: 0 }, - { name: "FitH" }, - null, - ]); + expect(openAction).toEqual( + new Map([["dest", [{ num: 15, gen: 0 }, { name: "FitH" }, null]]]) + ); expect(openAction.action).toBeUndefined(); }); @@ -1796,16 +1794,14 @@ describe("api", function () { const promise1 = loadingTask1.promise .then(pdfDoc => pdfDoc.getOpenAction()) .then(function (openAction) { - expect(openAction.dest).toBeUndefined(); - expect(openAction.action).toEqual("Print"); + expect(openAction).toEqual(new Map([["action", "Print"]])); return loadingTask1.destroy(); }); const promise2 = loadingTask2.promise .then(pdfDoc => pdfDoc.getOpenAction()) .then(function (openAction) { - expect(openAction.dest).toBeUndefined(); - expect(openAction.action).toEqual("Print"); + expect(openAction).toEqual(new Map([["action", "Print"]])); return loadingTask2.destroy(); }); diff --git a/web/app.js b/web/app.js index fdf2e20946d02..1042ea5e09581 100644 --- a/web/app.js +++ b/web/app.js @@ -1589,7 +1589,7 @@ const PDFViewerApplication = { this._initializePdfHistory({ fingerprint: pdfDocument.fingerprints[0], viewOnLoad, - initialDest: openAction?.dest, + initialDest: openAction?.get("dest"), }); const initialBookmark = this.initialBookmark; @@ -1788,7 +1788,7 @@ const PDFViewerApplication = { if (pdfDocument !== this.pdfDocument) { return; // The document was closed while the auto print data resolved. } - let triggerAutoPrint = openAction?.action === "Print"; + let triggerAutoPrint = openAction?.get("action") === "Print"; if (jsActions) { console.warn("Warning: JavaScript support is not enabled");