1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibWeb: Remove GC allocations in FetchAlgorithms constructor

We should not GC allocate in the constructors of GC-allocated objects
because a new allocation might trigger garbage collection, which in
turn might access not fully initialized objects.
This commit is contained in:
Aliaksandr Kalenik 2023-09-03 17:32:52 +02:00 committed by Andreas Kling
parent f9f9c38de3
commit 5951a93f51
2 changed files with 46 additions and 15 deletions

View file

@ -12,16 +12,34 @@ namespace Web::Fetch::Infrastructure {
JS::NonnullGCPtr<FetchAlgorithms> FetchAlgorithms::create(JS::VM& vm, Input input)
{
return vm.heap().allocate_without_realm<FetchAlgorithms>(vm, move(input));
auto process_request_body_chunk_length = JS::create_heap_function(vm.heap(), move(input.process_request_body_chunk_length));
auto process_request_end_of_body = JS::create_heap_function(vm.heap(), move(input.process_request_end_of_body));
auto process_early_hints_response = JS::create_heap_function(vm.heap(), move(input.process_early_hints_response));
auto process_response = JS::create_heap_function(vm.heap(), move(input.process_response));
auto process_response_end_of_body = JS::create_heap_function(vm.heap(), move(input.process_response_end_of_body));
auto process_response_consume_body = JS::create_heap_function(vm.heap(), move(input.process_response_consume_body));
return vm.heap().allocate_without_realm<FetchAlgorithms>(
process_request_body_chunk_length,
process_request_end_of_body,
process_early_hints_response,
process_response,
process_response_end_of_body,
process_response_consume_body);
}
FetchAlgorithms::FetchAlgorithms(JS::VM& vm, Input input)
: m_process_request_body_chunk_length(JS::create_heap_function(vm.heap(), move(input.process_request_body_chunk_length)))
, m_process_request_end_of_body(JS::create_heap_function(vm.heap(), move(input.process_request_end_of_body)))
, m_process_early_hints_response(JS::create_heap_function(vm.heap(), move(input.process_early_hints_response)))
, m_process_response(JS::create_heap_function(vm.heap(), move(input.process_response)))
, m_process_response_end_of_body(JS::create_heap_function(vm.heap(), move(input.process_response_end_of_body)))
, m_process_response_consume_body(JS::create_heap_function(vm.heap(), move(input.process_response_consume_body)))
FetchAlgorithms::FetchAlgorithms(
ProcessRequestBodyChunkLengthHeapFunction process_request_body_chunk_length,
ProcessRequestEndOfBodyHeapFunction process_request_end_of_body,
ProcessEarlyHintsResponseHeapFunction process_early_hints_response,
ProcessResponseHeapFunction process_response,
ProcessResponseEndOfBodyHeapFunction process_response_end_of_body,
ProcessResponseConsumeBodyHeapFunction process_response_consume_body)
: m_process_request_body_chunk_length(process_request_body_chunk_length)
, m_process_request_end_of_body(process_request_end_of_body)
, m_process_early_hints_response(process_early_hints_response)
, m_process_response(process_response)
, m_process_response_end_of_body(process_response_end_of_body)
, m_process_response_consume_body(process_response_consume_body)
{
}