Merge pull request #20148 from fnlctrl/icc-lazy-finalization-registry

Lazy initialize FinalizationRegistry used by IccColorSpace.#finalizer
This commit is contained in:
calixteman 2025-08-06 11:24:40 +02:00 committed by GitHub
commit d41f144716
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,9 +48,7 @@ class IccColorSpace extends ColorSpace {
static #wasmUrl = null; static #wasmUrl = null;
static #finalizer = new FinalizationRegistry(transformer => { static #finalizer = null;
qcms_drop_transformer(transformer);
});
constructor(iccProfile, name, numComps) { constructor(iccProfile, name, numComps) {
if (!IccColorSpace.isUsable) { if (!IccColorSpace.isUsable) {
@ -100,6 +98,9 @@ class IccColorSpace extends ColorSpace {
if (!this.#transformer) { if (!this.#transformer) {
throw new Error("Failed to create ICC color space"); throw new Error("Failed to create ICC color space");
} }
IccColorSpace.#finalizer ||= new FinalizationRegistry(transformer => {
qcms_drop_transformer(transformer);
});
IccColorSpace.#finalizer.register(this, this.#transformer); IccColorSpace.#finalizer.register(this, this.#transformer);
} }