LibWeb: Use JS::HeapFunction in Fetch::Fetching::PendingResponse

This fixes a long-standing realm leak.
This commit is contained in:
Andreas Kling 2024-04-03 11:49:50 +02:00
parent 338dde70a1
commit a9842ebe48
Notes: sideshowbarker 2024-07-17 07:25:39 +09:00
2 changed files with 7 additions and 4 deletions

View File

@ -34,6 +34,7 @@ PendingResponse::PendingResponse(JS::NonnullGCPtr<Infrastructure::Request> reque
void PendingResponse::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_callback);
visitor.visit(m_request);
visitor.visit(m_response);
}
@ -41,7 +42,7 @@ void PendingResponse::visit_edges(JS::Cell::Visitor& visitor)
void PendingResponse::when_loaded(Callback callback)
{
VERIFY(!m_callback);
m_callback = move(callback);
m_callback = JS::create_heap_function(heap(), move(callback));
if (m_response)
run_callback();
}
@ -59,7 +60,9 @@ void PendingResponse::run_callback()
VERIFY(m_callback);
VERIFY(m_response);
Platform::EventLoopPlugin::the().deferred_invoke([this] {
m_callback(*m_response);
VERIFY(m_callback);
VERIFY(m_response);
m_callback->function()(*m_response);
m_request->remove_pending_response({}, *this);
});
}

View File

@ -23,7 +23,7 @@ class PendingResponse : public JS::Cell {
JS_DECLARE_ALLOCATOR(PendingResponse);
public:
using Callback = JS::SafeFunction<void(JS::NonnullGCPtr<Infrastructure::Response>)>;
using Callback = Function<void(JS::NonnullGCPtr<Infrastructure::Response>)>;
[[nodiscard]] static JS::NonnullGCPtr<PendingResponse> create(JS::VM&, JS::NonnullGCPtr<Infrastructure::Request>);
[[nodiscard]] static JS::NonnullGCPtr<PendingResponse> create(JS::VM&, JS::NonnullGCPtr<Infrastructure::Request>, JS::NonnullGCPtr<Infrastructure::Response>);
@ -38,7 +38,7 @@ private:
void run_callback();
Callback m_callback;
JS::GCPtr<JS::HeapFunction<void(JS::NonnullGCPtr<Infrastructure::Response>)>> m_callback;
JS::NonnullGCPtr<Infrastructure::Request> m_request;
JS::GCPtr<Infrastructure::Response> m_response;
};