mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibWeb: Use JS::HeapFunction in Fetch::Fetching::PendingResponse
This fixes a long-standing realm leak.
This commit is contained in:
parent
338dde70a1
commit
a9842ebe48
Notes:
sideshowbarker
2024-07-17 07:25:39 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a9842ebe48 Pull-request: https://github.com/SerenityOS/serenity/pull/23815 Reviewed-by: https://github.com/ADKaster
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user