From e82ad79eb91937e1cf70d2a08b9e663dcb92b12b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 5 Jun 2022 15:35:04 +0200 Subject: [PATCH] Conditionally bundle `gulp image_decoders`-specific code in `src/core/jbig2.js` (PR 9729 follow-up) This method/function was added only for the `gulp image_decoders`-builds, and is completely unused elsewhere (e.g. in the Firefox PDF Viewer). While this only reduces the size of the *built* `pdf.worker.js` file by a little over 1 kB, it can't hurt to remove completely unused code from the "normal" builds. --- src/core/jbig2.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/jbig2.js b/src/core/jbig2.js index 0485e050b..0339721cf 100644 --- a/src/core/jbig2.js +++ b/src/core/jbig2.js @@ -1473,8 +1473,7 @@ function processSegment(segment, visitor) { break; default: throw new Jbig2Error( - `segment type ${header.typeName}(${header.type})` + - " is not implemented" + `segment type ${header.typeName}(${header.type}) is not implemented` ); } const callbackName = "on" + header.typeName; @@ -1500,6 +1499,9 @@ function parseJbig2Chunks(chunks) { } function parseJbig2(data) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("IMAGE_DECODERS")) { + throw new Error("Not implemented: parseJbig2"); + } const end = data.length; let position = 0; @@ -2560,6 +2562,9 @@ class Jbig2Image { } parse(data) { + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("IMAGE_DECODERS")) { + throw new Error("Not implemented: Jbig2Image.parse"); + } const { imgData, width, height } = parseJbig2(data); this.width = width; this.height = height;