Skip to content

Truly independent web browser

Everywhere: Make Utf16View’s StringView constructor consteval

sideshowbarkerf22403b50ea4
diff --git a/AK/Utf16StringBuilder.cpp b/AK/Utf16StringBuilder.cpp
index 3adbdbb9fd0..d154d500632 100644
--- a/AK/Utf16StringBuilder.cpp
+++ b/AK/Utf16StringBuilder.cpp
@@ -310,7 +310,12 @@ void Utf16StringBuilder::append_ascii_without_validation(ReadonlyBytes string)
void Utf16StringBuilder::append_quoted_escaped_for_json(StringView string)
{
- append_quoted_escaped_for_json(Utf16View { string });
+ if (string.is_ascii()) {
+ append_quoted_escaped_for_json(Utf16View::from_ascii(string));
+ return;
+ }
+ auto utf16_string = Utf16String::from_wtf8_with_replacement_character(string);
+ append_quoted_escaped_for_json(utf16_string.utf16_view());
}
void Utf16StringBuilder::append_quoted_escaped_for_json(Utf16View const& string)
@@ -470,7 +475,10 @@ ErrorOr<void> Utf16StringBuilder::try_append(Utf16View const& view)
ErrorOr<void> Utf16StringBuilder::try_append_escaped_for_json(StringView string)
{
- return try_append_escaped_for_json(Utf16View { string });
+ if (string.is_ascii())
+ return try_append_escaped_for_json(Utf16View::from_ascii(string));
+ auto utf16_string = Utf16String::from_wtf8_with_replacement_character(string);
+ return try_append_escaped_for_json(utf16_string.utf16_view());
}
ErrorOr<void> Utf16StringBuilder::try_append_escaped_for_json(Utf16View const& string)
diff --git a/AK/Utf16View.h b/AK/Utf16View.h
index 334e278ff42..7b1b5396b8f 100644
--- a/AK/Utf16View.h
+++ b/AK/Utf16View.h
@@ -165,13 +165,23 @@ public:
m_length_in_code_units |= 1uz << Detail::UTF16_FLAG;
}
- constexpr Utf16View(StringView string)
+ // A view of ASCII text known at compile time, such as a string literal. Use from_ascii() for text known only at run
+ // time.
+ consteval Utf16View(StringView string)
: m_string { .latin1 = string.characters_without_null_termination() }
, m_length_in_code_units(string.length())
{
VERIFY(all_of(string, AK::is_ascii));
}
+ // A view of text that holds nothing but ASCII, one code unit per byte. Text that may hold anything else has to be
+ // converted to UTF-16 instead.
+ static constexpr Utf16View from_ascii(StringView string)
+ {
+ VERIFY(all_of(string, AK::is_ascii));
+ return { string.characters_without_null_termination(), string.length(), true };
+ }
+
// A view of Latin-1 bytes, one per code unit. Unless is_ascii is set, they may include code units above U+007F.
static ALWAYS_INLINE Utf16View from_latin1(ReadonlyBytes bytes, bool is_ascii)
{
@@ -278,7 +288,7 @@ public:
return StringView { ascii_span().data(), length_in_code_units() } == other;
if (other.is_ascii())
- return *this == Utf16View { other };
+ return *this == Utf16View { other.characters_without_null_termination(), other.length(), true };
Utf8View other_utf8 { other };
diff --git a/Libraries/LibUnicode/IntlExports.cpp b/Libraries/LibUnicode/IntlExports.cpp
index 82b16d453cb..a06eecb7be3 100644
--- a/Libraries/LibUnicode/IntlExports.cpp
+++ b/Libraries/LibUnicode/IntlExports.cpp
@@ -115,7 +115,7 @@ extern "C" bool unicode_parse_unicode_locale_id(UnicodeIntlText locale, void* co
},
[&](Unicode::OtherExtension const& other_extension) {
char key[] = { other_extension.key };
- append_locale_id_part(context, append_part, UnicodeLocaleIDPart::OtherExtensionKey, Utf16View { StringView { key, 1 } });
+ append_locale_id_part(context, append_part, UnicodeLocaleIDPart::OtherExtensionKey, Utf16View::from_ascii(StringView { key, 1 }));
append_locale_id_part(context, append_part, UnicodeLocaleIDPart::OtherExtensionValue, other_extension.value.utf16_view());
});
}
diff --git a/Libraries/LibUnicode/Segmenter.cpp b/Libraries/LibUnicode/Segmenter.cpp
index 2c46e73a66f..fea894b56c0 100644
--- a/Libraries/LibUnicode/Segmenter.cpp
+++ b/Libraries/LibUnicode/Segmenter.cpp
@@ -838,7 +838,7 @@ extern "C" void* unicode_layout_line_segmenter_create(u16 const* text, size_t le
ascii_storage.unchecked_append(static_cast<char>(text[index]));
auto ascii_view = ascii_storage.is_empty()
? Utf16View {}
- : Utf16View { StringView { ascii_storage.data(), ascii_storage.size() } };
+ : Utf16View::from_ascii(StringView { ascii_storage.data(), ascii_storage.size() });
if (auto segmenter = Unicode::Segmenter::try_create_for_ascii_line(ascii_view)) {
return new UnicodeLayoutSegmenterHandle {
.segmenter = segmenter.release_nonnull(),
diff --git a/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
index d1a0a269ab8..013b014492f 100644
--- a/Libraries/LibWeb/Bindings/MainThreadVM.cpp
+++ b/Libraries/LibWeb/Bindings/MainThreadVM.cpp
@@ -158,7 +158,7 @@ void initialize_main_thread_vm(HTML::AgentType type)
main_thread_vm_ptr()->host_ensure_can_add_private_element = [](JS::Object const& object) -> JS::ThrowCompletionOr<void> {
// 1. If O is a WindowProxy object, or implements Location, then return ThrowCompletion(a new TypeError).
if (HTML::WindowProxy::from_object(object) || impl_from<HTML::Location>(&object))
- return main_thread_vm_ptr()->throw_completion<JS::TypeError>("Cannot add private elements to window or location object"sv);
+ return main_thread_vm_ptr()->throw_completion<JS::TypeError>(u"Cannot add private elements to window or location object"sv);
// 2. Return NormalCompletion(unused).
return {};
diff --git a/Libraries/LibWeb/CSS/PropertyName.h b/Libraries/LibWeb/CSS/PropertyName.h
index 1092fee6fd1..045d028e8a0 100644
--- a/Libraries/LibWeb/CSS/PropertyName.h
+++ b/Libraries/LibWeb/CSS/PropertyName.h
@@ -24,6 +24,13 @@ inline bool is_a_custom_property_name_string(Utf16View string)
&& string.code_unit_at(1) == '-';
}
+// The same check, on UTF-8 text: A name longer than its two dashes in code units is longer in bytes too, and the other
+// way round.
+inline bool is_a_custom_property_name_string(StringView string)
+{
+ return string.length() > 2 && string[0] == '-' && string[1] == '-';
+}
+
// https://drafts.css-houdini.org/css-typed-om-1/#valid-css-property
inline bool is_a_valid_css_property(Utf16FlyString const& string)
{
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
index c8a11855f51..ea7f2ecd925 100644
--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
@@ -2544,8 +2544,8 @@ void record_element_directionality(DOM::Element& element)
if (!style_engine)
return;
- auto const directionality = element.directionality() == DOM::Element::Directionality::Rtl ? "rtl"sv : "ltr"sv;
- StyleEngineFFI::style_engine_set_element_directionality(style_engine->host(), element.style_node_id(), style_engine->intern_text_atom(Utf16View { directionality }));
+ auto const directionality = element.directionality() == DOM::Element::Directionality::Rtl ? u"rtl"sv : u"ltr"sv;
+ StyleEngineFFI::style_engine_set_element_directionality(style_engine->host(), element.style_node_id(), style_engine->intern_text_atom(directionality));
}
void record_element_custom_states_changed(DOM::Element& element)
diff --git a/Libraries/LibWeb/CookieStore/CookieStore.cpp b/Libraries/LibWeb/CookieStore/CookieStore.cpp
index 69b7bd6d91b..dc06c497a0a 100644
--- a/Libraries/LibWeb/CookieStore/CookieStore.cpp
+++ b/Libraries/LibWeb/CookieStore/CookieStore.cpp
@@ -167,7 +167,7 @@ static GC::Ref<CookieListCompletionSteps> create_cookie_list_completion_steps(JS
});
}
-static GC::Ref<CookieMutationCompletionSteps> create_cookie_mutation_completion_steps(JS::Object& global, GC::Ref<WebIDL::Promise> promise, StringView failure_message)
+static GC::Ref<CookieMutationCompletionSteps> create_cookie_mutation_completion_steps(JS::Object& global, GC::Ref<WebIDL::Promise> promise, Utf16View failure_message)
{
return GC::Function<void(bool)>::create(GC::Heap::the(), [global = GC::Ref { global }, promise, failure_message](bool result) {
// NB: The UI's notification of this mutation's cookie changes is handled from a deferred invocation scheduled while
@@ -549,7 +549,7 @@ GC::Ref<WebIDL::Promise> CookieStore::set(JS::Realm& realm, CookieInit const& op
if (!url.has_value())
return promise;
- set(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, "Name, value, domain or path are malformed"sv));
+ set(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, u"Name, value, domain or path are malformed"sv));
return promise;
}
@@ -569,7 +569,7 @@ GC::Ref<WebIDL::Promise> CookieStore::set(JS::Realm& realm, Utf16String name, Ut
if (!url.has_value())
return promise;
- set(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, "Name or value are malformed"sv));
+ set(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, u"Name or value are malformed"sv));
return promise;
}
@@ -613,7 +613,7 @@ GC::Ref<WebIDL::Promise> CookieStore::delete_(JS::Realm& realm, CookieStoreDelet
if (!url.has_value())
return promise;
- delete_(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, "Name is malformed"sv));
+ delete_(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, u"Name is malformed"sv));
return promise;
}
@@ -630,7 +630,7 @@ GC::Ref<WebIDL::Promise> CookieStore::delete_(JS::Realm& realm, Utf16String name
if (!url.has_value())
return promise;
- delete_(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, "Name is malformed"sv));
+ delete_(HTML::principal_realm_settings_object(realm).id, url.release_value(), options, create_cookie_mutation_completion_steps(realm.global_object(), promise, u"Name is malformed"sv));
return promise;
}
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 9e034925099..25e5abdb284 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -6410,7 +6410,7 @@ bool is_a_registrable_domain_suffix_of_or_is_equal_to(URL::Host const& host_suff
auto const& original_host_string = original_host.get<String>();
// 2. If hostSuffix, prefixed by U+002E (.), does not match the end of originalHost, then return false.
- if (!ends_with_dot_prefixed_suffix(Utf16View { original_host_string.bytes_as_string_view() }, Utf16View { host_suffix_string.bytes_as_string_view() }))
+ if (!ends_with_dot_prefixed_suffix(Utf16View::from_ascii(original_host_string.bytes_as_string_view()), Utf16View::from_ascii(host_suffix_string.bytes_as_string_view())))
return false;
// 3. If any of the following are true:
@@ -6423,11 +6423,11 @@ bool is_a_registrable_domain_suffix_of_or_is_equal_to(URL::Host const& host_suff
auto original_host_public_suffix = original_host.public_suffix();
VERIFY(original_host_public_suffix.has_value());
- if (ends_with_dot_prefixed_suffix(Utf16View { original_host_public_suffix->bytes_as_string_view() }, Utf16View { host_suffix_string.bytes_as_string_view() }))
+ if (ends_with_dot_prefixed_suffix(Utf16View::from_ascii(original_host_public_suffix->bytes_as_string_view()), Utf16View::from_ascii(host_suffix_string.bytes_as_string_view())))
return false;
// 4. Assert: originalHost's public suffix, prefixed by U+002E (.), matches the end of hostSuffix.
- VERIFY(ends_with_dot_prefixed_suffix(Utf16View { host_suffix_string.bytes_as_string_view() }, Utf16View { original_host_public_suffix->bytes_as_string_view() }));
+ VERIFY(ends_with_dot_prefixed_suffix(Utf16View::from_ascii(host_suffix_string.bytes_as_string_view()), Utf16View::from_ascii(original_host_public_suffix->bytes_as_string_view())));
}
// 5. Return true.
diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
index c673fb2422c..24aa25b1fe1 100644
--- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
+++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
@@ -1001,18 +1001,18 @@ struct ResolvedWhiteSpace {
&& first_is_one_of(*collapse, CSS::Keyword::Preserve, CSS::Keyword::PreserveBreaks, CSS::Keyword::BreakSpaces);
}
- Optional<StringView> white_space_value() const
+ Optional<Utf16View> white_space_value() const
{
if (!collapse.has_value() || !wrap_mode.has_value())
return {};
auto nowrap = *wrap_mode == CSS::Keyword::Nowrap;
switch (*collapse) {
case CSS::Keyword::Collapse:
- return nowrap ? "nowrap"sv : "normal"sv;
+ return nowrap ? u"nowrap"sv : u"normal"sv;
case CSS::Keyword::Preserve:
- return nowrap ? "pre"sv : "pre-wrap"sv;
+ return nowrap ? u"pre"sv : u"pre-wrap"sv;
case CSS::Keyword::PreserveBreaks:
- return nowrap ? OptionalNone {} : Optional<StringView> { "pre-line"sv };
+ return nowrap ? OptionalNone {} : Optional<Utf16View> { u"pre-line"sv };
default:
return {};
}
diff --git a/Libraries/LibWeb/HTML/CustomElements/CustomElementAlgorithms.cpp b/Libraries/LibWeb/HTML/CustomElements/CustomElementAlgorithms.cpp
index 9852b1e2f22..83d72acf6a8 100644
--- a/Libraries/LibWeb/HTML/CustomElements/CustomElementAlgorithms.cpp
+++ b/Libraries/LibWeb/HTML/CustomElements/CustomElementAlgorithms.cpp
@@ -186,7 +186,7 @@ JS::ThrowCompletionOr<void> upgrade_custom_element(DOM::Element& element, GC::Re
// 4. If SameValue(constructResult, element) is false, then throw a TypeError.
if (!JS::same_value(construct_result, element_wrapper.ptr()))
- return vm.throw_completion<JS::TypeError>("Constructing the custom element returned a different element from the custom element"sv);
+ return vm.throw_completion<JS::TypeError>(u"Constructing the custom element returned a different element from the custom element"sv);
return {};
};
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index 5520e582798..abc22663b2f 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -3200,7 +3200,7 @@ Utf16String HTMLInputElement::convert_number_to_string(double input) const
}
// https://html.spec.whatwg.org/multipage/input.html#concept-input-value-string-date
-WebIDL::ExceptionOr<Optional<double>> HTMLInputElement::convert_string_to_date(StringView input) const
+WebIDL::ExceptionOr<Optional<double>> HTMLInputElement::convert_string_to_date(Utf16View input) const
{
// https://html.spec.whatwg.org/multipage/input.html#date-state-(type=date):concept-input-value-string-date
if (type_state() == TypeAttributeState::Date) {
@@ -3256,7 +3256,7 @@ WebIDL::ExceptionOr<Optional<double>> HTMLInputElement::convert_string_to_date(U
// FIXME: Implement a UTF-16 GenericLexer.
if (!input.has_ascii_storage())
return Optional<double> {};
- return convert_string_to_date(input.ascii_view());
+ return convert_string_to_date(input.utf16_view());
}
// https://html.spec.whatwg.org/multipage/input.html#concept-input-value-date-string
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h
index 24d10cd9cab..af0c0712b08 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.h
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.h
@@ -356,7 +356,7 @@ private:
Optional<double> convert_string_to_number(Utf16View input) const;
Utf16String convert_number_to_string(double input) const;
- WebIDL::ExceptionOr<Optional<double>> convert_string_to_date(StringView input) const;
+ WebIDL::ExceptionOr<Optional<double>> convert_string_to_date(Utf16View input) const;
WebIDL::ExceptionOr<Optional<double>> convert_string_to_date(Utf16String const& input) const;
Utf16String convert_date_to_string(double input) const;
diff --git a/Libraries/LibWeb/HTML/MediaControls.cpp b/Libraries/LibWeb/HTML/MediaControls.cpp
index 4bfaae9b2e1..800bb47c5d9 100644
--- a/Libraries/LibWeb/HTML/MediaControls.cpp
+++ b/Libraries/LibWeb/HTML/MediaControls.cpp
@@ -821,7 +821,7 @@ void MediaControls::update_placeholder_visibility()
if (!m_dom->placeholder_circle)
return;
- auto display = should_show_placeholder() ? "flex"sv : "none"sv;
+ auto display = should_show_placeholder() ? u"flex"sv : u"none"sv;
MUST(m_dom->placeholder_circle->style()->set_property(CSS::PropertyID::Display, display));
}
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index 9b55fc806d2..fbd59c77f9d 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -2255,7 +2255,7 @@ Utf16String HTMLParser::serialize_html_fragment(DOM::Node const& node, Serializa
builder.append_ascii("<template shadowrootmode=\""sv);
// 2. If shadow's mode is "open", then append "open". Otherwise, append "closed".
- builder.append(shadow->mode() == Web::DOM::ShadowRootMode::Open ? "open"sv : "closed"sv);
+ builder.append_ascii(shadow->mode() == Web::DOM::ShadowRootMode::Open ? "open"sv : "closed"sv);
// 3. Append """.
builder.append_ascii('"');
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp
index 2257c0739b3..2de1b4acd78 100644
--- a/Libraries/LibWeb/Internals/Internals.cpp
+++ b/Libraries/LibWeb/Internals/Internals.cpp
@@ -1595,7 +1595,7 @@ static void define_scroller_properties(HTML::Window& window, JS::Object& object,
object.define_direct_property("scroller"_utf16_fly_string, wrapped_node_with_unique_id(window, scroller.map([](auto const& id) { return id.node_id; })), JS::default_attributes);
if (scroller.has_value() && scroller->kind == AsyncScrollNodeKind::PseudoElement) {
auto pseudo_element = CSS::pseudo_element_name(static_cast<CSS::PseudoElement>(scroller->pseudo_element_type));
- object.define_direct_property("scrollerPseudoElement"_utf16_fly_string, JS::PrimitiveString::create(vm, pseudo_element), JS::default_attributes);
+ object.define_direct_property("scrollerPseudoElement"_utf16_fly_string, JS::PrimitiveString::create(vm, Utf16View::from_ascii(pseudo_element)), JS::default_attributes);
}
}
@@ -1608,8 +1608,8 @@ GC::Ref<JS::Object> Internals::take_input_trace()
auto const& record = records[i];
auto object = JS::Object::create(realm, nullptr);
object->define_direct_property("id"_utf16_fly_string, JS::Value(static_cast<double>(record.input_event_id)), JS::default_attributes);
- object->define_direct_property("stage"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_trace_stage_name(record.stage)), JS::default_attributes);
- object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_routing_decision_name(record.decision)), JS::default_attributes);
+ object->define_direct_property("stage"_utf16_fly_string, JS::PrimitiveString::create(vm(), Utf16View::from_ascii(input_trace_stage_name(record.stage))), JS::default_attributes);
+ object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), Utf16View::from_ascii(input_routing_decision_name(record.decision))), JS::default_attributes);
define_scroller_properties(window(), *object, record.scroller);
object->define_direct_property("target"_utf16_fly_string, wrapped_node_with_unique_id(window(), record.dom_target), JS::default_attributes);
MUST(array->create_data_property_or_throw(i, object));
@@ -1621,7 +1621,7 @@ GC::Ref<JS::Object> Internals::first_wheel_step_route_to_object(Compositing::Fir
{
auto& realm = HTML::relevant_realm(window());
auto object = JS::Object::create(realm, nullptr);
- object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), input_routing_decision_name(result.route.decision)), JS::default_attributes);
+ object->define_direct_property("decision"_utf16_fly_string, JS::PrimitiveString::create(vm(), Utf16View::from_ascii(input_routing_decision_name(result.route.decision))), JS::default_attributes);
define_scroller_properties(window(), *object, result.route.scroller);
object->define_direct_property("document"_utf16_fly_string, wrapped_node_with_unique_id(window(), result.document_id), JS::default_attributes);
return object;
diff --git a/Libraries/LibWeb/WebAudio/AudioWorkletProcessor.cpp b/Libraries/LibWeb/WebAudio/AudioWorkletProcessor.cpp
index af6e47f6d38..4dddc6c37c0 100644
--- a/Libraries/LibWeb/WebAudio/AudioWorkletProcessor.cpp
+++ b/Libraries/LibWeb/WebAudio/AudioWorkletProcessor.cpp
@@ -23,11 +23,11 @@ WebIDL::ExceptionOr<GC::Ref<AudioWorkletProcessor>> AudioWorkletProcessor::const
// pending processor construction data, and a TypeError must be thrown.
auto* global_scope = Bindings::impl_from<AudioWorkletGlobalScope>(&realm.global_object());
if (!global_scope)
- return realm.vm().throw_completion<JS::TypeError>("AudioWorkletProcessor can only be constructed in an AudioWorkletGlobalScope"sv);
+ return realm.vm().throw_completion<JS::TypeError>(u"AudioWorkletProcessor can only be constructed in an AudioWorkletGlobalScope"sv);
auto pending_data = global_scope->take_pending_processor_construction_data();
if (!pending_data.has_value())
- return realm.vm().throw_completion<JS::TypeError>("AudioWorkletProcessor cannot be constructed directly; it is instantiated by AudioWorkletNode"sv);
+ return realm.vm().throw_completion<JS::TypeError>(u"AudioWorkletProcessor cannot be constructed directly; it is instantiated by AudioWorkletNode"sv);
// 2. Set this's port to the pending construction data's transferred port.
return GC::Heap::the().allocate<AudioWorkletProcessor>(*global_scope, pending_data->port);
diff --git a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py b/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
index c0b93c421b8..6799f5b0e01 100644
--- a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
+++ b/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
@@ -317,11 +317,11 @@ def svg_list_indexed_property_setter_conversion(
value_type = fully_qualified_name_for_interface(value_interface)
return f"""[&]() -> JS::ThrowCompletionOr<GC::Ref<{value_type}>> {{
if (!value.is_object())
- return vm.throw_completion<JS::TypeError>("Value must be an {value_parameter.type.name}"sv);
+ return vm.throw_completion<JS::TypeError>(u"Value must be an {value_parameter.type.name}"sv);
if (auto* impl = Web::Bindings::impl_from<{value_type}>(&value.as_object()))
return GC::Ref {{ *impl }};
- return vm.throw_completion<JS::TypeError>("Value must be an {value_parameter.type.name}"sv);
+ return vm.throw_completion<JS::TypeError>(u"Value must be an {value_parameter.type.name}"sv);
}}()"""
diff --git a/Tests/AK/TestUtf16StringBuilder.cpp b/Tests/AK/TestUtf16StringBuilder.cpp
index b76efd1fea7..e001e0a9bbc 100644
--- a/Tests/AK/TestUtf16StringBuilder.cpp
+++ b/Tests/AK/TestUtf16StringBuilder.cpp
@@ -75,6 +75,19 @@ TEST_CASE(append_quoted_escaped_for_json)
widened_builder.append_quoted_escaped_for_json("ascii"sv);
EXPECT_EQ(widened_builder.view(), u"\u263A\"ascii\""sv);
+ Utf16StringBuilder utf8_builder;
+ utf8_builder.append_quoted_escaped_for_json("caf\xc3\xa9 \xe2\x98\xba"sv);
+ EXPECT_EQ(utf8_builder.view(), u"\"caf\u00e9 \u263A\""sv);
+
+ // A lone surrogate in WTF-8 is decoded as a single replacement character.
+ Utf16StringBuilder wtf8_surrogate_builder;
+ wtf8_surrogate_builder.append_quoted_escaped_for_json("\xed\xa0\x80"sv);
+ EXPECT_EQ(wtf8_surrogate_builder.view(), u"\"\ufffd\""sv);
+
+ Utf16StringBuilder unquoted_utf8_builder;
+ unquoted_utf8_builder.append_escaped_for_json("caf\xc3\xa9\n"sv);
+ EXPECT_EQ(unquoted_utf8_builder.view(), u"caf\u00e9\\n"sv);
+
char16_t lone_surrogate = 0xd800;
Utf16StringBuilder surrogate_builder;
surrogate_builder.append_quoted_escaped_for_json(Utf16View { &lone_surrogate, 1 });
diff --git a/Tests/AK/TestUtf16View.cpp b/Tests/AK/TestUtf16View.cpp
index 225923582c3..059123df7b2 100644
--- a/Tests/AK/TestUtf16View.cpp
+++ b/Tests/AK/TestUtf16View.cpp
@@ -906,7 +906,7 @@ TEST_CASE(find_code_unit_offset_nul_at_any_alignment)
ascii_buffer.fill('A');
for (size_t start_offset = 0; start_offset < 64; ++start_offset) {
- Utf16View view { StringView { ascii_buffer.data() + start_offset, 6 } };
+ auto view = Utf16View::from_ascii(StringView { ascii_buffer.data() + start_offset, 6 });
EXPECT(!view.find_code_unit_offset(u'\0').has_value());
EXPECT(!view.contains(u'\0'));
}