From 2e6e2c3b41c19433f2c8a8b841375524fa1ae96a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 25 Aug 2020 11:25:08 +0200 Subject: [PATCH 1/2] Access the `XRef` data correctly in the "GetStats" handler in `src/core/worker.js` Even though the code obviously works as-is, given that we have unit-tests for it, it still feels incorrect to just *assume* that the `XRef`-instance has all of its properties immediately available. Especially when (almost) all of the other handlers, in `src/core/worker.js`, protect their data accesses with appropriate `pdfManager.ensure` calls. --- src/core/worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/worker.js b/src/core/worker.js index d2c680c53..5fe692bf5 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -507,7 +507,7 @@ class WorkerMessageHandler { }); handler.on("GetStats", function wphSetupGetStats(data) { - return pdfManager.pdfDocument.xref.stats; + return pdfManager.ensureXRef("stats"); }); handler.on("GetAnnotations", function ({ pageIndex, intent }) { From bd16c363cec319e60d1dc5cab0033d1fd0f7e882 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 25 Aug 2020 11:54:23 +0200 Subject: [PATCH 2/2] Access the `Catalog` data correctly in the "GetPageIndex" handler in `src/core/worker.js` Even though the code obviously works as-is, given that we have unit-tests for it, it still feels incorrect to just *assume* that the `Catalog`-instance has all of its properties immediately available. Especially when (almost) all of the other handlers, in `src/core/worker.js`, protect their data accesses with appropriate `pdfManager.ensure` calls. --- src/core/worker.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 5fe692bf5..d11070e6a 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -438,10 +438,9 @@ class WorkerMessageHandler { }); }); - handler.on("GetPageIndex", function wphSetupGetPageIndex(data) { - var ref = Ref.get(data.ref.num, data.ref.gen); - var catalog = pdfManager.pdfDocument.catalog; - return catalog.getPageIndex(ref); + handler.on("GetPageIndex", function wphSetupGetPageIndex({ ref }) { + const pageRef = Ref.get(ref.num, ref.gen); + return pdfManager.ensureCatalog("getPageIndex", [pageRef]); }); handler.on("GetDestinations", function wphSetupGetDestinations(data) {