1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibWeb: Let Document have a direct GCPtr to its containing Web::Page

With this change, Document now always has a Web::Page. This means we no
longer rely on the breakable link between Document and BrowsingContext
to find a relevant Web::Page.

Fixes #22290
This commit is contained in:
Andreas Kling 2023-12-15 13:43:39 +01:00
parent b2b5297997
commit 70193c0009
12 changed files with 35 additions and 10 deletions

View file

@ -236,6 +236,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Document>> Document::create_and_initialize(
// FIXME: Why do we assume `creation_url` is non-empty here? Is this a spec bug?
// FIXME: Why do we assume `top_level_creation_url` is non-empty here? Is this a spec bug?
HTML::WindowEnvironmentSettingsObject::setup(
browsing_context->page(),
creation_url.value(),
move(realm_execution_context),
navigation_params.reserved_environment.visit(
@ -321,6 +322,7 @@ JS::NonnullGCPtr<Document> Document::create(JS::Realm& realm, AK::URL const& url
Document::Document(JS::Realm& realm, const AK::URL& url)
: ParentNode(realm, *this, NodeType::DOCUMENT_NODE)
, m_page(Bindings::host_defined_page(realm))
, m_style_computer(make<CSS::StyleComputer>(*this))
, m_url(url)
{
@ -353,6 +355,7 @@ void Document::initialize(JS::Realm& realm)
void Document::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_page);
visitor.visit(m_window);
visitor.visit(m_layout_root);
visitor.visit(m_style_sheets);
@ -1908,12 +1911,12 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
Page* Document::page()
{
return m_browsing_context ? &m_browsing_context->page() : nullptr;
return m_page;
}
Page const* Document::page() const
{
return m_browsing_context ? &m_browsing_context->page() : nullptr;
return m_page;
}
EventTarget* Document::get_parent(Event const& event)