From 150d9d1c6bf04fd635916c35b9f5f4db24af8eb9 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Thu, 20 Feb 2025 17:55:01 +0100 Subject: [PATCH] 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. --- targets/wasm_exec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/targets/wasm_exec.js b/targets/wasm_exec.js index e30f3256f..e61fa52ff 100644 --- a/targets/wasm_exec.js +++ b/targets/wasm_exec.js @@ -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); } },