Skip to content

Commit

Permalink
Merge pull request #18159 from Snuffleupagus/loadingParams-test
Browse files Browse the repository at this point in the history
Improve the `loadingParams` functionality in the API
  • Loading branch information
Snuffleupagus committed May 24, 2024
2 parents 6460e9e + 06334c9 commit 17e09e5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,13 @@ function getDocument(src) {
const transportParams = {
disableFontFace,
fontExtraProperties,
enableXfa,
ownerDocument,
disableAutoFetch,
pdfBug,
styleElement,
loadingParams: {
disableAutoFetch,
enableXfa,
},
};

worker.promise
Expand Down Expand Up @@ -2364,6 +2366,7 @@ class WorkerTransport {
ownerDocument: params.ownerDocument,
styleElement: params.styleElement,
});
this.loadingParams = params.loadingParams;
this._params = params;

this.canvasFactory = factory.canvasFactory;
Expand Down Expand Up @@ -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");
Expand Down
17 changes: 17 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 17e09e5

Please sign in to comment.