Procházet zdrojové kódy

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.
Shannon Booth před 10 měsíci
rodič
revize
fc83653f3c

+ 10 - 10
Userland/Libraries/LibWeb/HTML/Navigable.cpp

@@ -1435,7 +1435,7 @@ WebIDL::ExceptionOr<void> Navigable::navigate(NavigateParams params)
         //     set to true and completionSteps set to the following step:
         //     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] {
         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.
             // 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()) {
                 if (this->has_been_destroyed()) {
                     // NOTE: This check is not in the spec but we should not continue navigation if navigable 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);
                     set_delaying_load_events(false);
@@ -1447,7 +1447,7 @@ WebIDL::ExceptionOr<void> Navigable::navigate(NavigateParams params)
                     return;
                     return;
                 }
                 }
                 finalize_a_cross_document_navigation(*this, to_history_handling_behavior(history_handling), history_entry);
                 finalize_a_cross_document_navigation(*this, to_history_handling_behavior(history_handling), history_entry);
-            });
+            }));
         })).release_value_but_fixme_should_propagate_errors();
         })).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();
     auto traversable = traversable_navigable();
 
 
     // 17. Append the following session history synchronous navigation steps involving navigable to traversable:
     // 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.
         // 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);
         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
         // 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".
         //            navigation status whose id is navigationId, url is url, and status is "complete".
         (void)navigation_id;
         (void)navigation_id;
-    });
+    }));
 
 
     return {};
     return {};
 }
 }
@@ -1710,9 +1710,9 @@ WebIDL::ExceptionOr<void> Navigable::navigate_to_a_javascript_url(URL::URL const
     history_entry->set_document_state(document_state);
     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.
     // 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);
         finalize_a_cross_document_navigation(*this, history_handling, history_entry);
-    });
+    }));
 
 
     return {};
     return {};
 }
 }
@@ -1727,10 +1727,10 @@ void Navigable::reload()
     auto traversable = traversable_navigable();
     auto traversable = traversable_navigable();
 
 
     // 3. Append the following session history traversal steps to traversable:
     // 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.
         // 1. Apply the reload history step to traversable.
         traversable->apply_the_reload_history_step();
         traversable->apply_the_reload_history_step();
-    });
+    }));
 }
 }
 
 
 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#the-navigation-must-be-a-replace
 // 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();
     auto traversable = navigable->traversable_navigable();
 
 
     // 13. Append the following session history synchronous navigation steps involving navigable to traversable:
     // 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.
         // 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);
         finalize_a_same_document_navigation(*traversable, *navigable, new_entry, entry_to_replace, history_handling);
-    });
+    }));
 }
 }
 
 
 void Navigable::scroll_offset_did_change()
 void Navigable::scroll_offset_did_change()

+ 5 - 5
Userland/Libraries/LibWeb/HTML/NavigableContainer.cpp

@@ -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
 // 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.
     // 1. Let parentNavigable be element's node navigable.
     auto parent_navigable = 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();
     auto traversable = parent_navigable->traversable_navigable();
 
 
     // 12. Append the following session history traversal steps to traversable:
     // 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.
         // 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();
         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) {
         if (after_session_history_update) {
             after_session_history_update->function()();
             after_session_history_update->function()();
         }
         }
-    });
+    }));
 
 
     return {};
     return {};
 }
 }
@@ -294,10 +294,10 @@ void NavigableContainer::destroy_the_child_navigable()
         auto traversable = this->navigable()->traversable_navigable();
         auto traversable = this->navigable()->traversable_navigable();
 
 
         // 9. Append the following session history traversal steps to traversable:
         // 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.
             // 1. Update for navigable creation/destruction given traversable.
             traversable->update_for_navigable_creation_or_destruction();
             traversable->update_for_navigable_creation_or_destruction();
-        });
+        }));
     }));
     }));
 }
 }
 
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/NavigableContainer.h

@@ -64,7 +64,7 @@ protected:
     // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#navigate-an-iframe-or-frame
     // 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 = {});
     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
     // https://html.spec.whatwg.org/multipage/document-sequences.html#content-navigable
     JS::GCPtr<Navigable> m_content_navigable { nullptr };
     JS::GCPtr<Navigable> m_content_navigable { nullptr };

+ 2 - 2
Userland/Libraries/LibWeb/HTML/Navigation.cpp

@@ -665,7 +665,7 @@ WebIDL::ExceptionOr<NavigationResult> Navigation::perform_a_navigation_api_trave
     auto source_snapshot_params = document.snapshot_source_snapshot_params();
     auto source_snapshot_params = document.snapshot_source_snapshot_params();
 
 
     // 12. Append the following session history traversal steps to traversable:
     // 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.
         // 1. Let navigableSHEs be the result of getting session history entries given navigable.
         auto navigable_shes = navigable->get_session_history_entries();
         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));
                 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.
     // 13. Return a navigation API method tracker-derived result for apiMethodTracker.
     return navigation_api_method_tracker_derived_result(api_method_tracker);
     return navigation_api_method_tracker_derived_result(api_method_tracker);

+ 6 - 6
Userland/Libraries/LibWeb/HTML/SessionHistoryTraversalQueue.cpp

@@ -12,9 +12,9 @@ namespace Web::HTML {
 JS_DEFINE_ALLOCATOR(SessionHistoryTraversalQueue);
 JS_DEFINE_ALLOCATOR(SessionHistoryTraversalQueue);
 JS_DEFINE_ALLOCATOR(SessionHistoryTraversalQueueEntry);
 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)
 void SessionHistoryTraversalQueueEntry::visit_edges(JS::Cell::Visitor& visitor)
@@ -46,17 +46,17 @@ void SessionHistoryTraversalQueue::visit_edges(JS::Cell::Visitor& visitor)
     visitor.visit(m_queue);
     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()) {
     if (!m_timer->is_active()) {
         m_timer->start();
         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()) {
     if (!m_timer->is_active()) {
         m_timer->start();
         m_timer->start();
     }
     }

+ 3 - 3
Userland/Libraries/LibWeb/HTML/SessionHistoryTraversalQueue.h

@@ -23,7 +23,7 @@ struct SessionHistoryTraversalQueueEntry : public JS::Cell {
     JS_DECLARE_ALLOCATOR(SessionHistoryTraversalQueueEntry);
     JS_DECLARE_ALLOCATOR(SessionHistoryTraversalQueueEntry);
 
 
 public:
 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; }
     JS::GCPtr<HTML::Navigable> target_navigable() const { return m_target_navigable; }
     void execute_steps() const { m_steps->function()(); }
     void execute_steps() const { m_steps->function()(); }
@@ -49,8 +49,8 @@ class SessionHistoryTraversalQueue : public JS::Cell {
 public:
 public:
     SessionHistoryTraversalQueue();
     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
     // 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&);
     JS::GCPtr<SessionHistoryTraversalQueueEntry> first_synchronous_navigation_steps_with_target_navigable_not_contained_in(HashTable<JS::NonnullGCPtr<Navigable>> const&);

+ 2 - 2
Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -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:
     // 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.
         // 1. Let allSteps be the result of getting all used history steps for traversable.
         auto all_steps = get_all_used_history_steps();
         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,
         // 5. Apply the traverse history step allSteps[targetStepIndex] to traversable, given sourceSnapshotParams,
         //    initiatorToCheck, and userInvolvement.
         //    initiatorToCheck, and userInvolvement.
         apply_the_traverse_history_step(all_steps[target_step_index], source_snapshot_params, initiator_to_check, user_involvement);
         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
 // https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-for-navigable-creation/destruction

+ 4 - 4
Userland/Libraries/LibWeb/HTML/TraversableNavigable.h

@@ -80,14 +80,14 @@ public:
     void close_top_level_traversable();
     void close_top_level_traversable();
     void destroy_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; }
     String window_handle() const { return m_window_handle; }