mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Add support for optional double arguments with no default value
This is implemented by emitting AK::Optional, similar to optional boolean arguments.
This commit is contained in:
parent
0072581693
commit
a257ef0f35
Notes:
sideshowbarker
2024-07-18 20:18:03 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/a257ef0f35c Pull-request: https://github.com/SerenityOS/serenity/pull/6352
1 changed files with 30 additions and 2 deletions
|
@ -599,11 +599,39 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
auto& @cpp_name@ = static_cast<@parameter.type.name@Wrapper*>(@cpp_name@_object)->impl();
|
||||
)~~~");
|
||||
} else if (parameter.type.name == "double") {
|
||||
scoped_generator.append(R"~~~(
|
||||
auto @cpp_name@ = @js_name@@js_suffix@.to_double(global_object);
|
||||
if (!optional) {
|
||||
scoped_generator.append(R"~~~(
|
||||
double @cpp_name@ = @js_name@@js_suffix@.to_double(global_object);
|
||||
if (vm.exception())
|
||||
@return_statement@
|
||||
)~~~");
|
||||
} else {
|
||||
if (!optional_default_value.is_null()) {
|
||||
scoped_generator.append(R"~~~(
|
||||
double @cpp_name@;
|
||||
)~~~");
|
||||
} else {
|
||||
scoped_generator.append(R"~~~(
|
||||
Optional<double> @cpp_name@;
|
||||
)~~~");
|
||||
}
|
||||
scoped_generator.append(R"~~~(
|
||||
if (!@js_name@@js_suffix@.is_undefined()) {
|
||||
@cpp_name@ = @js_name@@js_suffix@.to_double(global_object);
|
||||
if (vm.exception())
|
||||
@return_statement@
|
||||
}
|
||||
)~~~");
|
||||
if (!optional_default_value.is_null()) {
|
||||
scoped_generator.append(R"~~~(
|
||||
else
|
||||
@cpp_name@ = @parameter.optional_default_value@;
|
||||
)~~~");
|
||||
} else {
|
||||
scoped_generator.append(R"~~~(
|
||||
)~~~");
|
||||
}
|
||||
}
|
||||
} else if (parameter.type.name == "boolean") {
|
||||
if (!optional) {
|
||||
scoped_generator.append(R"~~~(
|
||||
|
|
Loading…
Reference in a new issue