1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:57:44 +00:00

LibWeb: Make Fetch::Infrastructure::Body be GC allocated

Making the body GC-allocated allows us to avoid using `JS::Handle`
for `m_stream` in its members.
This commit is contained in:
Aliaksandr Kalenik 2023-08-18 19:38:13 +02:00 committed by Andreas Kling
parent 953c19bdb7
commit bdd3a16b16
21 changed files with 117 additions and 91 deletions

View file

@ -82,6 +82,7 @@ void XMLHttpRequest::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_upload_object);
visitor.visit(m_author_request_headers);
visitor.visit(m_request_body);
visitor.visit(m_response);
visitor.visit(m_fetch_controller);
@ -194,7 +195,7 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
// Note: Automatically done by the layers above us.
// 2. If thiss responses body is null, then return null.
if (!m_response->body().has_value())
if (!m_response->body())
return JS::js_null();
// 3. Let jsonObject be the result of running parse JSON from bytes on thiss received bytes. If that threw an exception, then return null.
@ -214,7 +215,7 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
String XMLHttpRequest::get_text_response() const
{
// 1. If xhrs responses body is null, then return the empty string.
if (!m_response->body().has_value())
if (!m_response->body())
return String {};
// 2. Let charset be the result of get a final encoding for xhr.
@ -559,8 +560,8 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
// body
// Thiss request body.
if (m_request_body.has_value())
request->set_body(m_request_body.value());
if (m_request_body)
request->set_body(JS::NonnullGCPtr { *m_request_body });
// client
// Thiss relevant settings object.
@ -594,7 +595,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
// 9. If reqs body is null, then set thiss upload complete flag.
// NOTE: req's body is always m_request_body here, see step 6.
if (!m_request_body.has_value())
if (!m_request_body)
m_upload_complete = true;
// 10. Set thiss send() flag.
@ -615,11 +616,11 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
// NOTE: req's body is always m_request_body here, see step 6.
// 4. Assert: requestBodyLength is an integer.
// NOTE: This is done to provide a better assertion failure message, whereas below the message would be "m_has_value"
if (m_request_body.has_value())
if (m_request_body)
VERIFY(m_request_body->length().has_value());
// NOTE: This is const to allow the callback functions to take a copy of it and know it won't change.
auto const request_body_length = m_request_body.has_value() ? m_request_body->length().value() : 0;
auto const request_body_length = m_request_body ? m_request_body->length().value() : 0;
// 5. If thiss upload complete flag is unset and thiss upload listener flag is set, then fire a progress event named loadstart at thiss upload object with requestBodyTransmitted and requestBodyLength.
if (!m_upload_complete && m_upload_listener)
@ -691,7 +692,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
return;
// 7. If thiss responses body is null, then run handle response end-of-body for this and return.
if (!m_response->body().has_value()) {
if (!m_response->body()) {
// NOTE: This cannot throw, as `handle_response_end_of_body` only throws in a synchronous context.
// FIXME: However, we can receive allocation failures, but we can't propagate them anywhere currently.
handle_response_end_of_body().release_value_but_fixme_should_propagate_errors();