mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:52:43 +00:00 
			
		
		
		
	 5951a93f51
			
		
	
	
		5951a93f51
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			56 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibJS/Heap/Heap.h>
 | |
| #include <LibJS/Runtime/VM.h>
 | |
| #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
 | |
| 
 | |
| namespace Web::Fetch::Infrastructure {
 | |
| 
 | |
| JS::NonnullGCPtr<FetchAlgorithms> FetchAlgorithms::create(JS::VM& vm, Input 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(
 | |
|     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)
 | |
| {
 | |
| }
 | |
| 
 | |
| void FetchAlgorithms::visit_edges(JS::Cell::Visitor& visitor)
 | |
| {
 | |
|     visitor.visit(m_process_request_body_chunk_length);
 | |
|     visitor.visit(m_process_request_end_of_body);
 | |
|     visitor.visit(m_process_early_hints_response);
 | |
|     visitor.visit(m_process_response);
 | |
|     visitor.visit(m_process_response_end_of_body);
 | |
|     visitor.visit(m_process_response_consume_body);
 | |
| }
 | |
| 
 | |
| }
 |