mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibWeb: Add XMLHttpRequest::timeout setter and getter
This commit is contained in:
parent
1e1d59cc25
commit
8b42c05648
3 changed files with 24 additions and 0 deletions
|
@ -693,4 +693,23 @@ DOM::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
|
|||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#ref-for-dom-xmlhttprequest-timeout%E2%91%A2
|
||||
DOM::ExceptionOr<void> XMLHttpRequest::set_timeout(u32 timeout)
|
||||
{
|
||||
// 1. If the current global object is a Window object and this’s synchronous flag is set,
|
||||
// then throw an "InvalidAccessError" DOMException.
|
||||
auto& global_object = wrapper()->global_object();
|
||||
if (global_object.class_name() == "WindowObject" && m_synchronous)
|
||||
return DOM::InvalidAccessError::create("Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context.");
|
||||
|
||||
// 2. Set this’s timeout to the given value.
|
||||
m_timeout = timeout;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-timeout
|
||||
u32 XMLHttpRequest::timeout() const { return m_timeout; }
|
||||
|
||||
}
|
||||
|
|
|
@ -71,6 +71,9 @@ public:
|
|||
|
||||
DOM::ExceptionOr<void> override_mime_type(String const& mime);
|
||||
|
||||
DOM::ExceptionOr<void> set_timeout(u32 timeout);
|
||||
u32 timeout() const;
|
||||
|
||||
private:
|
||||
virtual void ref_event_target() override { ref(); }
|
||||
virtual void unref_event_target() override { unref(); }
|
||||
|
@ -96,6 +99,7 @@ private:
|
|||
ReadyState m_ready_state { ReadyState::Unsent };
|
||||
unsigned m_status { 0 };
|
||||
bool m_send { false };
|
||||
u32 m_timeout { 0 };
|
||||
|
||||
String m_method;
|
||||
AK::URL m_url;
|
||||
|
|
|
@ -25,6 +25,7 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget {
|
|||
readonly attribute DOMString responseText;
|
||||
readonly attribute any response;
|
||||
attribute XMLHttpRequestResponseType responseType;
|
||||
attribute unsigned long timeout;
|
||||
|
||||
undefined open(DOMString method, DOMString url);
|
||||
undefined open(ByteString method, USVString url, boolean async, optional USVString? username = {}, optional USVString? password = {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue