1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibWeb: Implement XMLHttpRequest.withCredentials

This commit is contained in:
Linus Groh 2022-11-13 14:47:21 +00:00
parent bfa378660b
commit 93c0c73b9e
3 changed files with 35 additions and 2 deletions

View file

@ -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 thiss 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 thiss 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 thiss 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 thiss 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
{