From 7572382c7ac1df33fc3ffbc2d0666387bb08cc11 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 31 Oct 2024 09:25:07 +0100 Subject: [PATCH] Change the "FetchBuiltInCMap"/"FetchStandardFontData" message-handlers to be asynchronous This way we can directly throw Errors, rather than having to "manually" return rejected Promises, which is ever so slightly shorter. Also, since `useWorkerFetch` is always true in MOZCENTRAL builds these message-handlers should not be invoked there. --- src/display/api.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 211c37862..b19a89790 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -2916,29 +2916,31 @@ class WorkerTransport { }); }); - messageHandler.on("FetchBuiltInCMap", data => { + messageHandler.on("FetchBuiltInCMap", async data => { + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { + throw new Error("Not implemented: FetchBuiltInCMap"); + } if (this.destroyed) { - return Promise.reject(new Error("Worker was destroyed.")); + throw new Error("Worker was destroyed."); } if (!this.cMapReaderFactory) { - return Promise.reject( - new Error( - "CMapReaderFactory not initialized, see the `useWorkerFetch` parameter." - ) + throw new Error( + "CMapReaderFactory not initialized, see the `useWorkerFetch` parameter." ); } return this.cMapReaderFactory.fetch(data); }); - messageHandler.on("FetchStandardFontData", data => { + messageHandler.on("FetchStandardFontData", async data => { + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { + throw new Error("Not implemented: FetchStandardFontData"); + } if (this.destroyed) { - return Promise.reject(new Error("Worker was destroyed.")); + throw new Error("Worker was destroyed."); } if (!this.standardFontDataFactory) { - return Promise.reject( - new Error( - "StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter." - ) + throw new Error( + "StandardFontDataFactory not initialized, see the `useWorkerFetch` parameter." ); } return this.standardFontDataFactory.fetch(data);