runtime: implement SetFinalizer to fix syscall/js finalizeRef leak

This commit is contained in:
felipegenef
2026-07-13 00:25:42 -03:00
committed by Ron Evans
parent f1c39e8356
commit 7994d2e912
7 changed files with 450 additions and 1 deletions
+12
View File
@@ -59,6 +59,7 @@ func TestBuild(t *testing.T) {
"cgo/",
"channel.go",
"embed/",
"finalizer.go",
"float.go",
"gc.go",
"generics.go",
@@ -358,6 +359,17 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
continue
}
}
if name == "finalizer.go" && options.Target != "wasm" {
// runtime.SetFinalizer is implemented for the block GC, but the
// test asserts deterministic collection of a dropped object, which
// only holds on the GOOS=js wasm target. The host default GC is
// boehm (SetFinalizer is a no-op there); conservative stack scanning
// on the emulated targets can pin the object; and the wasip2
// component entry lays out the stack differently, so collection is
// not deterministic on those. The feature still works on all of
// them, it just can't be golden-tested for firing.
continue
}
name := name // redefine to avoid race condition
t.Run(name, func(t *testing.T) {