1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 18:17:41 +00:00

LibWeb: Use DOMException in XMLHttpRequest::set_request_header()

This commit is contained in:
Linus Groh 2021-02-20 00:45:24 +01:00 committed by Andreas Kling
parent 4e1de09340
commit c4d8cce9a2
2 changed files with 11 additions and 11 deletions

View file

@ -27,10 +27,12 @@
#include <LibJS/Runtime/Function.h> #include <LibJS/Runtime/Function.h>
#include <LibWeb/Bindings/EventWrapper.h> #include <LibWeb/Bindings/EventWrapper.h>
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h> #include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h> #include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/EventListener.h> #include <LibWeb/DOM/EventListener.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/Window.h> #include <LibWeb/DOM/Window.h>
#include <LibWeb/HTML/EventNames.h> #include <LibWeb/HTML/EventNames.h>
#include <LibWeb/Loader/ResourceLoader.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 // 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) { if (m_ready_state != ReadyState::Opened)
// FIXME: throw an "InvalidStateError" DOMException. return DOM::InvalidStateError::create("XHR readyState is not OPENED");
return;
}
if (m_send) { if (m_send)
// FIXME: throw an "InvalidStateError" DOMException. return DOM::InvalidStateError::create("XHR send() flag is already set");
return;
}
// FIXME: Check if name matches the name production. // FIXME: Check if name matches the name production.
// FIXME: Check if value matches the value production. // FIXME: Check if value matches the value production.
if (is_forbidden_header_name(header)) if (is_forbidden_header_name(header))
return; return {};
// FIXME: Combine // FIXME: Combine
m_request_headers.set(header, normalize_header_value(value)); m_request_headers.set(header, normalize_header_value(value));
return {};
} }
void XMLHttpRequest::open(const String& method, const String& url) void XMLHttpRequest::open(const String& method, const String& url)

View file

@ -33,6 +33,7 @@
#include <LibWeb/Bindings/WindowObject.h> #include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/Wrappable.h> #include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h> #include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/XHR/XMLHttpRequestEventTarget.h> #include <LibWeb/XHR/XMLHttpRequestEventTarget.h>
namespace Web::XHR { namespace Web::XHR {
@ -71,7 +72,7 @@ public:
void open(const String& method, const String& url); void open(const String& method, const String& url);
void send(); 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: private:
virtual void ref_event_target() override { ref(); } virtual void ref_event_target() override { ref(); }