summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/XHR
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-02-20 00:45:24 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-20 09:14:19 +0100
commitc4d8cce9a201400c564fb0ba858e953e338a567d (patch)
tree51feb14740ebec0bce2e72623ed31c4f2c77ba99 /Userland/Libraries/LibWeb/XHR
parent4e1de093407ff07d7783c939cb0a99004179d0e2 (diff)
downloadserenity-c4d8cce9a201400c564fb0ba858e953e338a567d.zip
LibWeb: Use DOMException in XMLHttpRequest::set_request_header()
Diffstat (limited to 'Userland/Libraries/LibWeb/XHR')
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp19
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h3
2 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index 694d6818d2..a8f8664040 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -27,10 +27,12 @@
#include <LibJS/Runtime/Function.h>
#include <LibWeb/Bindings/EventWrapper.h>
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
+#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/EventListener.h>
+#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/Loader/ResourceLoader.h>
@@ -103,26 +105,23 @@ static String normalize_header_value(const String& header_value)
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader
-void XMLHttpRequest::set_request_header(const String& header, const String& value)
+DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(const String& header, const String& value)
{
- 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: Check if name matches the name production.
// FIXME: Check if value matches the value production.
if (is_forbidden_header_name(header))
- return;
+ return {};
// FIXME: Combine
m_request_headers.set(header, normalize_header_value(value));
+ return {};
}
void XMLHttpRequest::open(const String& method, const String& url)
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h
index 3071ba3aa2..686caa01d3 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h
@@ -33,6 +33,7 @@
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h>
+#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/XHR/XMLHttpRequestEventTarget.h>
namespace Web::XHR {
@@ -71,7 +72,7 @@ public:
void open(const String& method, const String& url);
void send();
- void set_request_header(const String& header, const String& value);
+ DOM::ExceptionOr<void> set_request_header(const String& header, const String& value);
private:
virtual void ref_event_target() override { ref(); }