fix: Avoid total failure on wasm finalizer call

This commit is contained in:
Laurent Demailly
2024-07-20 15:29:52 -07:00
committed by Ron Evans
parent 2d17dec7bf
commit 8fe039156b
+16 -3
View File
@@ -303,9 +303,22 @@
// func finalizeRef(v ref)
"syscall/js.finalizeRef": (v_ref) => {
// Note: TinyGo does not support finalizers so this should never be
// called.
console.error('syscall/js.finalizeRef not implemented');
// Note: TinyGo does not support finalizers so this is only called
// for one specific case, by js.go:jsString. and can/might leak memory.
const id = mem().getUint32(unboxValue(v_ref), true);
// Note that this if is so far seemingly never true. Someone should investigate why.
if (this._goRefCounts?.[id] !== undefined) {
this._goRefCounts[id]--;
if (this._goRefCounts[id] === 0) {
const v = this._values[id];
this._values[id] = null;
this._ids.delete(v);
this._idPool.push(id);
}
} else {
// Log as a hint and reminder that something is probably off.
console.log("syscall/js.finalizeRef: unknown id", id);
}
},
// func stringVal(value string) ref