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

LibWeb: Port DOMException interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-06 16:03:01 +12:00 committed by Tim Flynn
parent bcb6851c07
commit 41928c2902
65 changed files with 296 additions and 296 deletions

View file

@ -109,7 +109,7 @@ WebIDL::ExceptionOr<String> XMLHttpRequest::response_text() const
{
// 1. If thiss response type is not the empty string or "text", then throw an "InvalidStateError" DOMException.
if (m_response_type != Bindings::XMLHttpRequestResponseType::Empty && m_response_type != Bindings::XMLHttpRequestResponseType::Text)
return WebIDL::InvalidStateError::create(realm(), "XHR responseText can only be used for responseType \"\" or \"text\"");
return WebIDL::InvalidStateError::create(realm(), "XHR responseText can only be used for responseType \"\" or \"text\""_fly_string);
// 2. If thiss state is not loading or done, then return the empty string.
if (m_state != State::Loading && m_state != State::Done)
@ -127,11 +127,11 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_response_type(Bindings::XMLHttpReq
// 2. If thiss state is loading or done, then throw an "InvalidStateError" DOMException.
if (m_state == State::Loading || m_state == State::Done)
return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done");
return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done"_fly_string);
// 3. If the current global object is a Window object and thiss 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");
return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_fly_string);
// 4. Set thiss response type to the given value.
m_response_type = response_type;
@ -316,20 +316,20 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name_
// 1. If thiss state is not opened, then throw an "InvalidStateError" DOMException.
if (m_state != State::Opened)
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED");
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED"_fly_string);
// 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");
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_fly_string);
// 3. Normalize value.
auto normalized_value = TRY_OR_THROW_OOM(vm, Fetch::Infrastructure::normalize_header_value(value));
// 4. If name is not a header name or value is not a header value, then throw a "SyntaxError" DOMException.
if (!Fetch::Infrastructure::is_header_name(name))
return WebIDL::SyntaxError::create(realm, "Header name contains invalid characters.");
return WebIDL::SyntaxError::create(realm, "Header name contains invalid characters."_fly_string);
if (!Fetch::Infrastructure::is_header_value(value))
return WebIDL::SyntaxError::create(realm, "Header value contains invalid characters.");
return WebIDL::SyntaxError::create(realm, "Header value contains invalid characters."_fly_string);
auto header = Fetch::Infrastructure::Header {
.name = TRY_OR_THROW_OOM(vm, ByteBuffer::copy(name)),
@ -361,16 +361,16 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
if (is<HTML::Window>(HTML::relevant_global_object(*this))) {
auto const& window = static_cast<HTML::Window const&>(HTML::relevant_global_object(*this));
if (!window.associated_document().is_fully_active())
return WebIDL::InvalidStateError::create(realm(), "Invalid state: Window's associated document is not fully active.");
return WebIDL::InvalidStateError::create(realm(), "Invalid state: Window's associated document is not fully active."_fly_string);
}
// 2. If method is not a method, then throw a "SyntaxError" DOMException.
if (!Fetch::Infrastructure::is_method(method))
return WebIDL::SyntaxError::create(realm(), "An invalid or illegal string was specified.");
return WebIDL::SyntaxError::create(realm(), "An invalid or illegal string was specified."_fly_string);
// 3. If method is a forbidden method, then throw a "SecurityError" DOMException.
if (Fetch::Infrastructure::is_forbidden_method(method))
return WebIDL::SecurityError::create(realm(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'");
return WebIDL::SecurityError::create(realm(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"_fly_string);
// 4. Normalize method.
auto normalized_method = TRY_OR_THROW_OOM(vm(), Fetch::Infrastructure::normalize_method(method));
@ -381,7 +381,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
// 6. If parsedURL is failure, then throw a "SyntaxError" DOMException.
if (!parsed_url.is_valid())
return WebIDL::SyntaxError::create(realm(), "Invalid URL");
return WebIDL::SyntaxError::create(realm(), "Invalid URL"_fly_string);
// 7. If the async argument is omitted, set async to true, and set username and password to null.
// NOTE: This is handled in the overload lacking the async argument.
@ -401,7 +401,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
if (!async
&& is<HTML::Window>(HTML::current_global_object())
&& (m_timeout != 0 || m_response_type != Bindings::XMLHttpRequestResponseType::Empty)) {
return WebIDL::InvalidAccessError::create(realm(), "Synchronous XMLHttpRequests in a Window context do not support timeout or a non-empty responseType");
return WebIDL::InvalidAccessError::create(realm(), "Synchronous XMLHttpRequests in a Window context do not support timeout or a non-empty responseType"_fly_string);
}
// 10. Terminate thiss fetch controller.
@ -449,11 +449,11 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
// 1. If thiss state is not opened, then throw an "InvalidStateError" DOMException.
if (m_state != State::Opened)
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED");
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED"_fly_string);
// 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");
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_fly_string);
// 3. If thiss request method is `GET` or `HEAD`, then set body to null.
if (m_request_method.is_one_of("GET"sv, "HEAD"sv))
@ -917,7 +917,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
// 1. If thiss state is loading or done, then throw an "InvalidStateError" DOMException.
if (m_state == State::Loading || m_state == State::Done)
return WebIDL::InvalidStateError::create(realm(), "Cannot override MIME type when state is Loading or Done.");
return WebIDL::InvalidStateError::create(realm(), "Cannot override MIME type when state is Loading or Done."_fly_string);
// 2. Set thiss override MIME type to the result of parsing mime.
m_override_mime_type = TRY_OR_THROW_OOM(vm, MimeSniff::MimeType::parse(mime));
@ -935,7 +935,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_timeout(u32 timeout)
// 1. If the current global object is a Window object and thiss synchronous flag is set,
// then throw an "InvalidAccessError" DOMException.
if (is<HTML::Window>(HTML::current_global_object()) && m_synchronous)
return WebIDL::InvalidAccessError::create(realm(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context.");
return WebIDL::InvalidAccessError::create(realm(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."_fly_string);
// 2. Set thiss timeout to the given value.
m_timeout = timeout;
@ -960,11 +960,11 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_with_credentials(bool with_credent
// 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");
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not UNSENT or OPENED"_fly_string);
// 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");
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_fly_string);
// 3. Set thiss cross-origin credentials to the given value.
m_cross_origin_credentials = with_credentials;
@ -1107,15 +1107,15 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::handle_errors()
// 2. If xhrs timed out flag is set, then run the request error steps for xhr, timeout, and "TimeoutError" DOMException.
if (m_timed_out)
return TRY(request_error_steps(EventNames::timeout, WebIDL::TimeoutError::create(realm(), "Timed out"sv)));
return TRY(request_error_steps(EventNames::timeout, WebIDL::TimeoutError::create(realm(), "Timed out"_fly_string)));
// 3. Otherwise, if xhrs responses aborted flag is set, run the request error steps for xhr, abort, and "AbortError" DOMException.
if (m_response->aborted())
return TRY(request_error_steps(EventNames::abort, WebIDL::AbortError::create(realm(), "Aborted"sv)));
return TRY(request_error_steps(EventNames::abort, WebIDL::AbortError::create(realm(), "Aborted"_fly_string)));
// 4. Otherwise, if xhrs response is a network error, then run the request error steps for xhr, error, and "NetworkError" DOMException.
if (m_response->is_network_error())
return TRY(request_error_steps(EventNames::error, WebIDL::NetworkError::create(realm(), "Network error"sv)));
return TRY(request_error_steps(EventNames::error, WebIDL::NetworkError::create(realm(), "Network error"_fly_string)));
return {};
}