LibJS+LibWeb: Port interned bytecode strings to UTF-16

This was almost a no-op, except we intern JS exception messages. So the
bulk of this patch is porting exception messages to UTF-16.
This commit is contained in:
Timothy Flynn 2025-08-07 19:31:52 -04:00 committed by Jelle Raaijmakers
commit 70db474cf0
Notes: github-actions[bot] 2025-08-14 08:28:16 +00:00
162 changed files with 1405 additions and 1422 deletions

View file

@ -119,7 +119,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\""_string);
return WebIDL::InvalidStateError::create(realm(), "XHR responseText can only be used for responseType \"\" or \"text\""_utf16);
// 2. If thiss state is not loading or done, then return the empty string.
if (m_state != State::Loading && m_state != State::Done)
@ -134,7 +134,7 @@ WebIDL::ExceptionOr<GC::Ptr<DOM::Document>> XMLHttpRequest::response_xml()
{
// 1. If thiss response type is not the empty string or "document", then throw an "InvalidStateError" DOMException.
if (m_response_type != Bindings::XMLHttpRequestResponseType::Empty && m_response_type != Bindings::XMLHttpRequestResponseType::Document)
return WebIDL::InvalidStateError::create(realm(), "XHR responseXML can only be used for responseXML \"\" or \"document\""_string);
return WebIDL::InvalidStateError::create(realm(), "XHR responseXML can only be used for responseXML \"\" or \"document\""_utf16);
// 2. If thiss state is not done, then return null.
if (m_state != State::Done)
@ -165,11 +165,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"_string);
return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done"_utf16);
// 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_principal_global_object()) && m_synchronous)
return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_string);
return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_utf16);
// 4. Set thiss response type to the given value.
m_response_type = response_type;
@ -421,20 +421,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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED"_utf16);
// 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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_utf16);
// 3. Normalize value.
auto normalized_value = 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."_string);
return WebIDL::SyntaxError::create(realm, "Header name contains invalid characters."_utf16);
if (!Fetch::Infrastructure::is_header_value(normalized_value))
return WebIDL::SyntaxError::create(realm, "Header value contains invalid characters."_string);
return WebIDL::SyntaxError::create(realm, "Header value contains invalid characters."_utf16);
auto header = Fetch::Infrastructure::Header {
.name = MUST(ByteBuffer::copy(name)),
@ -466,16 +466,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."_string);
return WebIDL::InvalidStateError::create(realm(), "Invalid state: Window's associated document is not fully active."_utf16);
}
// 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."_string);
return WebIDL::SyntaxError::create(realm(), "An invalid or illegal string was specified."_utf16);
// 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'"_string);
return WebIDL::SecurityError::create(realm(), "Forbidden method, must not be 'CONNECT', 'TRACE', or 'TRACK'"_utf16);
// 4. Normalize method.
auto normalized_method = Fetch::Infrastructure::normalize_method(method);
@ -488,7 +488,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
// 6. If parsedURL is failure, then throw a "SyntaxError" DOMException.
if (!parsed_url.has_value())
return WebIDL::SyntaxError::create(realm(), "Invalid URL"_string);
return WebIDL::SyntaxError::create(realm(), "Invalid URL"_utf16);
// 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.
@ -508,7 +508,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
if (!async
&& is<HTML::Window>(HTML::current_principal_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"_string);
return WebIDL::InvalidAccessError::create(realm(), "Synchronous XMLHttpRequests in a Window context do not support timeout or a non-empty responseType"_utf16);
}
// 10. Terminate thiss fetch controller.
@ -556,11 +556,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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not OPENED"_utf16);
// 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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_utf16);
// 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))
@ -1034,7 +1034,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."_string);
return WebIDL::InvalidStateError::create(realm(), "Cannot override MIME type when state is Loading or Done."_utf16);
// 2. Set thiss override MIME type to the result of parsing mime.
m_override_mime_type = MimeSniff::MimeType::parse(mime);
@ -1052,7 +1052,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_principal_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."_string);
return WebIDL::InvalidAccessError::create(realm(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."_utf16);
// 2. Set thiss timeout to the given value.
m_timeout = timeout;
@ -1077,11 +1077,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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR readyState is not UNSENT or OPENED"_utf16);
// 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"_string);
return WebIDL::InvalidStateError::create(realm, "XHR send() flag is already set"_utf16);
// 3. Set thiss cross-origin credentials to the given value.
m_cross_origin_credentials = with_credentials;
@ -1223,15 +1223,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"_string)));
return TRY(request_error_steps(EventNames::timeout, WebIDL::TimeoutError::create(realm(), "Timed out"_utf16)));
// 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"_string)));
return TRY(request_error_steps(EventNames::abort, WebIDL::AbortError::create(realm(), "Aborted"_utf16)));
// 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"_string)));
return TRY(request_error_steps(EventNames::error, WebIDL::NetworkError::create(realm(), "Network error"_utf16)));
return {};
}