From 9f5323e1732034b3c150310acfe37e8de1a1dd81 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 27 Dec 2023 21:02:38 +1300 Subject: [PATCH] LibWeb: Use ConvertToInt for IDL integer conversion This is how the spec tells us we should be converting to these integer types. Also leave around a FIXME to pass through information about the [Clamp] and [EnforceRange] extended attributes, and port over these instances to the new WebIDL integer typedefs. --- .../BindingsGenerator/IDLGenerators.cpp | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 68a10c3753d..52d9cacb328 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -159,19 +159,19 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface) return { .name = "bool", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "unsigned long" && !type.is_nullable()) - return { .name = "u32", .sequence_storage_type = SequenceStorageType::Vector }; + return { .name = "WebIDL::UnsignedLong", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "unsigned short" && !type.is_nullable()) - return { .name = "u16", .sequence_storage_type = SequenceStorageType::Vector }; + return { .name = "WebIDL::UnsignedShort", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "long long" && !type.is_nullable()) - return { .name = "i64", .sequence_storage_type = SequenceStorageType::Vector }; + return { .name = "WebIDL::LongLong", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "unsigned long long" && !type.is_nullable()) - return { .name = "u64", .sequence_storage_type = SequenceStorageType::Vector }; + return { .name = "WebIDL::UnsignedLongLong", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "long" && !type.is_nullable()) - return { .name = "i32", .sequence_storage_type = SequenceStorageType::Vector }; + return { .name = "WebIDL::Long", .sequence_storage_type = SequenceStorageType::Vector }; if (type.name() == "any" || type.name() == "undefined") return { .name = "JS::Value", .sequence_storage_type = SequenceStorageType::MarkedVector }; @@ -494,11 +494,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } else if (parameter.type->name() == "unsigned long") { if (!optional || optional_default_value.has_value()) { scoped_generator.append(R"~~~( - u32 @cpp_name@; + WebIDL::UnsignedLong @cpp_name@; )~~~"); } else { scoped_generator.append(R"~~~( - Optional @cpp_name@; + Optional @cpp_name@; )~~~"); } if (optional) { @@ -506,8 +506,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter if (!@js_name@@js_suffix@.is_undefined()) )~~~"); } + // FIXME: pass through [EnforceRange] and [Clamp] extended attributes scoped_generator.append(R"~~~( - @cpp_name@ = TRY(@js_name@@js_suffix@.to_u32(vm)); + @cpp_name@ = TRY(convert_to_int(vm, @js_name@@js_suffix@)); )~~~"); if (optional_default_value.has_value()) { scoped_generator.append(R"~~~( @@ -518,11 +519,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } else if (parameter.type->name() == "unsigned short") { if (!optional || optional_default_value.has_value()) { scoped_generator.append(R"~~~( - u16 @cpp_name@; + WebIDL::UnsignedShort @cpp_name@; )~~~"); } else { scoped_generator.append(R"~~~( - Optional @cpp_name@; + Optional @cpp_name@; )~~~"); } if (optional) { @@ -530,8 +531,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter if (!@js_name@@js_suffix@.is_undefined()) )~~~"); } + // FIXME: pass through [EnforceRange] and [Clamp] extended attributes scoped_generator.append(R"~~~( - @cpp_name@ = TRY(@js_name@@js_suffix@.to_u16(vm)); + @cpp_name@ = TRY(convert_to_int(vm, @js_name@@js_suffix@)); )~~~"); if (optional_default_value.has_value()) { scoped_generator.append(R"~~~( @@ -542,11 +544,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } else if (parameter.type->name() == "long") { if (!optional || optional_default_value.has_value()) { scoped_generator.append(R"~~~( - i32 @cpp_name@; + WebIDL::Long @cpp_name@; )~~~"); } else { scoped_generator.append(R"~~~( - Optional @cpp_name@; + Optional @cpp_name@; )~~~"); } if (optional) { @@ -554,8 +556,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter if (!@js_name@@js_suffix@.is_undefined()) )~~~"); } + // FIXME: pass through [EnforceRange] and [Clamp] extended attributes scoped_generator.append(R"~~~( - @cpp_name@ = TRY(@js_name@@js_suffix@.to_i32(vm)); + @cpp_name@ = TRY(convert_to_int(vm, @js_name@@js_suffix@)); )~~~"); if (optional_default_value.has_value()) { scoped_generator.append(R"~~~( @@ -566,11 +569,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter } else if (parameter.type->name() == "long long") { if (!optional || optional_default_value.has_value()) { scoped_generator.append(R"~~~( - i64 @cpp_name@; + WebIDL::LongLong @cpp_name@; )~~~"); } else { scoped_generator.append(R"~~~( - Optional @cpp_name@; + Optional @cpp_name@; )~~~"); } if (optional) { @@ -578,8 +581,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter if (!@js_name@@js_suffix@.is_undefined()) )~~~"); } + // FIXME: pass through [EnforceRange] and [Clamp] extended attributes scoped_generator.append(R"~~~( - @cpp_name@ = TRY(@js_name@@js_suffix@.to_bigint_int64(vm)); + @cpp_name@ = TRY(convert_to_int(vm, @js_name@@js_suffix@)); )~~~"); if (optional_default_value.has_value()) { scoped_generator.append(R"~~~( @@ -3376,8 +3380,10 @@ void generate_namespace_implementation(IDL::Interface const& interface, StringBu #include #include #include +#include #include #include +#include )~~~"); @@ -3588,8 +3594,10 @@ void generate_constructor_implementation(IDL::Interface const& interface, String # include #endif #include +#include #include #include +#include )~~~"); @@ -4044,6 +4052,7 @@ void generate_prototype_implementation(IDL::Interface const& interface, StringBu #include #include #include +#include #if __has_include() # include