diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index a8f8664040..dad9ed0d44 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -124,7 +124,7 @@ DOM::ExceptionOr XMLHttpRequest::set_request_header(const String& header, return {}; } -void XMLHttpRequest::open(const String& method, const String& url) +DOM::ExceptionOr XMLHttpRequest::open(const String& method, const String& url) { // FIXME: Let settingsObject be this’s relevant settings object. @@ -132,19 +132,15 @@ void XMLHttpRequest::open(const String& method, const String& url) // FIXME: Check that the method matches the method token production. https://tools.ietf.org/html/rfc7230#section-3.1.1 - if (is_forbidden_method(method)) { - // FIXME: Throw a "SecurityError" DOMException. - return; - } + if (is_forbidden_method(method)) + return DOM::SecurityError::create("Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"); String normalized_method = normalize_method(method); // FIXME: Pass in settingObject's API base URL and API URL character encoding. URL parsed_url(url); - if (!parsed_url.is_valid()) { - // FIXME: Throw a "SyntaxError" DOMException. - return; - } + if (!parsed_url.is_valid()) + return DOM::SyntaxError::create("Invalid URL"); if (!parsed_url.host().is_null()) { // FIXME: If the username argument is not null, set the username given parsedURL and username. @@ -173,6 +169,7 @@ void XMLHttpRequest::open(const String& method, const String& url) if (m_ready_state != ReadyState::Opened) set_ready_state(ReadyState::Opened); + return {}; } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index 686caa01d3..143b1d603f 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -69,7 +69,8 @@ public: ReadyState ready_state() const { return m_ready_state; }; String response_text() const; - void open(const String& method, const String& url); + + DOM::ExceptionOr open(const String& method, const String& url); void send(); DOM::ExceptionOr set_request_header(const String& header, const String& value);