/* * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Web::Fetch::Infrastructure { // https://fetch.spec.whatwg.org/#fetch-elsewhere-fetch class FetchAlgorithms : public JS::Cell { JS_CELL(FetchAlgorithms, JS::Cell); JS_DECLARE_ALLOCATOR(FetchAlgorithms); public: struct ConsumeBodyFailureTag { }; using BodyBytes = Variant; using ProcessRequestBodyChunkLengthFunction = Function; using ProcessRequestEndOfBodyFunction = Function; using ProcessEarlyHintsResponseFunction = Function)>; using ProcessResponseFunction = Function)>; using ProcessResponseEndOfBodyFunction = Function)>; using ProcessResponseConsumeBodyFunction = Function, BodyBytes)>; using ProcessRequestBodyChunkLengthHeapFunction = JS::NonnullGCPtr>; using ProcessRequestEndOfBodyHeapFunction = JS::NonnullGCPtr>; using ProcessEarlyHintsResponseHeapFunction = JS::NonnullGCPtr>; using ProcessResponseHeapFunction = JS::NonnullGCPtr>; using ProcessResponseEndOfBodyHeapFunction = JS::NonnullGCPtr>; using ProcessResponseConsumeBodyHeapFunction = JS::NonnullGCPtr>; struct Input { 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); 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( 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); ProcessRequestBodyChunkLengthHeapFunction m_process_request_body_chunk_length; ProcessRequestEndOfBodyHeapFunction m_process_request_end_of_body; ProcessEarlyHintsResponseHeapFunction m_process_early_hints_response; ProcessResponseHeapFunction m_process_response; ProcessResponseEndOfBodyHeapFunction m_process_response_end_of_body; ProcessResponseConsumeBodyHeapFunction m_process_response_consume_body; }; }