From d5247ae33e99eb8e084c7ea74dd23e51d75b8d6d Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sun, 9 Oct 2022 22:33:51 +0200 Subject: [PATCH] LibWeb: Let lambdas return WebIDL::ExceptionOr in XHR::send() Instead of ErrorOr let these lambdas return WebIdL::ExceptionOr. This patch also cleans up this part so it's a bit more readable. --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 285259af87..83b70a21d3 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -433,12 +433,19 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optionalpage()); request.set_method(m_method); if (body_with_type.has_value()) { - TRY_OR_RETURN_OOM(realm, body_with_type->body.source().visit([&](ByteBuffer const& buffer) -> ErrorOr { + TRY(body_with_type->body.source().visit( + [&](ByteBuffer const& buffer) -> WebIDL::ExceptionOr { request.set_body(buffer); - return {}; }, [&](JS::Handle const& blob) -> ErrorOr { - auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes())); + return {}; + }, + [&](JS::Handle const& blob) -> WebIDL::ExceptionOr { + auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(blob->bytes())); request.set_body(byte_buffer); - return {}; }, [](auto&) -> ErrorOr { return {}; })); + return {}; + }, + [](auto&) -> WebIDL::ExceptionOr { + return {}; + })); if (body_with_type->type.has_value()) { // If type is non-null and this’s headers’s header list does not contain `Content-Type`, then append (`Content-Type`, type) to this’s headers. if (!m_request_headers.contains("Content-Type"sv))