LibWeb: Avoid GC::Root capture in check_if_unloading_is_canceled()

We never want to capture GC::Roots in GC::Function lambdas, since that
very easily creates reference cycles and leak huge object graphs.
Capturing a raw pointer or GC::Ptr/Ref is fine, since that's exactly
what GC::Function is good at.
This commit is contained in:
Andreas Kling
2025-12-22 09:52:01 -06:00
committed by Andreas Kling
parent 1640b7957c
commit f64b0e0351
Notes: github-actions[bot] 2025-12-24 09:20:39 +00:00

View File

@@ -989,7 +989,8 @@ TraversableNavigable::CheckIfUnloadingIsCanceledResult TraversableNavigable::che
// 7. For each document of documentsToFireBeforeunload, 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) {
queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*document), GC::create_function(heap(), [document, &final_status, &completed_tasks, &unload_prompt_shown] {
// NOTE: We don't capture `document` by value here because it is a GC::Root and we want to avoid reference cycles.
queue_global_task(Task::Source::NavigationAndTraversal, relevant_global_object(*document), GC::create_function(heap(), [document = document.ptr(), &final_status, &completed_tasks, &unload_prompt_shown] {
// 1. Let (unloadPromptShownForThisDocument, unloadPromptCanceledByThisDocument) be the result of running the steps to fire beforeunload given document and unloadPromptShown.
auto [unload_prompt_shown_for_this_document, unload_prompt_canceled_by_this_document] = document->steps_to_fire_beforeunload(unload_prompt_shown);