mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +00:00
LibWeb: Add full support for optional and nullable to IDL string types
Used by History.
This commit is contained in:
parent
f8eb616fe3
commit
3faed65e2b
1 changed files with 13 additions and 2 deletions
|
@ -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@;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue