remove ranges from live list on GC finalization

Add a weak finalizer to Range that removes its linked list node from
Page._live_ranges when V8 garbage-collects the JS Range object. This
prevents the list from growing unboundedly and avoids iterating over
stale entries during mutation updates.
This commit is contained in:
egrs
2026-03-11 07:27:39 +01:00
parent d2c55da6c9
commit 625d424199

View File

@@ -680,6 +680,10 @@ fn getContainerElement(self: *const Range) ?*Node.Element {
return parent.is(Node.Element);
}
pub fn deinit(self: *Range, _: bool, page: *Page) void {
page._live_ranges.remove(&self._proto._range_link);
}
pub const JsApi = struct {
pub const bridge = js.Bridge(Range);
@@ -687,6 +691,8 @@ pub const JsApi = struct {
pub const name = "Range";
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
pub const weak = true;
pub const finalizer = bridge.finalizer(Range.deinit);
};
// Constants for compareBoundaryPoints