From 4be29653045d6a98b3ac71087e967a9cd65d3d08 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 8 Nov 2024 11:06:33 +0000 Subject: [PATCH] LibWeb: Match spec changes to "apply the history step" Corresponds to https://github.com/whatwg/html/pull/10704 Also a tiny formatting change because the commit hook demands it. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Document.h | 2 +- .../LibWeb/HTML/TraversableNavigable.cpp | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 00102526c3613..1ce87400dfe45 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -4386,7 +4386,7 @@ void Document::restore_the_history_object_state(JS::NonnullGCPtr entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api, Optional> previous_entry_for_activation, bool update_navigation_api) +void Document::update_for_history_step_application(JS::NonnullGCPtr entry, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api, JS::GCPtr previous_entry_for_activation, bool update_navigation_api) { (void)previous_entry_for_activation; diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index eb1b29509bd8e..8528c37572ea5 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -614,7 +614,7 @@ class Document HTML::SourceSnapshotParams snapshot_source_snapshot_params() const; - void update_for_history_step_application(JS::NonnullGCPtr, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api = {}, Optional> previous_entry_for_activation = {}, bool update_navigation_api = true); + void update_for_history_step_application(JS::NonnullGCPtr, bool do_not_reactivate, size_t script_history_length, size_t script_history_index, Optional navigation_type, Optional>> entries_for_navigation_api = {}, JS::GCPtr previous_entry_for_activation = {}, bool update_navigation_api = true); HashMap>& shared_resource_requests(); diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index f893dff1411bb..1620f0f2ca6fe 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -688,8 +688,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // that is synchronous navigation steps with a target navigable not contained in navigablesThatMustWaitBeforeHandlingSyncNavigation. // 2. Remove steps from traversable's session history traversal queue's algorithm set. for (auto entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation); - entry; - entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation)) { + entry; + entry = m_session_history_traversal_queue->first_synchronous_navigation_steps_with_target_navigable_not_contained_in(navigables_that_must_wait_before_handling_sync_navigation)) { // 3. Set traversable's running nested apply history step to true. m_running_nested_apply_history_step = true; @@ -735,6 +735,8 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // 9. Let entriesForNavigationAPI be the result of getting session history entries for the navigation API given navigable and targetStep. auto entries_for_navigation_api = get_session_history_entries_for_the_navigation_api(*navigable, target_step); + // NOTE: Steps 10 and 11 come after step 12. + // 12. In both cases, let afterPotentialUnloads be the following steps: bool const update_only = changing_navigable_continuation->update_only; JS::GCPtr const target_entry = changing_navigable_continuation->target_entry; @@ -746,15 +748,18 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ target_entry->set_classic_history_api_state(populated_target_entry->classic_history_api_state()); } - // 1. If changingNavigableContinuation's update-only is false, then activate history entry targetEntry for navigable. + // 1. Let previousEntry be navigable's active session history entry. + JS::GCPtr const previous_entry = navigable->active_session_history_entry(); + + // 2. If changingNavigableContinuation's update-only is false, then activate history entry targetEntry for navigable. if (!update_only) navigable->activate_history_entry(*target_entry); - // 2. Let updateDocument be an algorithm step which performs update document for history step application given + // 3. Let updateDocument be an algorithm step which performs update document for history step application given // targetEntry's document, targetEntry, changingNavigableContinuation's update-only, scriptHistoryLength, - // scriptHistoryIndex, navigationType, entriesForNavigationAPI, and displayedEntry. - auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only, navigation_type] { - target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, navigation_type, entries_for_navigation_api); + // scriptHistoryIndex, navigationType, entriesForNavigationAPI, and previousEntry. + auto update_document = [script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), target_entry, update_only, navigation_type, previous_entry] { + target_entry->document()->update_for_history_step_application(*target_entry, update_only, script_history_length, script_history_index, navigation_type, entries_for_navigation_api, previous_entry); }; // 3. If targetEntry's document is equal to displayedDocument, then perform updateDocument.