From 29362e6afb36b446d58226a09275a614e0a1e266 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 6 Mar 2026 11:50:24 +0100 Subject: [PATCH 1/2] Remove the `JBig2CCITTFaxWasmImage` instance when running clean-up This follows the same pattern as the existing handling for the `JpxImage` instance. --- src/core/cleanup_helper.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/cleanup_helper.js b/src/core/cleanup_helper.js index 5ada23cf3..966977bc3 100644 --- a/src/core/cleanup_helper.js +++ b/src/core/cleanup_helper.js @@ -16,6 +16,7 @@ import { clearPatternCaches } from "./pattern.js"; import { clearPrimitiveCaches } from "./primitives.js"; import { clearUnicodeCaches } from "./unicode.js"; +import { JBig2CCITTFaxWasmImage } from "./jbig2_ccittFax_wasm.js"; import { JpxImage } from "./jpx.js"; function clearGlobalCaches() { @@ -23,8 +24,9 @@ function clearGlobalCaches() { clearPrimitiveCaches(); clearUnicodeCaches(); - // Remove the global `JpxImage` instance, since it may hold a reference to - // the WebAssembly module. + // Remove the global `JBig2CCITTFaxWasmImage`/`JpxImage` instances, + // since they may hold references to the WebAssembly modules. + JBig2CCITTFaxWasmImage.cleanup(); JpxImage.cleanup(); } From efa13c5e2a8001f70466489ceeee7cb70681dd74 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 6 Mar 2026 11:58:22 +0100 Subject: [PATCH 2/2] Don't duplicate the `Jbig2Error` exception Let `src/core/jbig2_ccittFax_wasm.js` import the existing exception, rather than duplicate its code. --- src/core/jbig2_ccittFax_wasm.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/core/jbig2_ccittFax_wasm.js b/src/core/jbig2_ccittFax_wasm.js index 6a72f98f6..d7340c310 100644 --- a/src/core/jbig2_ccittFax_wasm.js +++ b/src/core/jbig2_ccittFax_wasm.js @@ -13,15 +13,10 @@ * limitations under the License. */ -import { BaseException, warn } from "../shared/util.js"; import { fetchBinaryData } from "./core_utils.js"; import JBig2 from "../../external/jbig2/jbig2.js"; - -class JBig2Error extends BaseException { - constructor(msg) { - super(msg, "Jbig2Error"); - } -} +import { Jbig2Error } from "./jbig2.js"; +import { warn } from "../shared/util.js"; class JBig2CCITTFaxWasmImage { static #buffer = null; @@ -87,7 +82,7 @@ class JBig2CCITTFaxWasmImage { } const module = await this.#modulePromise; if (!module) { - throw new JBig2Error("JBig2 failed to initialize"); + throw new Jbig2Error("JBig2 failed to initialize"); } let ptr, globalsPtr; @@ -118,7 +113,7 @@ class JBig2CCITTFaxWasmImage { module._jbig2_decode(ptr, size, width, height, globalsPtr, globalsSize); } if (!module.imageData) { - throw new JBig2Error("Unknown error"); + throw new Jbig2Error("Unknown error"); } const { imageData } = module; module.imageData = null; @@ -139,4 +134,4 @@ class JBig2CCITTFaxWasmImage { } } -export { JBig2CCITTFaxWasmImage, JBig2Error }; +export { JBig2CCITTFaxWasmImage };