mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
LibWeb: Let LoadRequest::set_body() take by value
This changes the signature of LoadRequest::set_body() to take by value and then use move semantics to move the contents of the ByteBuffer. This is done to avoid the fallible copy constructor of ByteBuffer.
This commit is contained in:
parent
7831e62955
commit
f09e256328
3 changed files with 6 additions and 5 deletions
|
@ -128,7 +128,7 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
|
||||||
auto body = url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer();
|
auto body = url_encode(parameters, AK::URL::PercentEncodeSet::ApplicationXWWWFormUrlencoded).to_byte_buffer();
|
||||||
request.set_method("POST");
|
request.set_method("POST");
|
||||||
request.set_header("Content-Type", "application/x-www-form-urlencoded");
|
request.set_header("Content-Type", "application/x-www-form-urlencoded");
|
||||||
request.set_body(body);
|
request.set_body(move(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto* page = document().page())
|
if (auto* page = document().page())
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
void set_method(String const& method) { m_method = method; }
|
void set_method(String const& method) { m_method = method; }
|
||||||
|
|
||||||
ByteBuffer const& body() const { return m_body; }
|
ByteBuffer const& body() const { return m_body; }
|
||||||
void set_body(ByteBuffer const& body) { m_body = body; }
|
void set_body(ByteBuffer body) { m_body = move(body); }
|
||||||
|
|
||||||
void start_timer() { m_load_timer.start(); };
|
void start_timer() { m_load_timer.start(); };
|
||||||
Time load_time() const { return m_load_timer.elapsed_time(); }
|
Time load_time() const { return m_load_timer.elapsed_time(); }
|
||||||
|
|
|
@ -440,16 +440,17 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Variant<JS::Handle<DOM::
|
||||||
auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page());
|
auto request = LoadRequest::create_for_url_on_page(request_url, m_window->page());
|
||||||
request.set_method(m_method);
|
request.set_method(m_method);
|
||||||
if (serialized_document.has_value()) {
|
if (serialized_document.has_value()) {
|
||||||
request.set_body(serialized_document.value());
|
request.set_body(serialized_document.release_value());
|
||||||
} else if (body_with_type.has_value()) {
|
} else if (body_with_type.has_value()) {
|
||||||
TRY(body_with_type->body.source().visit(
|
TRY(body_with_type->body.source().visit(
|
||||||
[&](ByteBuffer const& buffer) -> WebIDL::ExceptionOr<void> {
|
[&](ByteBuffer const& buffer) -> WebIDL::ExceptionOr<void> {
|
||||||
request.set_body(buffer);
|
auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(buffer));
|
||||||
|
request.set_body(move(byte_buffer));
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
[&](JS::Handle<FileAPI::Blob> const& blob) -> WebIDL::ExceptionOr<void> {
|
[&](JS::Handle<FileAPI::Blob> const& blob) -> WebIDL::ExceptionOr<void> {
|
||||||
auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(blob->bytes()));
|
auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(blob->bytes()));
|
||||||
request.set_body(byte_buffer);
|
request.set_body(move(byte_buffer));
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
[](auto&) -> WebIDL::ExceptionOr<void> {
|
[](auto&) -> WebIDL::ExceptionOr<void> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue