mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb/IDL: Add support for optional enums
This commit is contained in:
parent
2a27f2293a
commit
633ac53c0c
Notes:
sideshowbarker
2024-07-17 10:16:36 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/633ac53c0c Pull-request: https://github.com/SerenityOS/serenity/pull/14184 Reviewed-by: https://github.com/Quaker762 ✅ Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/sunverwerth
1 changed files with 14 additions and 0 deletions
|
@ -577,6 +577,15 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
enum_generator.set("js_name.as_string", String::formatted("{}{}_string", enum_generator.get("js_name"), enum_generator.get("js_suffix")));
|
||||
enum_generator.append(R"~~~(
|
||||
@parameter.type.name@ @cpp_name@ { @parameter.type.name@::@enum.default.cpp_value@ };
|
||||
)~~~");
|
||||
|
||||
if (optional) {
|
||||
enum_generator.append(R"~~~(
|
||||
if (!@js_name@@js_suffix@.is_undefined()) {
|
||||
)~~~");
|
||||
}
|
||||
|
||||
enum_generator.append(R"~~~(
|
||||
auto @js_name.as_string@ = TRY(@js_name@@js_suffix@.to_string(global_object));
|
||||
)~~~");
|
||||
auto first = true;
|
||||
|
@ -596,6 +605,11 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
@else@
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidEnumerationValue, @js_name.as_string@, "@parameter.type.name@");
|
||||
)~~~");
|
||||
|
||||
if (optional) {
|
||||
enum_generator.append(R"~~~(
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
} else if (interface.dictionaries.contains(parameter.type->name)) {
|
||||
if (optional_default_value.has_value() && optional_default_value != "{}")
|
||||
|
|
Loading…
Add table
Reference in a new issue