From 55f0dc823ff266aeb29fd6f7d47d5e7f89a50ee6 Mon Sep 17 00:00:00 2001 From: justus2510 Date: Sun, 13 Oct 2024 03:52:16 +0200 Subject: [PATCH] LibWeb: Handle unpaired surrogates in USVStrings This should fix (at least) the last two remaining WPT test failures in FileAPI/unicode.html. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 12 ++++++++---- .../unpaired-surrogates-in-constructor.txt | 2 ++ .../unpaired-surrogates-in-constructor.html | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/FileAPI/unpaired-surrogates-in-constructor.txt create mode 100644 Tests/LibWeb/Text/input/FileAPI/unpaired-surrogates-in-constructor.html diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 51b4fa42cae..abbb39da659 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1414,19 +1414,23 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter )~~~"); } - bool includes_string = false; + RefPtr string_type; for (auto& type : types) { if (type->is_string()) { - includes_string = true; + string_type = type; break; } } - if (includes_string) { + if (string_type) { // 14. If types includes a string type, then return the result of converting V to that type. // NOTE: Currently all string types are converted to String. + + IDL::Parameter parameter { .type = *string_type, .name = ByteString::empty(), .optional_default_value = {}, .extended_attributes = {} }; + generate_to_cpp(union_generator, parameter, js_name, js_suffix, ByteString::formatted("{}{}_string", js_name, js_suffix), interface, false, false, {}, false, recursion_depth + 1); + union_generator.append(R"~~~( - return TRY(@js_name@@js_suffix@.to_string(vm)); + return { @js_name@@js_suffix@_string }; )~~~"); } else if (numeric_type && includes_bigint) { // 15. If types includes a numeric type and bigint, then return the result of converting V to either that numeric type or bigint. diff --git a/Tests/LibWeb/Text/expected/FileAPI/unpaired-surrogates-in-constructor.txt b/Tests/LibWeb/Text/expected/FileAPI/unpaired-surrogates-in-constructor.txt new file mode 100644 index 00000000000..38e03525155 --- /dev/null +++ b/Tests/LibWeb/Text/expected/FileAPI/unpaired-surrogates-in-constructor.txt @@ -0,0 +1,2 @@ +PASS +PASS diff --git a/Tests/LibWeb/Text/input/FileAPI/unpaired-surrogates-in-constructor.html b/Tests/LibWeb/Text/input/FileAPI/unpaired-surrogates-in-constructor.html new file mode 100644 index 00000000000..75d88275a0b --- /dev/null +++ b/Tests/LibWeb/Text/input/FileAPI/unpaired-surrogates-in-constructor.html @@ -0,0 +1,16 @@ + + +