Browse Source

LibWeb: Mark local variables captured in GC functions as ignored

These variables are all captured in queued events or other event loop
tasks, but are all guarded by event loop spins later in the function.

The IGNORE_USE_IN_ESCAPING_LAMBDA will soon be required for all locals
that are captured by ref in GC::Function as well as AK::Function.
Andrew Kaster 7 months ago
parent
commit
6ed2bf2bb1

+ 2 - 2
Libraries/LibWeb/DOM/Document.cpp

@@ -3470,7 +3470,7 @@ void Document::destroy_a_document_and_its_descendants(GC::Ptr<GC::Function<void(
     }
 
     // 2. Let childNavigables be document's child navigables.
-    auto child_navigables = document_tree_child_navigables();
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto child_navigables = document_tree_child_navigables();
 
     // 3. Let numberDestroyed be 0.
     IGNORE_USE_IN_ESCAPING_LAMBDA size_t number_destroyed = 0;
@@ -3698,7 +3698,7 @@ void Document::unload_a_document_and_its_descendants(GC::Ptr<Document> new_docum
             descendant_navigables.append(other_navigable);
     }
 
-    auto unloaded_documents_count = descendant_navigables.size() + 1;
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto unloaded_documents_count = descendant_navigables.size() + 1;
 
     HTML::queue_global_task(HTML::Task::Source::NavigationAndTraversal, HTML::relevant_global_object(*this), GC::create_function(heap(), [&number_unloaded, this, new_document] {
         unload(new_document);

+ 1 - 1
Libraries/LibWeb/HTML/EventSource.cpp

@@ -280,7 +280,7 @@ void EventSource::announce_the_connection()
 // https://html.spec.whatwg.org/multipage/server-sent-events.html#reestablish-the-connection
 void EventSource::reestablish_the_connection()
 {
-    bool initial_task_has_run { false };
+    IGNORE_USE_IN_ESCAPING_LAMBDA bool initial_task_has_run { false };
 
     // 1. Queue a task to run the following steps:
     HTML::queue_a_task(HTML::Task::Source::RemoteEvent, nullptr, nullptr, GC::create_function(heap(), [&]() {

+ 2 - 1
Libraries/LibWeb/HTML/Scripting/Fetching.cpp

@@ -475,7 +475,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri
     auto& vm = realm.vm();
 
     // 1. Let response be null.
-    GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
+    IGNORE_USE_IN_ESCAPING_LAMBDA GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
 
     // 2. Let bodyBytes be null.
     Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes;
@@ -510,6 +510,7 @@ WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_scri
     }
 
     // 5. Pause until response is not null.
+    // FIXME: Consider using a "response holder" to avoid needing to annotate response as IGNORE_USE_IN_ESCAPING_LAMBDA.
     auto& event_loop = settings_object.responsible_event_loop();
     event_loop.spin_until(GC::create_function(vm.heap(), [&]() -> bool {
         return response;

+ 8 - 8
Libraries/LibWeb/HTML/TraversableNavigable.cpp

@@ -429,7 +429,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
     bool check_for_cancelation,
     IGNORE_USE_IN_ESCAPING_LAMBDA Optional<SourceSnapshotParams> source_snapshot_params,
     GC::Ptr<Navigable> initiator_to_check,
-    Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
+    IGNORE_USE_IN_ESCAPING_LAMBDA Optional<UserNavigationInvolvement> user_involvement_for_navigate_events,
     IGNORE_USE_IN_ESCAPING_LAMBDA Optional<Bindings::NavigationType> navigation_type,
     IGNORE_USE_IN_ESCAPING_LAMBDA SynchronousNavigation synchronous_navigation)
 {
@@ -487,7 +487,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
     }
 
     // 9. Let totalChangeJobs be the size of changingNavigables.
-    auto total_change_jobs = changing_navigables.size();
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto total_change_jobs = changing_navigables.size();
 
     // 10. Let completedChangeJobs be 0.
     IGNORE_USE_IN_ESCAPING_LAMBDA size_t completed_change_jobs = 0;
@@ -799,7 +799,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_
     }));
 
     // 15. Let totalNonchangingJobs be the size of nonchangingNavigablesThatStillNeedUpdates.
-    auto total_non_changing_jobs = non_changing_navigables_that_still_need_updates.size();
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto total_non_changing_jobs = non_changing_navigables_that_still_need_updates.size();
 
     // 16. Let completedNonchangingJobs be 0.
     IGNORE_USE_IN_ESCAPING_LAMBDA auto completed_non_changing_jobs = 0u;
@@ -880,10 +880,10 @@ TraversableNavigable::CheckIfUnloadingIsCanceledResult TraversableNavigable::che
         documents_to_fire_beforeunload.append(navigable->active_document());
 
     // 2. Let unloadPromptShown be false.
-    auto unload_prompt_shown = false;
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto unload_prompt_shown = false;
 
     // 3. Let finalStatus be "continue".
-    auto final_status = CheckIfUnloadingIsCanceledResult::Continue;
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto final_status = CheckIfUnloadingIsCanceledResult::Continue;
 
     // 4. If traversable was given, then:
     if (traversable) {
@@ -900,7 +900,7 @@ TraversableNavigable::CheckIfUnloadingIsCanceledResult TraversableNavigable::che
             VERIFY(user_involvement_for_navigate_events.has_value());
 
             // 2. Let eventsFired be false.
-            auto events_fired = false;
+            IGNORE_USE_IN_ESCAPING_LAMBDA auto events_fired = false;
 
             // 3. Let needsBeforeunload be true if navigablesThatNeedBeforeUnload contains traversable; otherwise false.
             auto it = navigables_that_need_before_unload.find_if([&traversable](GC::Root<Navigable> navigable) {
@@ -964,10 +964,10 @@ TraversableNavigable::CheckIfUnloadingIsCanceledResult TraversableNavigable::che
     }
 
     // 5. Let totalTasks be the size of documentsThatNeedBeforeunload.
-    auto total_tasks = documents_to_fire_beforeunload.size();
+    IGNORE_USE_IN_ESCAPING_LAMBDA auto total_tasks = documents_to_fire_beforeunload.size();
 
     // 6. Let completedTasks be 0.
-    size_t completed_tasks = 0;
+    IGNORE_USE_IN_ESCAPING_LAMBDA size_t completed_tasks = 0;
 
     // 7. For each document of documents, queue a global task on the navigation and traversal task source given document's relevant global object to run the steps:
     for (auto& document : documents_to_fire_beforeunload) {

+ 2 - 2
Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp

@@ -79,8 +79,8 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
 
         // 2. For each entry of openConnections that does not have its close pending flag set to true,
         //    queue a task to fire a version change event named versionchange at entry with db’s version and version.
-        u32 events_to_fire = open_connections.size();
-        u32 events_fired = 0;
+        IGNORE_USE_IN_ESCAPING_LAMBDA u32 events_to_fire = open_connections.size();
+        IGNORE_USE_IN_ESCAPING_LAMBDA u32 events_fired = 0;
         for (auto& entry : open_connections) {
             if (!entry->close_pending()) {
                 HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(realm.vm().heap(), [&realm, entry, db, version, &events_fired]() {

+ 2 - 2
Libraries/LibWeb/XHR/XMLHttpRequest.cpp

@@ -892,7 +892,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
         }
     } else {
         // 1. Let processedResponse be false.
-        bool processed_response = false;
+        IGNORE_USE_IN_ESCAPING_LAMBDA bool processed_response = false;
 
         // 2. Let processResponseConsumeBody, given a response and nullOrFailureOrBytes, be these steps:
         auto process_response_consume_body = [this, &processed_response](GC::Ref<Fetch::Infrastructure::Response> response, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer> null_or_failure_or_bytes) {
@@ -927,7 +927,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
 
         // 4. Let now be the present time.
         // 5. Pause until either processedResponse is true or this’s timeout is not 0 and this’s timeout milliseconds have passed since now.
-        bool did_time_out = false;
+        IGNORE_USE_IN_ESCAPING_LAMBDA bool did_time_out = false;
 
         if (m_timeout != 0) {
             auto timer = Platform::Timer::create_single_shot(heap(), m_timeout, nullptr);