mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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:
committed by
Andreas Kling
parent
1640b7957c
commit
f64b0e0351
Notes:
github-actions[bot]
2025-12-24 09:20:39 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/f64b0e03511 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7223 Reviewed-by: https://github.com/trflynn89
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user