1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibWeb: Implement get_the_history_object_length_and_index()

This commit is contained in:
Aliaksandr Kalenik 2023-04-13 10:18:46 +03:00 committed by Andreas Kling
parent 09cb266cb8
commit 5b06e43938
2 changed files with 28 additions and 0 deletions

View file

@ -149,6 +149,28 @@ Vector<int> TraversableNavigable::get_all_used_history_steps() const
return sorted_steps;
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-the-history-object-length-and-index
TraversableNavigable::HistoryObjectLengthAndIndex TraversableNavigable::get_the_history_object_length_and_index(int step) const
{
// 1. Let steps be the result of getting all used history steps within traversable.
auto steps = get_all_used_history_steps();
// 2. Let scriptHistoryLength be the size of steps.
auto script_history_length = steps.size();
// 3. Assert: steps contains step.
VERIFY(steps.contains_slow(step));
// 4. Let scriptHistoryIndex be the index of step in steps.
auto script_history_index = *steps.find_first_index(step);
// 5. Return (scriptHistoryLength, scriptHistoryIndex).
return HistoryObjectLengthAndIndex {
.script_history_length = script_history_length,
.script_history_index = script_history_index
};
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
void TraversableNavigable::clear_the_forward_session_history()
{