Skip to content

Commit

Permalink
LibWeb: Visit IntersectionObserverRegistration instead of using Handle
Browse files Browse the repository at this point in the history
This fixes GC-leak caused by JS::Handle<IntersectionObserverver>
preventing an element that owns the handle from being deallocated.
  • Loading branch information
kalenikaliaksandr authored and awesomekling committed Sep 26, 2023
1 parent ac5c470 commit 35623ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/DOM/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntersectionObserver> observer;
JS::NonnullGCPtr<IntersectionObserver> 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.
Expand Down

0 comments on commit 35623ad

Please sign in to comment.