From 06334c97efde3bfb4bb0429268396fb9f1883a97 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 24 May 2024 09:18:19 +0200 Subject: [PATCH] Improve the `loadingParams` functionality in the API - Move the definition of the `loadingParams` Object, to simplify the code. - Add a unit-test, since none existed and the viewer depends on this functionality. --- src/display/api.js | 15 +++++---------- test/unit/api_spec.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index a099e53a91362..fd7ba98cc9f81 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -386,11 +386,13 @@ function getDocument(src) { const transportParams = { disableFontFace, fontExtraProperties, - enableXfa, ownerDocument, - disableAutoFetch, pdfBug, styleElement, + loadingParams: { + disableAutoFetch, + enableXfa, + }, }; worker.promise @@ -2364,6 +2366,7 @@ class WorkerTransport { ownerDocument: params.ownerDocument, styleElement: params.styleElement, }); + this.loadingParams = params.loadingParams; this._params = params; this.canvasFactory = factory.canvasFactory; @@ -3095,14 +3098,6 @@ class WorkerTransport { const refStr = ref.gen === 0 ? `${ref.num}R` : `${ref.num}R${ref.gen}`; return this.#pageRefCache.get(refStr) ?? null; } - - get loadingParams() { - const { disableAutoFetch, enableXfa } = this._params; - return shadow(this, "loadingParams", { - disableAutoFetch, - enableXfa, - }); - } } const INITIAL_DATA = Symbol("INITIAL_DATA"); diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 1aa43aa83fec7..44f9de06b9373 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1069,6 +1069,23 @@ describe("api", function () { await loadingTask.destroy(); }); + it("gets loadingParams", async function () { + const loadingTask = getDocument( + buildGetDocumentParams(basicApiFileName, { + disableAutoFetch: true, + enableXfa: true, + }) + ); + const pdfDoc = await loadingTask.promise; + + expect(pdfDoc.loadingParams).toEqual({ + disableAutoFetch: true, + enableXfa: true, + }); + + await loadingTask.destroy(); + }); + it("gets page", async function () { const data = await pdfDocument.getPage(1); expect(data instanceof PDFPageProxy).toEqual(true);