fix: correctly handle id lookup for finalizeRef call

Modify the ID used for looking up the reference, based on suggestion made by @prochac

Also use console.error in the caase that the reference is not found, since it is now actually
known to be an error.
This commit is contained in:
Ron Evans
2025-02-20 17:55:01 +01:00
parent 8fe039156b
commit 150d9d1c6b
+2 -4
View File
@@ -305,8 +305,7 @@
"syscall/js.finalizeRef": (v_ref) => {
// 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.
const id = v_ref & 0xffffffffn;
if (this._goRefCounts?.[id] !== undefined) {
this._goRefCounts[id]--;
if (this._goRefCounts[id] === 0) {
@@ -316,8 +315,7 @@
this._idPool.push(id);
}
} else {
// Log as a hint and reminder that something is probably off.
console.log("syscall/js.finalizeRef: unknown id", id);
console.error("syscall/js.finalizeRef: unknown id", id);
}
},