test: keep objects alive in finalization fixtures

process.finalization only holds weak references to registered objects.
In unregister-function.mjs and finalization-cleanup.mjs the registered
objects were not captured by any closure, so a GC before exit could
collect them, skipping their exit callbacks and failing the assertions.
Reference them from the exit listeners so they stay reachable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DQrzezHzwzfCYeh2cYm2U
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66869
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Matteo CollinaandClaude Opus 5.5 authored and GitHub committed 2026-10-22 04:26:20 +00:00
1 parent e0619bb7e3
commit fd20448111
2 files changed
+5

No files matched your search

+2
View File
@@ -30,5 +30,7 @@ for (let i = 0; i < 10; i++) {
}
process.on('exit', function () {
// Keep `first` and `third` alive until exit; registrations only hold them weakly.
deepStrictEqual(keptAlive.map((obj) => obj.name), ['first', 'third'])
deepStrictEqual(finalized, ['first', 'third'])
})
+3
View File
@@ -25,5 +25,8 @@ unregisterABeforeExit()
unregisterBAgain()
process.on('exit', function () {
// Keep `a` and `b` alive until exit; registrations only hold them weakly.
strictEqual(a.name, 'a')
strictEqual(b.name, 'b')
strictEqual(calls.join(','), 'b:exit')
})