From 83be2606dba7ac430bab4d61a70e926d12d452ee Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 17 Oct 2024 07:43:34 -0400 Subject: [PATCH] LibWeb: Update spec steps for destroying a DOM document This just updates our copied spec steps - new steps are not implemented here. This is mostly just to highlight new steps we are missing around MessagePorts. No behavior change, but this does resolve an outstanding FIXME around spec step ordering. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 3a69696c545..f7c82f97ab4 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -3308,22 +3308,26 @@ void Document::run_unloading_cleanup_steps() // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document void Document::destroy() { - // NOTE: Abort needs to happen before destory. There is currently bug in the spec: https://github.com/whatwg/html/issues/9148 - // 4. Abort document. + // FIXME: 1. Assert: this is running as part of a task queued on document's relevant agent's event loop. + + // 2. Abort document. abort(); - // 2. Set document's salvageable state to false. + // 3. Set document's salvageable state to false. m_salvageable = false; - // 3. Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications. + // FIXME: 4. Let ports be the list of MessagePorts whose relevant global object's associated Document is document. + // FIXME: 5. For each port in ports, disentangle port. + + // 6. Run any unloading document cleanup steps for document that are defined by this specification and other applicable specifications. run_unloading_cleanup_steps(); - // 5. Remove any tasks whose document is document from any task queue (without running those tasks). + // 7. 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. + // 8. Set document's browsing context to null. m_browsing_context = nullptr; // Not in the spec: @@ -3332,14 +3336,12 @@ void Document::destroy() HTML::all_navigables().remove(navigable_container->content_navigable()); } - // 7. Set document's node navigable's active session history entry's document state's document to null. - if (navigable()) { - navigable()->active_session_history_entry()->document_state()->set_document(nullptr); - } + // 9. Set document's node navigable's active session history entry's document state's document to null. + if (auto navigable = this->navigable()) + 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. + // FIXME: 10. Remove document from the owner set of each WorkerGlobalScope object whose set contains document. + // FIXME: 11. For each workletGlobalScope in document's worklet global scopes, terminate workletGlobalScope. } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#make-document-unsalvageable