LibWeb: Remove some uses of [&] lambda captures for queued tasks

Using a default reference capture for these kinds of tasks is dangerous
and prone to error. Some of the variables should for sure be captured
by value so that we can keep a GC object alive rather than trying to
refer to stack objects.
This commit is contained in:
Andrew Kaster 2024-12-09 19:48:50 -07:00 committed by Andreas Kling
parent 6ed2bf2bb1
commit 66519af43f
Notes: github-actions[bot] 2024-12-10 06:14:03 +00:00
4 changed files with 10 additions and 10 deletions

View file

@ -298,7 +298,7 @@ void HTMLParser::the_end(GC::Ref<DOM::Document> document, GC::Ptr<HTMLParser> pa
while (!document->scripts_to_execute_when_parsing_has_finished().is_empty()) {
// 1. Spin the event loop until the first script in the list of scripts that will execute when the document has finished parsing
// has its "ready to be parser-executed" flag set and the parser's Document has no style sheet that is blocking scripts.
main_thread_event_loop().spin_until(GC::create_function(heap, [&] {
main_thread_event_loop().spin_until(GC::create_function(heap, [document] {
return document->scripts_to_execute_when_parsing_has_finished().first()->is_ready_to_be_parser_executed()
&& !document->has_a_style_sheet_that_is_blocking_scripts();
}));
@ -311,7 +311,7 @@ void HTMLParser::the_end(GC::Ref<DOM::Document> document, GC::Ptr<HTMLParser> pa
}
// 6. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps:
queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(heap, [document = document] {
queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(heap, [document] {
// 1. Set the Document's load timing info's DOM content loaded event start time to the current high resolution time given the Document's relevant global object.
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::current_high_resolution_time(relevant_global_object(*document));
@ -329,17 +329,17 @@ void HTMLParser::the_end(GC::Ref<DOM::Document> document, GC::Ptr<HTMLParser> pa
}));
// 7. Spin the event loop until the set of scripts that will execute as soon as possible and the list of scripts that will execute in order as soon as possible are empty.
main_thread_event_loop().spin_until(GC::create_function(heap, [&] {
main_thread_event_loop().spin_until(GC::create_function(heap, [document] {
return document->scripts_to_execute_as_soon_as_possible().is_empty();
}));
// 8. Spin the event loop until there is nothing that delays the load event in the Document.
main_thread_event_loop().spin_until(GC::create_function(heap, [&] {
main_thread_event_loop().spin_until(GC::create_function(heap, [document] {
return !document->anything_is_delaying_the_load_event();
}));
// 9. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following steps:
queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(document->heap(), [document = document] {
queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(document->heap(), [document] {
// 1. Update the current document readiness to "complete".
document->update_readiness(HTML::DocumentReadyState::Complete);