ladybird/Libraries/LibWeb/Fetch/Infrastructure/FetchRecord.h
Andreas Kling 66a19b8550
Some checks are pending
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
LibWeb: Make ESO "fetch group" weakly reference the fetch records
Otherwise we end up holding on to every fetch record indefinitely.

Found by analyzing GC heap graphs on Discord.
2025-07-29 20:00:17 -04:00

49 lines
1.7 KiB
C++

/*
* Copyright (c) 2024, Mohamed amine Bounya <mobounya@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Fetch/Infrastructure/FetchController.h>
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#concept-fetch-record
class FetchRecord final : public JS::Cell {
GC_CELL(FetchRecord, JS::Cell);
GC_DECLARE_ALLOCATOR(FetchRecord);
public:
[[nodiscard]] static GC::Ref<FetchRecord> create(JS::VM&, GC::Ref<Infrastructure::Request>);
[[nodiscard]] static GC::Ref<FetchRecord> create(JS::VM&, GC::Ref<Infrastructure::Request>, GC::Ptr<FetchController>);
[[nodiscard]] GC::Ref<Infrastructure::Request> request() const { return m_request; }
void set_request(GC::Ref<Infrastructure::Request> request) { m_request = request; }
[[nodiscard]] GC::Ptr<FetchController> fetch_controller() const { return m_fetch_controller; }
void set_fetch_controller(GC::Ptr<FetchController> fetch_controller) { m_fetch_controller = fetch_controller; }
private:
explicit FetchRecord(GC::Ref<Infrastructure::Request>);
FetchRecord(GC::Ref<Infrastructure::Request>, GC::Ptr<FetchController>);
virtual void visit_edges(Visitor&) override;
virtual void finalize() override;
// https://fetch.spec.whatwg.org/#concept-request
// A fetch record has an associated request (a request)
GC::Ref<Infrastructure::Request> m_request;
// https://fetch.spec.whatwg.org/#fetch-controller
// A fetch record has an associated controller (a fetch controller or null)
GC::Ptr<FetchController> m_fetch_controller { nullptr };
IntrusiveListNode<FetchRecord> m_list_node;
public:
using List = IntrusiveList<&FetchRecord::m_list_node>;
};
}