ソースを参照

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.
Kenneth Myhra 2 年 前
コミット
d5247ae33e
1 ファイル変更11 行追加4 行削除
  1. 11 4
      Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp

+ 11 - 4
Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp

@@ -433,12 +433,19 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBod
     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 (body_with_type.has_value()) {
     if (body_with_type.has_value()) {
-        TRY_OR_RETURN_OOM(realm, body_with_type->body.source().visit([&](ByteBuffer const& buffer) -> ErrorOr<void> {
+        TRY(body_with_type->body.source().visit(
+            [&](ByteBuffer const& buffer) -> WebIDL::ExceptionOr<void> {
                 request.set_body(buffer);
                 request.set_body(buffer);
-                return {}; }, [&](JS::Handle<FileAPI::Blob> const& blob) -> ErrorOr<void> {
-                auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes()));
+                return {};
+            },
+            [&](JS::Handle<FileAPI::Blob> const& blob) -> WebIDL::ExceptionOr<void> {
+                auto byte_buffer = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(blob->bytes()));
                 request.set_body(byte_buffer);
                 request.set_body(byte_buffer);
-                return {}; }, [](auto&) -> ErrorOr<void> { return {}; }));
+                return {};
+            },
+            [](auto&) -> WebIDL::ExceptionOr<void> {
+                return {};
+            }));
         if (body_with_type->type.has_value()) {
         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 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))
             if (!m_request_headers.contains("Content-Type"sv))