1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

LibWeb: Support generating IDL float types

The float type is used quite a bit in the SVG spec.
This commit is contained in:
Timothy Flynn 2022-03-21 14:18:34 -04:00 committed by Andreas Kling
parent 4d49c607f8
commit 3ebc5cc58e

View file

@ -78,6 +78,9 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
if (type.name == "double" && !type.nullable) if (type.name == "double" && !type.nullable)
return { .name = "double", .sequence_storage_type = SequenceStorageType::Vector }; return { .name = "double", .sequence_storage_type = SequenceStorageType::Vector };
if (type.name == "float" && !type.nullable)
return { .name = "float", .sequence_storage_type = SequenceStorageType::Vector };
if (type.name == "boolean" && !type.nullable) if (type.name == "boolean" && !type.nullable)
return { .name = "bool", .sequence_storage_type = SequenceStorageType::Vector }; return { .name = "bool", .sequence_storage_type = SequenceStorageType::Vector };
@ -379,19 +382,19 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
} }
)~~~"); )~~~");
} }
} else if (parameter.type->name == "double") { } else if (parameter.type->name == "double" || parameter.type->name == "float") {
if (!optional) { if (!optional) {
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
double @cpp_name@ = TRY(@js_name@@js_suffix@.to_double(global_object)); @parameter.type.name@ @cpp_name@ = TRY(@js_name@@js_suffix@.to_double(global_object));
)~~~"); )~~~");
} else { } else {
if (optional_default_value.has_value()) { if (optional_default_value.has_value()) {
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
double @cpp_name@; @parameter.type.name@ @cpp_name@;
)~~~"); )~~~");
} else { } else {
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
Optional<double> @cpp_name@; Optional<@parameter.type.name@> @cpp_name@;
)~~~"); )~~~");
} }
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
@ -1247,7 +1250,7 @@ static void generate_wrap_statement(SourceGenerator& generator, String const& va
@result_expression@ new_array@recursion_depth@; @result_expression@ new_array@recursion_depth@;
)~~~"); )~~~");
} else if (type.name == "boolean" || type.name == "double") { } else if (type.name == "boolean" || type.name == "double" || type.name == "float") {
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
@result_expression@ JS::Value(@value@); @result_expression@ JS::Value(@value@);
)~~~"); )~~~");