summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2022-04-18 20:31:29 +0200
committerLinus Groh <mail@linusgroh.de>2022-04-23 18:05:55 +0200
commita5514fece9cc15738bf41d579b203630c809fe8e (patch)
tree27f6941b89392bc360e0dd5ada289d7f0d9596b6
parent01194053b73b3ef7e14cff1834f70073d53417d1 (diff)
downloadserenity-a5514fece9cc15738bf41d579b203630c809fe8e.zip
LibWeb: Move XHR::open() towards more spec compliance
Following FIXMEs have been addressed: - 1. Let settingsObject be this’s relevant settings object. - 2. If settingsObject has a responsible document and it is not fully active, then throw an "InvalidStateError" DOMException. - 6. Let parsedURL be the result of parsing url with settingsObject's API base URL and settingsObject’s API URL character encoding. - 8. If the async argument is omitted, set async to true, and set username and password to null.
-rw-r--r--Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
index 8717250117..d4674251d7 100644
--- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
+++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp
@@ -468,14 +468,18 @@ DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name, St
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-open
DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method, String const& url)
{
+ // 8. If the async argument is omitted, set async to true, and set username and password to null.
return open(method, url, true, {}, {});
}
DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method, String const& url, bool async, String const& username, String const& password)
{
- // FIXME: 1. Let settingsObject be this’s relevant settings object.
+ // 1. Let settingsObject be this’s relevant settings object.
+ auto& settings_object = m_window->associated_document().relevant_settings_object();
- // FIXME: 2. If settingsObject has a responsible document and it is not fully active, then throw an "InvalidStateError" DOMException.
+ // 2. If settingsObject has a responsible document and it is not fully active, then throw an "InvalidStateError" DOMException.
+ if (!settings_object.responsible_document().is_null() && !settings_object.responsible_document()->is_active())
+ return DOM::InvalidStateError::create("Invalid state: Responsible document is not fully active.");
// 3. If method is not a method, then throw a "SyntaxError" DOMException.
if (!is_method(method))
@@ -489,13 +493,14 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method, String const&
auto normalized_method = normalize_method(method);
// 6. Let parsedURL be the result of parsing url with settingsObject’s API base URL and settingsObject’s API URL character encoding.
- // FIXME: Should use relevant settings object and not assume it's the Window object
- auto parsed_url = m_window->associated_document().parse_url(url);
+ auto parsed_url = settings_object.responsible_document()->parse_url(url);
+
// 7. If parsedURL is failure, then throw a "SyntaxError" DOMException.
if (!parsed_url.is_valid())
return DOM::SyntaxError::create("Invalid URL");
- // FIXME: 8. If the async argument is omitted, set async to true, and set username and password to null.
+ // 8. If the async argument is omitted, set async to true, and set username and password to null.
+ // NOTE: This is handled in the overload lacking the async argument.
// 9. If parsedURL’s host is non-null, then:
if (!parsed_url.host().is_null()) {
@@ -537,6 +542,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method, String const&
// 2. Fire an event named readystatechange at this.
set_ready_state(ReadyState::Opened);
}
+
return {};
}