LibWeb: Add full support for optional and nullable to IDL string types

Used by History.
This commit is contained in:
Luke Wilde 2021-09-12 00:09:07 +01:00 committed by Andreas Kling
parent f8eb616fe3
commit 3faed65e2b
Notes: sideshowbarker 2024-07-18 04:12:37 +09:00

View file

@ -550,11 +550,22 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// FIXME: Add support for optional, nullable and default values to all types
if (parameter.type.is_string()) {
if (!optional) {
scoped_generator.append(R"~~~(
if (!parameter.type.nullable) {
scoped_generator.append(R"~~~(
auto @cpp_name@ = @js_name@@js_suffix@.to_string(global_object, @legacy_null_to_empty_string@);
if (vm.exception())
@return_statement@
)~~~");
} else {
scoped_generator.append(R"~~~(
String @cpp_name@;
if (!@js_name@@js_suffix@.is_nullish()) {
@cpp_name@ = @js_name@@js_suffix@.to_string(global_object, @legacy_null_to_empty_string@);
if (vm.exception())
@return_statement@
}
)~~~");
}
} else {
scoped_generator.append(R"~~~(
String @cpp_name@;
@ -563,7 +574,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (vm.exception())
@return_statement@
})~~~");
if (optional_default_value.has_value()) {
if (optional_default_value.has_value() && (!parameter.type.nullable || optional_default_value.value() != "null")) {
scoped_generator.append(R"~~~( else {
@cpp_name@ = @parameter.optional_default_value@;
}