mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-03 08:52:54 +00:00
LibWeb: Use HeapFunction directly in SessionHistoryTraversalQueue
This allows us to use HeapFunction all of the way down, allowing us to remove the Handle usage in after_session_callback for create_new_child_navigable.
This commit is contained in:
parent
b6d2ab2332
commit
fc83653f3c
Notes:
github-actions[bot]
2024-08-18 09:16:10 +00:00
Author: https://github.com/shannonbooth
Commit: fc83653f3c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1108
Reviewed-by: https://github.com/awesomekling
8 changed files with 33 additions and 33 deletions
|
@ -1435,7 +1435,7 @@ WebIDL::ExceptionOr<void> Navigable::navigate(NavigateParams params)
|
|||
// set to true and completionSteps set to the following step:
|
||||
populate_session_history_entry_document(history_entry, source_snapshot_params, target_snapshot_params, navigation_id, navigation_params, csp_navigation_type, true, JS::create_heap_function(heap(), [this, history_entry, history_handling, navigation_id] {
|
||||
// 1. Append session history traversal steps to navigable's traversable to finalize a cross-document navigation given navigable, historyHandling, and historyEntry.
|
||||
traversable_navigable()->append_session_history_traversal_steps([this, history_entry, history_handling, navigation_id] {
|
||||
traversable_navigable()->append_session_history_traversal_steps(JS::create_heap_function(heap(), [this, history_entry, history_handling, navigation_id] {
|
||||
if (this->has_been_destroyed()) {
|
||||
// NOTE: This check is not in the spec but we should not continue navigation if navigable has been destroyed.
|
||||
set_delaying_load_events(false);
|
||||
|
@ -1447,7 +1447,7 @@ WebIDL::ExceptionOr<void> Navigable::navigate(NavigateParams params)
|
|||
return;
|
||||
}
|
||||
finalize_a_cross_document_navigation(*this, to_history_handling_behavior(history_handling), history_entry);
|
||||
});
|
||||
}));
|
||||
})).release_value_but_fixme_should_propagate_errors();
|
||||
});
|
||||
|
||||
|
@ -1529,14 +1529,14 @@ WebIDL::ExceptionOr<void> Navigable::navigate_to_a_fragment(URL::URL const& url,
|
|||
auto traversable = traversable_navigable();
|
||||
|
||||
// 17. Append the following session history synchronous navigation steps involving navigable to traversable:
|
||||
traversable->append_session_history_synchronous_navigation_steps(*this, [this, traversable, history_entry, entry_to_replace, navigation_id, history_handling] {
|
||||
traversable->append_session_history_synchronous_navigation_steps(*this, JS::create_heap_function(heap(), [this, traversable, history_entry, entry_to_replace, navigation_id, history_handling] {
|
||||
// 1. Finalize a same-document navigation given traversable, navigable, historyEntry, and entryToReplace.
|
||||
finalize_a_same_document_navigation(*traversable, *this, history_entry, entry_to_replace, history_handling);
|
||||
|
||||
// FIXME: 2. Invoke WebDriver BiDi fragment navigated with navigable's active browsing context and a new WebDriver BiDi
|
||||
// navigation status whose id is navigationId, url is url, and status is "complete".
|
||||
(void)navigation_id;
|
||||
});
|
||||
}));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -1710,9 +1710,9 @@ WebIDL::ExceptionOr<void> Navigable::navigate_to_a_javascript_url(URL::URL const
|
|||
history_entry->set_document_state(document_state);
|
||||
|
||||
// 13. Append session history traversal steps to targetNavigable's traversable to finalize a cross-document navigation with targetNavigable, historyHandling, and historyEntry.
|
||||
traversable_navigable()->append_session_history_traversal_steps([this, history_entry, history_handling, navigation_id] {
|
||||
traversable_navigable()->append_session_history_traversal_steps(JS::create_heap_function(heap(), [this, history_entry, history_handling, navigation_id] {
|
||||
finalize_a_cross_document_navigation(*this, history_handling, history_entry);
|
||||
});
|
||||
}));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -1727,10 +1727,10 @@ void Navigable::reload()
|
|||
auto traversable = traversable_navigable();
|
||||
|
||||
// 3. Append the following session history traversal steps to traversable:
|
||||
traversable->append_session_history_traversal_steps([traversable] {
|
||||
traversable->append_session_history_traversal_steps(JS::create_heap_function(heap(), [traversable] {
|
||||
// 1. Apply the reload history step to traversable.
|
||||
traversable->apply_the_reload_history_step();
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#the-navigation-must-be-a-replace
|
||||
|
@ -1942,10 +1942,10 @@ void perform_url_and_history_update_steps(DOM::Document& document, URL::URL new_
|
|||
auto traversable = navigable->traversable_navigable();
|
||||
|
||||
// 13. Append the following session history synchronous navigation steps involving navigable to traversable:
|
||||
traversable->append_session_history_synchronous_navigation_steps(*navigable, [traversable, navigable, new_entry, entry_to_replace, history_handling] {
|
||||
traversable->append_session_history_synchronous_navigation_steps(*navigable, JS::create_heap_function(document.realm().heap(), [traversable, navigable, new_entry, entry_to_replace, history_handling] {
|
||||
// 1. Finalize a same-document navigation given traversable, navigable, newEntry, and entryToReplace.
|
||||
finalize_a_same_document_navigation(*traversable, *navigable, new_entry, entry_to_replace, history_handling);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
void Navigable::scroll_offset_did_change()
|
||||
|
|
|
@ -59,7 +59,7 @@ JS::GCPtr<NavigableContainer> NavigableContainer::navigable_container_with_conte
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#create-a-new-child-navigable
|
||||
WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable(JS::Handle<JS::HeapFunction<void()>> after_session_history_update)
|
||||
WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable(JS::GCPtr<JS::HeapFunction<void()>> after_session_history_update)
|
||||
{
|
||||
// 1. Let parentNavigable be element's node navigable.
|
||||
auto parent_navigable = navigable();
|
||||
|
@ -110,7 +110,7 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable(JS::Han
|
|||
auto traversable = parent_navigable->traversable_navigable();
|
||||
|
||||
// 12. Append the following session history traversal steps to traversable:
|
||||
traversable->append_session_history_traversal_steps([traversable, navigable, parent_navigable, history_entry, after_session_history_update = move(after_session_history_update)] {
|
||||
traversable->append_session_history_traversal_steps(JS::create_heap_function(heap(), [traversable, navigable, parent_navigable, history_entry, after_session_history_update] {
|
||||
// 1. Let parentDocState be parentNavigable's active session history entry's document state.
|
||||
auto parent_doc_state = parent_navigable->active_session_history_entry()->document_state();
|
||||
|
||||
|
@ -140,7 +140,7 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable(JS::Han
|
|||
if (after_session_history_update) {
|
||||
after_session_history_update->function()();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -294,10 +294,10 @@ void NavigableContainer::destroy_the_child_navigable()
|
|||
auto traversable = this->navigable()->traversable_navigable();
|
||||
|
||||
// 9. Append the following session history traversal steps to traversable:
|
||||
traversable->append_session_history_traversal_steps([traversable] {
|
||||
traversable->append_session_history_traversal_steps(JS::create_heap_function(heap(), [traversable] {
|
||||
// 1. Update for navigable creation/destruction given traversable.
|
||||
traversable->update_for_navigable_creation_or_destruction();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ protected:
|
|||
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
|
||||
void navigate_an_iframe_or_frame(URL::URL url, ReferrerPolicy::ReferrerPolicy referrer_policy, Optional<String> srcdoc_string = {});
|
||||
|
||||
WebIDL::ExceptionOr<void> create_new_child_navigable(JS::Handle<JS::HeapFunction<void()>> after_session_history_update = {});
|
||||
WebIDL::ExceptionOr<void> create_new_child_navigable(JS::GCPtr<JS::HeapFunction<void()>> after_session_history_update = {});
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
|
||||
JS::GCPtr<Navigable> m_content_navigable { nullptr };
|
||||
|
|
|
@ -665,7 +665,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
|
|||
auto source_snapshot_params = document.snapshot_source_snapshot_params();
|
||||
|
||||
// 12. Append the following session history traversal steps to traversable:
|
||||
traversable->append_session_history_traversal_steps([key, api_method_tracker, navigable, source_snapshot_params, traversable, this] {
|
||||
traversable->append_session_history_traversal_steps(JS::create_heap_function(heap(), [key, api_method_tracker, navigable, source_snapshot_params, traversable, this] {
|
||||
// 1. Let navigableSHEs be the result of getting session history entries given navigable.
|
||||
auto navigable_shes = navigable->get_session_history_entries();
|
||||
|
||||
|
@ -727,7 +727,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
|
|||
reject_the_finished_promise(api_method_tracker, WebIDL::SecurityError::create(realm, "Navigation disallowed from this origin"_fly_string));
|
||||
}));
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// 13. Return a navigation API method tracker-derived result for apiMethodTracker.
|
||||
return navigation_api_method_tracker_derived_result(api_method_tracker);
|
||||
|
|
|
@ -12,9 +12,9 @@ namespace Web::HTML {
|
|||
JS_DEFINE_ALLOCATOR(SessionHistoryTraversalQueue);
|
||||
JS_DEFINE_ALLOCATOR(SessionHistoryTraversalQueueEntry);
|
||||
|
||||
JS::NonnullGCPtr<SessionHistoryTraversalQueueEntry> SessionHistoryTraversalQueueEntry::create(JS::VM& vm, Function<void()> steps, JS::GCPtr<HTML::Navigable> target_navigable)
|
||||
JS::NonnullGCPtr<SessionHistoryTraversalQueueEntry> SessionHistoryTraversalQueueEntry::create(JS::VM& vm, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps, JS::GCPtr<HTML::Navigable> target_navigable)
|
||||
{
|
||||
return vm.heap().allocate_without_realm<SessionHistoryTraversalQueueEntry>(JS::create_heap_function(vm.heap(), move(steps)), target_navigable);
|
||||
return vm.heap().allocate_without_realm<SessionHistoryTraversalQueueEntry>(steps, target_navigable);
|
||||
}
|
||||
|
||||
void SessionHistoryTraversalQueueEntry::visit_edges(JS::Cell::Visitor& visitor)
|
||||
|
@ -46,17 +46,17 @@ void SessionHistoryTraversalQueue::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_queue);
|
||||
}
|
||||
|
||||
void SessionHistoryTraversalQueue::append(Function<void()> steps)
|
||||
void SessionHistoryTraversalQueue::append(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
m_queue.append(SessionHistoryTraversalQueueEntry::create(vm(), move(steps), nullptr));
|
||||
m_queue.append(SessionHistoryTraversalQueueEntry::create(vm(), steps, nullptr));
|
||||
if (!m_timer->is_active()) {
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void SessionHistoryTraversalQueue::append_sync(Function<void()> steps, JS::GCPtr<Navigable> target_navigable)
|
||||
void SessionHistoryTraversalQueue::append_sync(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps, JS::GCPtr<Navigable> target_navigable)
|
||||
{
|
||||
m_queue.append(SessionHistoryTraversalQueueEntry::create(vm(), move(steps), target_navigable));
|
||||
m_queue.append(SessionHistoryTraversalQueueEntry::create(vm(), steps, target_navigable));
|
||||
if (!m_timer->is_active()) {
|
||||
m_timer->start();
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ struct SessionHistoryTraversalQueueEntry : public JS::Cell {
|
|||
JS_DECLARE_ALLOCATOR(SessionHistoryTraversalQueueEntry);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<SessionHistoryTraversalQueueEntry> create(JS::VM& vm, Function<void()> steps, JS::GCPtr<HTML::Navigable> target_navigable);
|
||||
static JS::NonnullGCPtr<SessionHistoryTraversalQueueEntry> create(JS::VM& vm, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps, JS::GCPtr<HTML::Navigable> target_navigable);
|
||||
|
||||
JS::GCPtr<HTML::Navigable> target_navigable() const { return m_target_navigable; }
|
||||
void execute_steps() const { m_steps->function()(); }
|
||||
|
@ -49,8 +49,8 @@ class SessionHistoryTraversalQueue : public JS::Cell {
|
|||
public:
|
||||
SessionHistoryTraversalQueue();
|
||||
|
||||
void append(Function<void()> steps);
|
||||
void append_sync(Function<void()> steps, JS::GCPtr<Navigable> target_navigable);
|
||||
void append(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps);
|
||||
void append_sync(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps, JS::GCPtr<Navigable> target_navigable);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#sync-navigations-jump-queue
|
||||
JS::GCPtr<SessionHistoryTraversalQueueEntry> first_synchronous_navigation_steps_with_target_navigable_not_contained_in(HashTable<JS::NonnullGCPtr<Navigable>> const&);
|
||||
|
|
|
@ -971,7 +971,7 @@ void TraversableNavigable::traverse_the_history_by_delta(int delta, Optional<DOM
|
|||
}
|
||||
|
||||
// 4. Append the following session history traversal steps to traversable:
|
||||
append_session_history_traversal_steps([this, delta, source_snapshot_params = move(source_snapshot_params), initiator_to_check, user_involvement] {
|
||||
append_session_history_traversal_steps(JS::create_heap_function(heap(), [this, delta, source_snapshot_params = move(source_snapshot_params), initiator_to_check, user_involvement] {
|
||||
// 1. Let allSteps be the result of getting all used history steps for traversable.
|
||||
auto all_steps = get_all_used_history_steps();
|
||||
|
||||
|
@ -989,7 +989,7 @@ void TraversableNavigable::traverse_the_history_by_delta(int delta, Optional<DOM
|
|||
// 5. Apply the traverse history step allSteps[targetStepIndex] to traversable, given sourceSnapshotParams,
|
||||
// initiatorToCheck, and userInvolvement.
|
||||
apply_the_traverse_history_step(all_steps[target_step_index], source_snapshot_params, initiator_to_check, user_involvement);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-for-navigable-creation/destruction
|
||||
|
|
|
@ -80,14 +80,14 @@ public:
|
|||
void close_top_level_traversable();
|
||||
void destroy_top_level_traversable();
|
||||
|
||||
void append_session_history_traversal_steps(ESCAPING Function<void()> steps)
|
||||
void append_session_history_traversal_steps(JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
m_session_history_traversal_queue->append(move(steps));
|
||||
m_session_history_traversal_queue->append(steps);
|
||||
}
|
||||
|
||||
void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, ESCAPING Function<void()> steps)
|
||||
void append_session_history_synchronous_navigation_steps(JS::NonnullGCPtr<Navigable> target_navigable, JS::NonnullGCPtr<JS::HeapFunction<void()>> steps)
|
||||
{
|
||||
m_session_history_traversal_queue->append_sync(move(steps), target_navigable);
|
||||
m_session_history_traversal_queue->append_sync(steps, target_navigable);
|
||||
}
|
||||
|
||||
String window_handle() const { return m_window_handle; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue