1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 08:38:06 +02:00

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.
This commit is contained in:
Jonas Jenwald 2024-10-31 09:25:07 +01:00
parent f013c39b9f
commit 7572382c7a

View file

@ -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);