LibIDL+LibWeb: Support UTF-16 USVString

This commit is contained in:
Timothy Flynn 2025-07-25 15:56:36 -04:00 committed by Jelle Raaijmakers
commit 49467d0583
Notes: github-actions[bot] 2025-07-25 22:41:48 +00:00
4 changed files with 9 additions and 3 deletions

View file

@ -119,7 +119,7 @@ public:
// https://webidl.spec.whatwg.org/#idl-symbol
bool is_symbol() const { return is_plain() && m_name == "symbol"; }
bool is_string() const { return is_plain() && m_name.is_one_of("ByteString", "CSSOMString", "DOMString", "Utf16DOMString", "USVString"); }
bool is_string() const { return is_plain() && m_name.is_one_of("ByteString", "CSSOMString", "DOMString", "Utf16DOMString", "USVString", "Utf16USVString"); }
// https://webidl.spec.whatwg.org/#dfn-integer-type
bool is_integer() const { return is_plain() && m_name.is_one_of("byte", "octet", "short", "unsigned short", "long", "unsigned long", "long long", "unsigned long long"); }

View file

@ -244,6 +244,11 @@ JS::ThrowCompletionOr<String> to_usv_string(JS::VM& vm, JS::Value value)
return TRY(value.to_utf16_string(vm)).to_well_formed_utf8();
}
JS::ThrowCompletionOr<Utf16String> to_utf16_usv_string(JS::VM& vm, JS::Value value)
{
return TRY(value.to_utf16_string(vm)).to_well_formed();
}
// https://webidl.spec.whatwg.org/#invoke-a-callback-function
// https://whatpr.org/webidl/1437.html#invoke-a-callback-function
template<typename ReturnSteps>

View file

@ -25,6 +25,7 @@ JS::Completion call_user_object_operation(CallbackType& callback, String const&
JS::ThrowCompletionOr<String> to_string(JS::VM&, JS::Value);
JS::ThrowCompletionOr<Utf16String> to_utf16_string(JS::VM&, JS::Value);
JS::ThrowCompletionOr<String> to_usv_string(JS::VM&, JS::Value);
JS::ThrowCompletionOr<Utf16String> to_utf16_usv_string(JS::VM&, JS::Value);
JS::ThrowCompletionOr<String> to_byte_string(JS::VM&, JS::Value);
enum class ExceptionBehavior {

View file

@ -426,8 +426,8 @@ static void generate_to_string(SourceGenerator& scoped_generator, ParameterType
scoped_generator.set("string_suffix", "_string"sv);
}
if (parameter.type->name() == "USVString")
scoped_generator.set("to_string", "to_usv_string"sv);
if (parameter.type->name().is_one_of("USVString"sv, "Utf16USVString"sv))
scoped_generator.set("to_string", is_utf16_string ? "to_utf16_usv_string"sv : "to_usv_string"sv);
else if (parameter.type->name() == "ByteString")
scoped_generator.set("to_string", "to_byte_string"sv);
else