From 21d9da0f3b0f43cff7dc8ff0ccbfda76192f6517 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 22 Nov 2023 23:57:34 +0100 Subject: [PATCH] LibWeb: Unregister IntersectionObserver from registration document Before this change, there was some confusion possible where an IO would try to find its way back to the document where we registered it. This led to an assertion failure in the test I'm adding in the next commit, so let's fix this first. IOs now (weakly) remember the document where they are registered, and only unregister from there. --- .../LibWeb/IntersectionObserver/IntersectionObserver.cpp | 8 ++++---- .../LibWeb/IntersectionObserver/IntersectionObserver.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index f9a9c7361c..cc0c6fb8cb 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -53,17 +53,17 @@ IntersectionObserver::IntersectionObserver(JS::Realm& realm, JS::GCPtrdocument().register_intersection_observer({}, *this); + m_document = node->document(); }); + m_document->register_intersection_observer({}, *this); } IntersectionObserver::~IntersectionObserver() = default; void IntersectionObserver::finalize() { - intersection_root().visit([this](auto& node) { - node->document().unregister_intersection_observer({}, *this); - }); + if (m_document) + m_document->unregister_intersection_observer({}, *this); } void IntersectionObserver::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h index 83fbee91c0..a8ce7b333f 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h @@ -83,6 +83,9 @@ private: // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-observationtargets-slot Vector> m_observation_targets; + + // AD-HOC: This is the document where we've registered the IntersectionObserver. + WeakPtr m_document; }; }