mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
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:
parent
57e2b5ef59
commit
21d9da0f3b
Notes:
sideshowbarker
2024-07-17 02:55:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/21d9da0f3b Pull-request: https://github.com/SerenityOS/serenity/pull/22024 Issue: https://github.com/SerenityOS/serenity/issues/22020
@ -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)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user