From 1bf4d3391e5ce25890ca06c11e927a4e2f39f548 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 17 Jul 2025 16:26:59 +0200 Subject: [PATCH] LibWeb: Use GC::Ptr for BrowsingContext pointer saved in Document Likely we forgot to update `WeakPtr` to `GC::Ptr` after converting `BrowsingContext` to GC-allocated object. --- Libraries/LibWeb/DOM/Document.cpp | 3 ++- Libraries/LibWeb/DOM/Document.h | 8 ++++---- Libraries/LibWeb/HTML/BarProp.cpp | 2 +- Libraries/LibWeb/HTML/BrowsingContext.h | 3 +-- Libraries/LibWeb/WebDriver/Actions.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index e516ee0c03d..fc82aa5d41c 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -544,6 +544,7 @@ void Document::visit_edges(Cell::Visitor& visitor) visitor.visit(m_inspected_node); visitor.visit(m_highlighted_node); visitor.visit(m_active_favicon); + visitor.visit(m_browsing_context); visitor.visit(m_focused_element); visitor.visit(m_active_element); visitor.visit(m_target_element); @@ -4239,7 +4240,7 @@ GC::Ptr Document::active_parser() return m_parser; } -void Document::set_browsing_context(HTML::BrowsingContext* browsing_context) +void Document::set_browsing_context(GC::Ptr browsing_context) { m_browsing_context = browsing_context; } diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 33429b5729c..cf85c41e419 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -308,10 +308,10 @@ public: String title() const; WebIDL::ExceptionOr set_title(String const&); - HTML::BrowsingContext* browsing_context() { return m_browsing_context.ptr(); } - HTML::BrowsingContext const* browsing_context() const { return m_browsing_context.ptr(); } + GC::Ptr browsing_context() { return m_browsing_context; } + GC::Ptr browsing_context() const { return m_browsing_context; } - void set_browsing_context(HTML::BrowsingContext*); + void set_browsing_context(GC::Ptr); Page& page(); Page const& page() const; @@ -960,7 +960,7 @@ private: OwnPtr m_style_computer; GC::Ptr m_style_sheets; GC::Ptr m_active_favicon; - WeakPtr m_browsing_context; + GC::Ptr m_browsing_context; URL::URL m_url; mutable OwnPtr m_element_by_id; diff --git a/Libraries/LibWeb/HTML/BarProp.cpp b/Libraries/LibWeb/HTML/BarProp.cpp index 19eef99e052..2c5b0266ad7 100644 --- a/Libraries/LibWeb/HTML/BarProp.cpp +++ b/Libraries/LibWeb/HTML/BarProp.cpp @@ -28,7 +28,7 @@ bool BarProp::visible() const { // 1. Let browsingContext be this's relevant global object's browsing context. auto& global_object = HTML::relevant_global_object(*this); - auto* browsing_context = as(global_object).associated_document().browsing_context(); + auto browsing_context = as(global_object).associated_document().browsing_context(); // 2. If browsingContext is null, then return true. if (!browsing_context) { diff --git a/Libraries/LibWeb/HTML/BrowsingContext.h b/Libraries/LibWeb/HTML/BrowsingContext.h index 88445deb35f..466de1f3aa3 100644 --- a/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Libraries/LibWeb/HTML/BrowsingContext.h @@ -16,8 +16,7 @@ namespace Web::HTML { -class BrowsingContext final : public JS::Cell - , public Weakable { +class BrowsingContext final : public JS::Cell { GC_CELL(BrowsingContext, JS::Cell); GC_DECLARE_ALLOCATOR(BrowsingContext); diff --git a/Libraries/LibWeb/WebDriver/Actions.cpp b/Libraries/LibWeb/WebDriver/Actions.cpp index 3eaf69c3463..4e134054a03 100644 --- a/Libraries/LibWeb/WebDriver/Actions.cpp +++ b/Libraries/LibWeb/WebDriver/Actions.cpp @@ -129,7 +129,7 @@ static CSSPixelPoint get_parent_offset(HTML::BrowsingContext const& browsing_con // 4. If parent navigable is not null: if (parent_navigable && parent_navigable->active_document() && parent_navigable->active_document()->browsing_context()) { // 1. Let parent context be parent navigable's document's browsing context. - auto* parent_context = parent_navigable->active_document()->browsing_context(); + auto parent_context = parent_navigable->active_document()->browsing_context(); // 2. Let (parentOffsetLeft, parentOffsetTop) be result of get parent offset of parent context. auto parent_offset = get_parent_offset(*parent_context);