From 183462acfd03aae8dab48375a45e5079f8cbcab4 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 4 Oct 2022 18:05:26 +0100 Subject: [PATCH] LibWeb: Use Infra AO for JSON parsing in XMLHttpRequest::response() --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 48469753ec..648ffbe0dd 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -97,14 +97,16 @@ WebIDL::ExceptionOr XMLHttpRequest::response_text() const // https://xhr.spec.whatwg.org/#response WebIDL::ExceptionOr XMLHttpRequest::response() { + auto& vm = this->vm(); + // 1. If this’s response type is the empty string or "text", then: if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) { // 1. If this’s state is not loading or done, then return the empty string. if (m_ready_state != ReadyState::Loading && m_ready_state != ReadyState::Done) - return JS::Value(JS::js_string(vm(), "")); + return JS::Value(JS::js_string(vm, "")); // 2. Return the result of getting a text response for this. - return JS::Value(JS::js_string(vm(), get_text_response())); + return JS::Value(JS::js_string(vm, get_text_response())); } // 2. If this’s state is not done, then return null. if (m_ready_state != ReadyState::Done) @@ -153,9 +155,7 @@ WebIDL::ExceptionOr XMLHttpRequest::response() return JS::Value(JS::js_null()); // 3. Let jsonObject be the result of running parse JSON from bytes on this’s received bytes. If that threw an exception, then return null. - TextCodec::UTF8Decoder decoder; - - auto json_object_result = JS::call(vm(), realm().intrinsics().json_parse_function(), JS::js_undefined(), JS::js_string(vm(), decoder.to_utf8({ m_received_bytes.data(), m_received_bytes.size() }))); + auto json_object_result = Infra::parse_json_bytes_to_javascript_value(vm, m_received_bytes); if (json_object_result.is_error()) return JS::Value(JS::js_null());