diff --git a/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt b/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt new file mode 100644 index 0000000000..af663e86b6 --- /dev/null +++ b/Tests/LibWeb/Text/expected/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.txt @@ -0,0 +1 @@ + PASS if we didn't crash! diff --git a/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html b/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html new file mode 100644 index 0000000000..417a1d3136 --- /dev/null +++ b/Tests/LibWeb/Text/input/IntersectionObserver/implicit-root-after-originating-iframe-is-removed-from-dom.html @@ -0,0 +1,17 @@ + + + + + diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 29d29c6f0d..28e4c73367 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace Web::IntersectionObserver { @@ -156,11 +157,16 @@ Variant, JS::Handle, Empty> Intersection return m_root.value(); } +// https://www.w3.org/TR/intersection-observer/#intersectionobserver-intersection-root Variant, JS::Handle> IntersectionObserver::intersection_root() const { - if (!m_root.has_value()) - return JS::make_handle(global_object().navigable()->traversable_navigable()->active_document()); - return m_root.value(); + // The intersection root for an IntersectionObserver is the value of its root attribute + // if the attribute is non-null; + if (m_root.has_value()) + return m_root.value(); + + // otherwise, it is the top-level browsing context’s document node, referred to as the implicit root. + return JS::make_handle(global_object().page().top_level_browsing_context().active_document()); } // https://www.w3.org/TR/intersection-observer/#intersectionobserver-root-intersection-rectangle