mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
fix: Avoid total failure on wasm finalizer call
This commit is contained in:
committed by
Ron Evans
parent
2d17dec7bf
commit
8fe039156b
+16
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user