LibWeb: Use JS::HeapFunction for callbacks in FetchController

If a function that captures a GC-allocated object is owned by another
GC-allocated object, it is more preferable to use JS::HeapFunction.
This is because JS::HeapFunction is visited, unlike introducing a new
heap root as JS::SafeFunction does.
This commit is contained in:
Aliaksandr Kalenik 2023-09-25 18:04:10 +02:00 committed by Andreas Kling
parent df86e52d75
commit baf37af09c
Notes: sideshowbarker 2024-07-17 18:46:57 +09:00
2 changed files with 22 additions and 8 deletions

View file

@ -24,27 +24,39 @@ void FetchController::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_full_timing_info);
visitor.visit(m_report_timing_steps);
visitor.visit(m_next_manual_redirect_steps);
visitor.visit(m_fetch_params);
}
void FetchController::set_report_timing_steps(Function<void(JS::Object const&)> report_timing_steps)
{
m_report_timing_steps = JS::create_heap_function(vm().heap(), move(report_timing_steps));
}
void FetchController::set_next_manual_redirect_steps(Function<void()> next_manual_redirect_steps)
{
m_next_manual_redirect_steps = JS::create_heap_function(vm().heap(), move(next_manual_redirect_steps));
}
// https://fetch.spec.whatwg.org/#finalize-and-report-timing
void FetchController::report_timing(JS::Object const& global) const
{
// 1. Assert: thiss report timing steps is not null.
VERIFY(m_report_timing_steps.has_value());
VERIFY(m_report_timing_steps);
// 2. Call thiss report timing steps with global.
(*m_report_timing_steps)(global);
m_report_timing_steps->function()(global);
}
// https://fetch.spec.whatwg.org/#fetch-controller-process-the-next-manual-redirect
void FetchController::process_next_manual_redirect() const
{
// 1. Assert: controllers next manual redirect steps are not null.
VERIFY(m_next_manual_redirect_steps.has_value());
VERIFY(m_next_manual_redirect_steps);
// 2. Call controllers next manual redirect steps.
(*m_next_manual_redirect_steps)();
m_next_manual_redirect_steps->function()();
}
// https://fetch.spec.whatwg.org/#extract-full-timing-info