LibWeb: Make FetchController's Requests::Request reference weak
This allows the Request to be cleaned up when it becomes inactive, which in turn allows the GC to clean up the FetchController which is indirectly captured by a root in the Request callbacks.
This commit is contained in:
parent
282c054ddc
commit
7c0802bd4f
4 changed files with 8 additions and 6 deletions
|
|
@ -42,7 +42,8 @@ private:
|
|||
NonnullRefPtr<Core::Notifier> m_notifier;
|
||||
};
|
||||
|
||||
class Request : public RefCounted<Request> {
|
||||
class Request : public RefCounted<Request>
|
||||
, public Weakable<Request> {
|
||||
public:
|
||||
struct CertificateAndKey {
|
||||
ByteString certificate;
|
||||
|
|
|
|||
|
|
@ -2156,7 +2156,7 @@ GC::Ref<PendingResponse> nonstandard_resource_loader_file_or_http_network_fetch(
|
|||
});
|
||||
|
||||
auto network_request = ResourceLoader::the().load(load_request, on_headers_received, on_data_received, on_complete);
|
||||
fetch_params.controller()->set_pending_request(move(network_request));
|
||||
fetch_params.controller()->set_pending_request(network_request);
|
||||
|
||||
return pending_response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ void FetchController::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_fetch_params);
|
||||
}
|
||||
|
||||
void FetchController::set_pending_request(RefPtr<Requests::Request> request)
|
||||
void FetchController::set_pending_request(RefPtr<Requests::Request> const& request)
|
||||
{
|
||||
m_pending_request = move(request);
|
||||
m_pending_request = request;
|
||||
}
|
||||
|
||||
void FetchController::set_report_timing_steps(Function<void(JS::Object&)> report_timing_steps)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibGC/Function.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
|
@ -52,7 +53,7 @@ public:
|
|||
|
||||
void set_fetch_params(Badge<FetchParams>, GC::Ref<FetchParams> fetch_params) { m_fetch_params = fetch_params; }
|
||||
|
||||
void set_pending_request(RefPtr<Requests::Request>);
|
||||
void set_pending_request(RefPtr<Requests::Request> const&);
|
||||
void set_inner_fetch_controller(GC::Ref<FetchController>);
|
||||
|
||||
void stop_fetch();
|
||||
|
|
@ -94,7 +95,7 @@ private:
|
|||
|
||||
GC::Ptr<FetchParams> m_fetch_params;
|
||||
|
||||
RefPtr<Requests::Request> m_pending_request;
|
||||
WeakPtr<Requests::Request> m_pending_request;
|
||||
|
||||
HashMap<u64, HTML::TaskID> m_ongoing_fetch_tasks;
|
||||
u64 m_next_fetch_task_id { 0 };
|
||||
|
|
|
|||
Loading…
Reference in a new issue