From 226d1b4db2d265f946bceb7eb71d05a615f90f93 Mon Sep 17 00:00:00 2001 From: Pierre Le Fevre Date: Thu, 26 Mar 2026 21:52:07 +0100 Subject: [PATCH] Review fixes: add DOM wrapper cache entries as GC roots The node_wrappers identity cache in DomBridge holds GcRef values that were not included in collect_roots(), meaning the GC could collect wrapper objects and break wrapper identity (same DOM node returning different JS objects across calls). Add cached wrappers as GC roots so identity is preserved across garbage collection cycles. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/js/src/vm.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/js/src/vm.rs b/crates/js/src/vm.rs index eee3a41..3bf67be 100644 --- a/crates/js/src/vm.rs +++ b/crates/js/src/vm.rs @@ -1995,6 +1995,13 @@ impl Vm { if let Some(r) = self.promise_prototype { roots.push(r); } + // DOM wrapper identity cache: keep cached wrappers alive so that the + // same DOM node always returns the same JS object. + if let Some(bridge) = &self.dom_bridge { + for &wrapper_ref in bridge.node_wrappers.borrow().values() { + roots.push(wrapper_ref); + } + } roots } -- 2.51.2