diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 1346d8ecc4a..fc23918ecf1 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -408,6 +408,12 @@ WebIDL::ExceptionOr Document::populate_with_html_head_and_body() return {}; } +void Document::finalize() +{ + Base::finalize(); + page().client().page_did_destroy_document(*this); +} + void Document::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); @@ -3070,8 +3076,6 @@ void Document::run_unloading_cleanup_steps() // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document void Document::destroy() { - page().client().page_did_destroy_document(*this); - // NOTE: Abort needs to happen before destory. There is currently bug in the spec: https://github.com/whatwg/html/issues/9148 // 4. Abort document. abort(); diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index ae7772b9749..b3b1e4be779 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -658,6 +658,7 @@ public: protected: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; + virtual void finalize() override; Document(JS::Realm&, URL::URL const&); diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index eea014edad6..d53dd3bb1a4 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -125,7 +125,6 @@ void PageClient::visit_edges(JS::Cell::Visitor& visitor) { Base::visit_edges(visitor); visitor.visit(m_page); - visitor.visit(m_console_clients); } ConnectionFromClient& PageClient::client() const diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index dda5f8cd6f9..1f2fec96b68 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -195,7 +195,8 @@ private: }; BackingStores m_backing_stores; - HashMap, NonnullOwnPtr> m_console_clients; + // NOTE: These documents are not visited, but manually removed from the map on document finalization. + HashMap, NonnullOwnPtr> m_console_clients; WeakPtr m_top_level_document_console_client; JS::Handle m_console_global_object;