From ef809eea1e7412426679e95db2daab5acf0344fb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 23 Nov 2023 00:01:26 +0100 Subject: [PATCH] LibWeb: Don't assume IO.unobserve() called on observed element It's perfectly possible for JavaScript to call unobserve() on an element that hasn't been observed. Let's stop asserting if that happens. :^) Fixes #22020 --- .../unobserve-element-without-matching-observe.txt | 1 + .../unobserve-element-without-matching-observe.html | 10 ++++++++++ Userland/Libraries/LibWeb/DOM/Element.cpp | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/IntersectionObserver/unobserve-element-without-matching-observe.txt create mode 100644 Tests/LibWeb/Text/input/IntersectionObserver/unobserve-element-without-matching-observe.html diff --git a/Tests/LibWeb/Text/expected/IntersectionObserver/unobserve-element-without-matching-observe.txt b/Tests/LibWeb/Text/expected/IntersectionObserver/unobserve-element-without-matching-observe.txt new file mode 100644 index 0000000000..be36d109cd --- /dev/null +++ b/Tests/LibWeb/Text/expected/IntersectionObserver/unobserve-element-without-matching-observe.txt @@ -0,0 +1 @@ + PASS! (Didn't crash) diff --git a/Tests/LibWeb/Text/input/IntersectionObserver/unobserve-element-without-matching-observe.html b/Tests/LibWeb/Text/input/IntersectionObserver/unobserve-element-without-matching-observe.html new file mode 100644 index 0000000000..39b64052a6 --- /dev/null +++ b/Tests/LibWeb/Text/input/IntersectionObserver/unobserve-element-without-matching-observe.html @@ -0,0 +1,10 @@ + + + diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index e77ee1be16..7d62a0b592 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -2086,7 +2086,8 @@ void Element::register_intersection_observer(Badge, JS::NonnullGCPtr observer) { - VERIFY(m_registered_intersection_observers); + if (!m_registered_intersection_observers) + return; m_registered_intersection_observers->remove_first_matching([&observer](IntersectionObserver::IntersectionObserverRegistration const& entry) { return entry.observer == observer; });