Merge pull request #20818 from Snuffleupagus/JBig2-fixes

A couple of small JBig2 fixes
This commit is contained in:
Jonas Jenwald 2026-03-06 16:04:03 +01:00 committed by GitHub
commit d9b81b5199
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 12 deletions

View File

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

View File

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