diff options
author | Linus Groh <mail@linusgroh.de> | 2022-11-13 14:47:21 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-14 10:00:11 +0000 |
commit | 93c0c73b9e4dbfcc60cf2096642215901375314f (patch) | |
tree | db0e4bcbd64f3da714fede25c618943398d62b9c /Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | |
parent | bfa378660be6982397540ff9ece73049e4c0b195 (diff) | |
download | serenity-93c0c73b9e4dbfcc60cf2096642215901375314f.zip |
LibWeb: Implement XMLHttpRequest.withCredentials
Diffstat (limited to 'Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 8a09c188b4..6c4f7d48bc 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -624,6 +624,32 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_timeout(u32 timeout) // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-timeout u32 XMLHttpRequest::timeout() const { return m_timeout; } +// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-withcredentials +bool XMLHttpRequest::with_credentials() const +{ + // The withCredentials getter steps are to return this’s cross-origin credentials. + return m_cross_origin_credentials; +} + +// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-withcredentials +WebIDL::ExceptionOr<void> XMLHttpRequest::set_with_credentials(bool with_credentials) +{ + auto& realm = this->realm(); + + // 1. If this’s state is not unsent or opened, then throw an "InvalidStateError" DOMException. + if (m_state != State::Unsent && m_state != State::Opened) + return WebIDL::InvalidStateError::create(realm, "XHR readyState is not UNSENT or OPENED"); + + // 2. If this’s send() flag is set, then throw an "InvalidStateError" DOMException. + if (m_send) + return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"); + + // 3. Set this’s cross-origin credentials to the given value. + m_cross_origin_credentials = with_credentials; + + return {}; +} + // https://xhr.spec.whatwg.org/#garbage-collection bool XMLHttpRequest::must_survive_garbage_collection() const { |