浏览代码

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.
Timothy Flynn 9 月之前
父节点
当前提交
83be2606db
共有 1 个文件被更改,包括 15 次插入13 次删除
  1. 15 13
      Userland/Libraries/LibWeb/DOM/Document.cpp

+ 15 - 13
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
 // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document
 void Document::destroy()
 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();
     abort();
 
 
-    // 2. Set document's salvageable state to false.
+    // 3. Set document's salvageable state to false.
     m_salvageable = 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();
     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) {
     HTML::main_thread_event_loop().task_queue().remove_tasks_matching([this](auto& task) {
         return task.document() == this;
         return task.document() == this;
     });
     });
 
 
-    // 6. Set document's browsing context to null.
+    // 8. Set document's browsing context to null.
     m_browsing_context = nullptr;
     m_browsing_context = nullptr;
 
 
     // Not in the spec:
     // Not in the spec:
@@ -3332,14 +3336,12 @@ void Document::destroy()
             HTML::all_navigables().remove(navigable_container->content_navigable());
             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);
-    }
-
-    // FIXME: 8. Remove document from the owner set of each WorkerGlobalScope object whose set contains document.
+    // 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: 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
 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#make-document-unsalvageable