mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
LibWeb: Fix bindings codegen for IDL enums with only one member
The SourceGenerator's @else@ mapping is only set in the second iteration of the loop, causing the generated return for unrecognized values to not be guarded by an else statement. We can simply use a hardcoded 'else' here, @else@ is only to create the first comparison as a plain 'if' and subsequent ones as 'else if'.
This commit is contained in:
parent
fd52119ca3
commit
d38f1fb5b2
1 changed files with 3 additions and 2 deletions
|
@ -585,6 +585,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
auto @js_name.as_string@ = TRY(@js_name@@js_suffix@.to_string(vm));
|
||||
)~~~");
|
||||
auto first = true;
|
||||
VERIFY(enumeration.translated_cpp_names.size() >= 1);
|
||||
for (auto& it : enumeration.translated_cpp_names) {
|
||||
enum_generator.set("enum.alt.name", it.key);
|
||||
enum_generator.set("enum.alt.value", it.value);
|
||||
|
@ -600,12 +601,12 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
|||
// NOTE: Attribute setters return undefined instead of throwing when the string doesn't match an enum value.
|
||||
if constexpr (!IsSame<Attribute, RemoveConst<ParameterType>>) {
|
||||
enum_generator.append(R"~~~(
|
||||
@else@
|
||||
else
|
||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, @js_name.as_string@, "@parameter.type.name@");
|
||||
)~~~");
|
||||
} else {
|
||||
enum_generator.append(R"~~~(
|
||||
@else@
|
||||
else
|
||||
return JS::js_undefined();
|
||||
)~~~");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue