mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05:00
LibWeb: Implement XMLHttpRequest.requestType setter according to spec
This commit is contained in:
parent
e448c74736
commit
455167008d
2 changed files with 21 additions and 1 deletions
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
WebIDL::ExceptionOr<void> send(Optional<Fetch::XMLHttpRequestBodyInit> body);
|
||||
|
||||
WebIDL::ExceptionOr<void> set_request_header(String const& header, String const& value);
|
||||
void set_response_type(Bindings::XMLHttpRequestResponseType type) { m_response_type = type; }
|
||||
WebIDL::ExceptionOr<void> set_response_type(Bindings::XMLHttpRequestResponseType);
|
||||
|
||||
String get_response_header(String const& name) { return m_response_headers.get(name).value_or({}); }
|
||||
String get_all_response_headers() const;
|
||||
|
|
Loading…
Reference in a new issue