diff options
author | Linus Groh <mail@linusgroh.de> | 2021-02-20 00:46:52 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-20 09:14:19 +0100 |
commit | 14058b6858ff2b0b3b03c72a65a8f31b9b59024f (patch) | |
tree | 5a0a18792702c1c1780d85d4e6547b2075c8fff6 /Userland/Libraries/LibWeb/XHR | |
parent | 70878290b9f93a013b143fc6edf62854c05d7014 (diff) | |
download | serenity-14058b6858ff2b0b3b03c72a65a8f31b9b59024f.zip |
LibWeb: Use DOMException in XMLHttpRequest::send()
Diffstat (limited to 'Userland/Libraries/LibWeb/XHR')
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 21 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 |
2 files changed, 10 insertions, 13 deletions
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<void> XMLHttpRequest::open(const String& method, const String& } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send -void XMLHttpRequest::send() +DOM::ExceptionOr<void> 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<XMLHttpRequest&>(*weak_this).set_ready_state(ReadyState::Done); const_cast<XMLHttpRequest&>(*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<DOM::Event> 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<void> open(const String& method, const String& url); - void send(); + DOM::ExceptionOr<void> send(); DOM::ExceptionOr<void> set_request_header(const String& header, const String& value); |