LibWeb: Implement most of "destroy a top-level traversable"

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
This commit is contained in:
Andreas Kling 2022-12-17 10:19:35 +01:00
parent 1b78e0f059
commit 40e7f64433
Notes: sideshowbarker 2024-07-17 02:08:15 +09:00
2 changed files with 29 additions and 0 deletions

View file

@ -508,4 +508,31 @@ void TraversableNavigable::apply_pending_history_changes()
apply_the_history_step(target_step);
}
// https://html.spec.whatwg.org/multipage/document-sequences.html#destroy-a-top-level-traversable
void TraversableNavigable::destroy_top_level_traversable()
{
VERIFY(is_top_level_traversable());
// 1. Let browsingContext be traversable's active browsing context.
auto browsing_context = active_browsing_context();
// 2. For each historyEntry in traversable's session history entries:
for (auto& history_entry : m_session_history_entries) {
// 1. Let document be historyEntry's document.
auto document = history_entry->document_state->document();
// 2. If document is not null, then destroy document.
if (document)
document->destroy();
}
// 3. Remove browsingContext.
browsing_context->remove();
// FIXME: 4. Remove traversable from the user interface (e.g., close or hide its tab in a tabbed browser).
// 5. Remove traversable from the user agent's top-level traversable set.
user_agent_top_level_traversable_set().remove(this);
}
}

View file

@ -45,6 +45,8 @@ public:
void clear_the_forward_session_history();
void traverse_the_history_by_delta(int delta);
void destroy_top_level_traversable();
private:
TraversableNavigable();