diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 0a6f36931fe..746358d6624 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -214,6 +214,7 @@ set(SOURCES Fetch/Infrastructure/ConnectionTimingInfo.cpp Fetch/Infrastructure/FetchAlgorithms.cpp Fetch/Infrastructure/FetchController.cpp + Fetch/Infrastructure/FetchRecord.cpp Fetch/Infrastructure/FetchParams.cpp Fetch/Infrastructure/FetchTimingInfo.cpp Fetch/Infrastructure/HTTP.cpp diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp new file mode 100644 index 00000000000..20fe3d4ffcc --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, Mohamed amine Bounya + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::Fetch::Infrastructure { + +JS_DEFINE_ALLOCATOR(FetchRecord); + +JS::NonnullGCPtr FetchRecord::create(JS::VM& vm, JS::NonnullGCPtr request) +{ + return vm.heap().allocate_without_realm(request); +} + +JS::NonnullGCPtr FetchRecord::create(JS::VM& vm, JS::NonnullGCPtr request, JS::GCPtr fetch_controller) +{ + return vm.heap().allocate_without_realm(request, fetch_controller); +} + +FetchRecord::FetchRecord(JS::NonnullGCPtr request) + : m_request(request) +{ +} + +FetchRecord::FetchRecord(JS::NonnullGCPtr request, JS::GCPtr fetch_controller) + : m_request(request) + , m_fetch_controller(fetch_controller) +{ +} + +void FetchRecord::visit_edges(Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_request); + visitor.visit(m_fetch_controller); +} + +} diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h new file mode 100644 index 00000000000..3e06b337251 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024, Mohamed amine Bounya + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::Fetch::Infrastructure { + +// https://fetch.spec.whatwg.org/#concept-fetch-record +class FetchRecord : public JS::Cell { + JS_CELL(FetchRecord, JS::Cell); + JS_DECLARE_ALLOCATOR(FetchRecord); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, JS::NonnullGCPtr); + [[nodiscard]] static JS::NonnullGCPtr create(JS::VM&, JS::NonnullGCPtr, JS::GCPtr); + + [[nodiscard]] JS::NonnullGCPtr request() const { return m_request; } + void set_request(JS::NonnullGCPtr request) { m_request = request; } + + [[nodiscard]] JS::GCPtr fetch_controller() const { return m_fetch_controller; } + void set_fetch_controller(JS::GCPtr fetch_controller) { m_fetch_controller = fetch_controller; } + +private: + explicit FetchRecord(JS::NonnullGCPtr); + FetchRecord(JS::NonnullGCPtr, JS::GCPtr); + + virtual void visit_edges(Visitor&) override; + + // https://fetch.spec.whatwg.org/#concept-request + // A fetch record has an associated request (a request) + JS::NonnullGCPtr m_request; + + // https://fetch.spec.whatwg.org/#fetch-controller + // A fetch record has an associated controller (a fetch controller or null) + JS::GCPtr m_fetch_controller { nullptr }; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e339cb1bfe3..6e94546205d 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -311,6 +311,7 @@ class FetchAlgorithms; class FetchController; class FetchParams; class FetchTimingInfo; +class FetchRecord; class HeaderList; class IncrementalReadLoopReadRequest; class Request;