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.
This commit is contained in:
Andreas Kling 2023-11-22 23:57:34 +01:00
parent 57e2b5ef59
commit 21d9da0f3b
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
2 changed files with 7 additions and 4 deletions

View File

@ -53,17 +53,17 @@ IntersectionObserver::IntersectionObserver(JS::Realm& realm, JS::GCPtr<WebIDL::C
, m_thresholds(move(thresholds))
{
intersection_root().visit([this](auto& node) {
node->document().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)

View File

@ -83,6 +83,9 @@ private:
// https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-observationtargets-slot
Vector<JS::NonnullGCPtr<DOM::Element>> m_observation_targets;
// AD-HOC: This is the document where we've registered the IntersectionObserver.
WeakPtr<DOM::Document> m_document;
};
}