1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibWeb: Handle non-object JSON in XMLHttpRequest response

This fixes a crash seen on https://web.basemark.com/run/
This commit is contained in:
Shannon Booth 2024-05-04 17:50:25 +12:00 committed by Andreas Kling
parent 3695344d6f
commit f7ba07cc8b
Notes: sideshowbarker 2024-07-16 19:57:55 +09:00
3 changed files with 27 additions and 6 deletions

View file

@ -173,7 +173,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_response_type(Bindings::XMLHttpReq
return {};
}
// https://xhr.spec.whatwg.org/#response
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-response
WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
{
auto& vm = this->vm();
@ -222,9 +222,6 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
// 7. Otherwise, if thiss response type is "document", set a document response for this.
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
set_document_response();
if (m_response_object.has<Empty>())
return JS::js_null();
}
// 8. Otherwise:
else {
@ -241,11 +238,16 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
return JS::js_null();
// 4. Set thiss response object to jsonObject.
m_response_object = JS::NonnullGCPtr<JS::Object> { json_object_result.release_value().as_object() };
if (json_object_result.value().is_object())
m_response_object = JS::NonnullGCPtr<JS::Object> { json_object_result.release_value().as_object() };
else
m_response_object = Empty {};
}
// 9. Return thiss response object.
return m_response_object.get<JS::NonnullGCPtr<JS::Object>>();
return m_response_object.visit(
[](JS::NonnullGCPtr<JS::Object> object) -> JS::Value { return object; },
[](auto const&) -> JS::Value { return JS::js_null(); });
}
// https://xhr.spec.whatwg.org/#text-response