mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
BindingsGenerator: Handle nullable enum properties
Add some checks to the statement wrapping code to make sure we properly handle the expected pattern of returning ``Optional<Enum>`` from nullable enum properties.
This commit is contained in:
parent
d3a8ee6e4b
commit
cf0ffc12cc
1 changed files with 4 additions and 1 deletions
|
@ -1621,7 +1621,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
|||
@result_expression@ JS::js_null();
|
||||
} else {
|
||||
)~~~");
|
||||
} else if (type.is_primitive()) {
|
||||
} else if (type.is_primitive() || interface.enumerations.contains(type.name())) {
|
||||
scoped_generator.append(R"~~~(
|
||||
if (!@value@.has_value()) {
|
||||
@result_expression@ JS::js_null();
|
||||
|
@ -1764,6 +1764,9 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
|||
);
|
||||
)~~~");
|
||||
} else if (interface.enumerations.contains(type.name())) {
|
||||
// Handle Enum? values, which were null-checked above
|
||||
if (type.is_nullable())
|
||||
scoped_generator.set("value", DeprecatedString::formatted("{}.value()", value));
|
||||
if (!interface.extended_attributes.contains("UseNewAKString")) {
|
||||
scoped_generator.append(R"~~~(
|
||||
@result_expression@ JS::PrimitiveString::create(vm, Bindings::idl_enum_to_deprecated_string(@value@));
|
||||
|
|
Loading…
Add table
Reference in a new issue