diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f9b6e028aa..e3154c4dd3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -2410,6 +2411,39 @@ void Document::discard() // FIXME: 9. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope. } +// https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document +void Document::destroy() +{ + // 1. Destroy the active documents of each of document's descendant navigables. + for (auto navigable : descendant_navigables()) { + if (auto document = navigable->active_document()) + document->destroy(); + } + + // 2. Set document's salvageable state to false. + m_salvageable = false; + + // FIXME: 3. Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications. + + // 4. Abort document. + abort(); + + // 5. Remove any tasks whose document is document from any task queue (without running those tasks). + HTML::main_thread_event_loop().task_queue().remove_tasks_matching([this](auto& task) { + return task.document() == this; + }); + + // 6. Set document's browsing context to null. + m_browsing_context = nullptr; + + // 7. Set document's node navigable's active session history entry's document state's document to null. + navigable()->active_session_history_entry()->document_state->set_document(nullptr); + + // FIXME: 8. Remove document from the owner set of each WorkerGlobalScope object whose set contains document. + + // FIXME: 9. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope. +} + // https://html.spec.whatwg.org/multipage/browsing-the-web.html#abort-a-document void Document::abort() { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index ab75d88fea..24ee0d570e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -448,6 +448,8 @@ public: Vector> descendant_navigables(); Vector> inclusive_descendant_navigables(); + void destroy(); + // https://html.spec.whatwg.org/multipage/window-object.html#discard-a-document void discard();