diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index bfdd783d62..33386e3ae1 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -65,7 +65,7 @@ WebIDL::ExceptionOr> fetch(JS: auto& vm = realm.vm(); // 1. Assert: request’s mode is "navigate" or processEarlyHintsResponse is null. - VERIFY(request.mode() == Infrastructure::Request::Mode::Navigate || !algorithms.process_early_hints_response().has_value()); + VERIFY(request.mode() == Infrastructure::Request::Mode::Navigate || !algorithms.process_early_hints_response()); // 2. Let taskDestination be null. JS::GCPtr task_destination; @@ -608,8 +608,8 @@ WebIDL::ExceptionOr fetch_response_handover(JS::Realm& realm, Infrastructu // 2. If fetchParams’s process response end-of-body is non-null, then run fetchParams’s process response // end-of-body given response. - if (fetch_params.algorithms()->process_response_end_of_body().has_value()) - (*fetch_params.algorithms()->process_response_end_of_body())(response); + if (fetch_params.algorithms()->process_response_end_of_body()) + (fetch_params.algorithms()->process_response_end_of_body())(response); // 3. If fetchParams’s request’s initiator type is non-null and fetchParams’s request’s client’s global // object is fetchParams’s task destination, then run fetchParams’s controller’s report timing steps @@ -634,9 +634,9 @@ WebIDL::ExceptionOr fetch_response_handover(JS::Realm& realm, Infrastructu // 4. If fetchParams’s process response is non-null, then queue a fetch task to run fetchParams’s process response // given response, with fetchParams’s task destination. - if (fetch_params.algorithms()->process_response().has_value()) { + if (fetch_params.algorithms()->process_response()) { Infrastructure::queue_fetch_task(task_destination, [&fetch_params, &response]() { - (*fetch_params.algorithms()->process_response())(response); + fetch_params.algorithms()->process_response()(response); }); } @@ -657,17 +657,17 @@ WebIDL::ExceptionOr fetch_response_handover(JS::Realm& realm, Infrastructu } // 8. If fetchParams’s process response consume body is non-null, then: - if (fetch_params.algorithms()->process_response_consume_body().has_value()) { + if (fetch_params.algorithms()->process_response_consume_body()) { // 1. Let processBody given nullOrBytes be this step: run fetchParams’s process response consume body given // response and nullOrBytes. auto process_body = [&fetch_params, &response](Variant const& null_or_bytes) { - (*fetch_params.algorithms()->process_response_consume_body())(response, null_or_bytes); + (fetch_params.algorithms()->process_response_consume_body())(response, null_or_bytes); }; // 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and // failure. auto process_body_error = [&fetch_params, &response](auto) { - (*fetch_params.algorithms()->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {}); + (fetch_params.algorithms()->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {}); }; // 3. If internalResponse's body is null, then queue a fetch task to run processBody given null, with diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp index a353a3197d..0b967ee551 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.cpp @@ -12,17 +12,27 @@ namespace Web::Fetch::Infrastructure { JS::NonnullGCPtr FetchAlgorithms::create(JS::VM& vm, Input input) { - return vm.heap().allocate_without_realm(move(input)); + return vm.heap().allocate_without_realm(vm, move(input)); } -FetchAlgorithms::FetchAlgorithms(Input input) - : m_process_request_body_chunk_length(move(input.process_request_body_chunk_length)) - , m_process_request_end_of_body(move(input.process_request_end_of_body)) - , m_process_early_hints_response(move(input.process_early_hints_response)) - , m_process_response(move(input.process_response)) - , m_process_response_end_of_body(move(input.process_response_end_of_body)) - , m_process_response_consume_body(move(input.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))) { } +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); +} + } diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h index 2676547d78..b7b0409d7d 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchAlgorithms.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -22,40 +23,42 @@ public: struct ConsumeBodyFailureTag { }; using BodyBytes = Variant; - using ProcessRequestBodyChunkLengthFunction = JS::SafeFunction; - using ProcessRequestEndOfBodyFunction = JS::SafeFunction; - using ProcessEarlyHintsResponseFunction = JS::SafeFunction)>; - using ProcessResponseFunction = JS::SafeFunction)>; - using ProcessResponseEndOfBodyFunction = JS::SafeFunction)>; - using ProcessResponseConsumeBodyFunction = JS::SafeFunction, BodyBytes)>; + using ProcessRequestBodyChunkLengthFunction = Function; + using ProcessRequestEndOfBodyFunction = Function; + using ProcessEarlyHintsResponseFunction = Function)>; + using ProcessResponseFunction = Function)>; + using ProcessResponseEndOfBodyFunction = Function)>; + using ProcessResponseConsumeBodyFunction = Function, BodyBytes)>; struct Input { - Optional process_request_body_chunk_length; - Optional process_request_end_of_body; - Optional process_early_hints_response; - Optional process_response; - Optional process_response_end_of_body; - Optional process_response_consume_body; + ProcessRequestBodyChunkLengthFunction process_request_body_chunk_length; + ProcessRequestEndOfBodyFunction process_request_end_of_body; + ProcessEarlyHintsResponseFunction process_early_hints_response; + ProcessResponseFunction process_response; + ProcessResponseEndOfBodyFunction process_response_end_of_body; + ProcessResponseConsumeBodyFunction process_response_consume_body; }; [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, Input); - Optional const& process_request_body_chunk_length() const { return m_process_request_body_chunk_length; } - Optional const& process_request_end_of_body() const { return m_process_request_end_of_body; } - Optional const& process_early_hints_response() const { return m_process_early_hints_response; } - Optional const& process_response() const { return m_process_response; } - Optional const& process_response_end_of_body() const { return m_process_response_end_of_body; } - Optional const& process_response_consume_body() const { return m_process_response_consume_body; } + ProcessRequestBodyChunkLengthFunction const& process_request_body_chunk_length() const { return m_process_request_body_chunk_length->function(); } + ProcessRequestEndOfBodyFunction const& process_request_end_of_body() const { return m_process_request_end_of_body->function(); } + ProcessEarlyHintsResponseFunction const& process_early_hints_response() const { return m_process_early_hints_response->function(); } + ProcessResponseFunction const& process_response() const { return m_process_response->function(); } + ProcessResponseEndOfBodyFunction const& process_response_end_of_body() const { return m_process_response_end_of_body->function(); } + ProcessResponseConsumeBodyFunction const& process_response_consume_body() const { return m_process_response_consume_body->function(); } + + virtual void visit_edges(JS::Cell::Visitor&) override; private: - explicit FetchAlgorithms(Input); + explicit FetchAlgorithms(JS::VM&, Input); - Optional m_process_request_body_chunk_length; - Optional m_process_request_end_of_body; - Optional m_process_early_hints_response; - Optional m_process_response; - Optional m_process_response_end_of_body; - Optional m_process_response_consume_body; + JS::NonnullGCPtr> m_process_request_body_chunk_length; + JS::NonnullGCPtr> m_process_request_end_of_body; + JS::NonnullGCPtr)>> m_process_early_hints_response; + JS::NonnullGCPtr)>> m_process_response; + JS::NonnullGCPtr)>> m_process_response_end_of_body; + JS::NonnullGCPtr, BodyBytes)>> m_process_response_consume_body; }; }