From 14058b6858ff2b0b3b03c72a65a8f31b9b59024f Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 20 Feb 2021 00:46:52 +0100 Subject: LibWeb: Use DOMException in XMLHttpRequest::send() --- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 21 +++++++++------------ Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index dad9ed0d44..b7ad3b4b93 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -173,17 +173,13 @@ DOM::ExceptionOr XMLHttpRequest::open(const String& method, const String& } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send -void XMLHttpRequest::send() +DOM::ExceptionOr XMLHttpRequest::send() { - if (m_ready_state != ReadyState::Opened) { - // FIXME: throw an "InvalidStateError" DOMException. - return; - } + if (m_ready_state != ReadyState::Opened) + return DOM::InvalidStateError::create("XHR readyState is not OPENED"); - if (m_send) { - // FIXME: throw an "InvalidStateError" DOMException. - return; - } + if (m_send) + return DOM::InvalidStateError::create("XHR send() flag is already set"); // FIXME: If this’s request method is `GET` or `HEAD`, then set body to null. @@ -199,10 +195,10 @@ void XMLHttpRequest::send() dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->document().url(), request_url); auto weak_this = make_weak_ptr(); if (!weak_this) - return; + return {}; const_cast(*weak_this).set_ready_state(ReadyState::Done); const_cast(*weak_this).dispatch_event(DOM::Event::create(HTML::EventNames::error)); - return; + return {}; } LoadRequest request; @@ -226,7 +222,7 @@ void XMLHttpRequest::send() // then fire a progress event named loadstart at this’s upload object with 0 and req’s body’s total bytes. if (m_ready_state != ReadyState::Opened || !m_send) - return; + return {}; // FIXME: in order to properly set ReadyState::HeadersReceived and ReadyState::Loading, // we need to make ResourceLoader give us more detailed updates than just "done" and "error". @@ -262,6 +258,7 @@ void XMLHttpRequest::send() } else { TODO(); } + return {}; } bool XMLHttpRequest::dispatch_event(NonnullRefPtr event) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index 143b1d603f..f90a5bf532 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -71,7 +71,7 @@ public: String response_text() const; DOM::ExceptionOr open(const String& method, const String& url); - void send(); + DOM::ExceptionOr send(); DOM::ExceptionOr set_request_header(const String& header, const String& value); -- cgit v1.2.3