diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-24 15:30:54 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-24 18:06:55 +0200 |
commit | 455167008d19bc32b48b66a7985486ffade71607 (patch) | |
tree | f07d064feb3612afe03b4b0a511d5f07ea6010cb /Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | |
parent | e448c74736e7693677b36c9ef9bc90655c613dfe (diff) | |
download | serenity-455167008d19bc32b48b66a7985486ffade71607.zip |
LibWeb: Implement XMLHttpRequest.requestType setter according to spec
Diffstat (limited to 'Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index e622477d62..8ea8645172 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -95,6 +95,26 @@ WebIDL::ExceptionOr<String> XMLHttpRequest::response_text() const return get_text_response(); } +// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-responsetype +WebIDL::ExceptionOr<void> XMLHttpRequest::set_response_type(Bindings::XMLHttpRequestResponseType response_type) +{ + // 1. If the current global object is not a Window object and the given value is "document", then return. + if (!is<HTML::Window>(HTML::current_global_object()) && response_type == Bindings::XMLHttpRequestResponseType::Document) + return {}; + + // 2. If this’s state is loading or done, then throw an "InvalidStateError" DOMException. + if (m_ready_state == ReadyState::Loading || m_ready_state == ReadyState::Done) + return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done"); + + // 3. If the current global object is a Window object and this’s synchronous flag is set, then throw an "InvalidAccessError" DOMException. + if (is<HTML::Window>(HTML::current_global_object()) && m_synchronous) + return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"); + + // 4. Set this’s response type to the given value. + m_response_type = response_type; + return {}; +} + // https://xhr.spec.whatwg.org/#response WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response() { |