diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 4309608dd23..1cc628f4089 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -50,9 +50,9 @@ WebIDL::ExceptionOr> IntersectionObserver IntersectionObserver::IntersectionObserver(JS::Realm& realm, JS::GCPtr callback, Optional, JS::Handle>> const& root, Vector&& thresholds) : PlatformObject(realm) , m_callback(callback) - , m_root(root) , m_thresholds(move(thresholds)) { + m_root = root.has_value() ? root->visit([](auto& value) -> JS::GCPtr { return *value; }) : nullptr; intersection_root().visit([this](auto& node) { m_document = node->document(); }); @@ -76,6 +76,7 @@ void IntersectionObserver::initialize(JS::Realm& realm) void IntersectionObserver::visit_edges(JS::Cell::Visitor& visitor) { Base::visit_edges(visitor); + visitor.visit(m_root); visitor.visit(m_callback); for (auto& entry : m_queued_entries) visitor.visit(entry); @@ -152,9 +153,13 @@ Vector> IntersectionObserver::take_records Variant, JS::Handle, Empty> IntersectionObserver::root() const { - if (!m_root.has_value()) + if (!m_root) return Empty {}; - return m_root.value(); + if (m_root->is_element()) + return JS::make_handle(static_cast(*m_root)); + if (m_root->is_document()) + return JS::make_handle(static_cast(*m_root)); + VERIFY_NOT_REACHED(); } // https://www.w3.org/TR/intersection-observer/#intersectionobserver-intersection-root @@ -162,8 +167,13 @@ Variant, JS::Handle> IntersectionObserve { // 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(); + if (m_root) { + if (m_root->is_element()) + return JS::make_handle(static_cast(*m_root)); + if (m_root->is_document()) + return JS::make_handle(static_cast(*m_root)); + VERIFY_NOT_REACHED(); + } // 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()); diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h index a8ce7b333fd..72676e9e6fa 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h @@ -73,7 +73,7 @@ private: JS::GCPtr m_callback; // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-root - Optional, JS::Handle>> m_root; + JS::GCPtr m_root; // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-thresholds Vector m_thresholds;