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

LibWeb: Remove redundant JS::Value() calls in XMLHttpRequest::response()

This commit is contained in:
Linus Groh 2022-10-04 18:07:43 +01:00
parent 183462acfd
commit 58b0edef7d

View file

@ -103,10 +103,10 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) { if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) {
// 1. If thiss state is not loading or done, then return the empty string. // 1. If thiss state is not loading or done, then return the empty string.
if (m_ready_state != ReadyState::Loading && m_ready_state != ReadyState::Done) if (m_ready_state != ReadyState::Loading && m_ready_state != ReadyState::Done)
return JS::Value(JS::js_string(vm, "")); return JS::js_string(vm, "");
// 2. Return the result of getting a text response for this. // 2. Return the result of getting a text response for this.
return JS::Value(JS::js_string(vm, get_text_response())); return JS::js_string(vm, get_text_response());
} }
// 2. If thiss state is not done, then return null. // 2. If thiss state is not done, then return null.
if (m_ready_state != ReadyState::Done) if (m_ready_state != ReadyState::Done)
@ -152,12 +152,12 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
// 2. If thiss responses body is null, then return null. // 2. If thiss responses body is null, then return null.
// FIXME: Implement this once we have 'Response'. // FIXME: Implement this once we have 'Response'.
if (m_received_bytes.is_empty()) if (m_received_bytes.is_empty())
return JS::Value(JS::js_null()); 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. // 3. Let jsonObject be the result of running parse JSON from bytes on thiss received bytes. If that threw an exception, then return null.
auto json_object_result = Infra::parse_json_bytes_to_javascript_value(vm, m_received_bytes); auto json_object_result = Infra::parse_json_bytes_to_javascript_value(vm, m_received_bytes);
if (json_object_result.is_error()) if (json_object_result.is_error())
return JS::Value(JS::js_null()); return JS::js_null();
// 4. Set thiss response object to jsonObject. // 4. Set thiss response object to jsonObject.
m_response_object = json_object_result.release_value(); m_response_object = json_object_result.release_value();