From 35623ad52e80809ec0c1c140aec0ce3a13096590 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 26 Sep 2023 16:54:39 +0200 Subject: [PATCH] LibWeb: Visit IntersectionObserverRegistration instead of using Handle This fixes GC-leak caused by JS::Handle preventing an element that owns the handle from being deallocated. --- Userland/Libraries/LibWeb/DOM/Element.cpp | 2 ++ .../LibWeb/IntersectionObserver/IntersectionObserver.cpp | 2 +- .../LibWeb/IntersectionObserver/IntersectionObserver.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 66a8dac55d..164ef4c4dd 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -128,6 +128,8 @@ void Element::visit_edges(Cell::Visitor& visitor) visitor.visit(m_custom_element_definition.ptr()); for (auto& pseudo_element_layout_node : m_pseudo_element_nodes) visitor.visit(pseudo_element_layout_node); + for (auto& registered_intersection_observers : m_registered_intersection_observers) + visitor.visit(registered_intersection_observers.observer); } // https://dom.spec.whatwg.org/#dom-element-getattribute diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 1fd2de8c32..7a66d9c8f1 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -92,7 +92,7 @@ void IntersectionObserver::observe(DOM::Element& target) // property set to observer, a previousThresholdIndex property set to -1, and a previousIsIntersecting // property set to false. auto intersection_observer_registration = IntersectionObserverRegistration { - .observer = JS::make_handle(*this), + .observer = *this, .previous_threshold_index = OptionalNone {}, .previous_is_intersecting = false, }; diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h index 8204476058..9debb0ff7a 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h @@ -23,7 +23,7 @@ struct IntersectionObserverInit { struct IntersectionObserverRegistration { // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverregistration-observer // [A]n observer property holding an IntersectionObserver. - JS::Handle observer; + JS::NonnullGCPtr observer; // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserverregistration-observer // NOTE: Optional is used in place of the spec using -1 to indicate no previous index.