BindingsGenerator: Support nullable integral attributes

Previously we were assuming that the attribute return value was never
nullable and going to be returned in an Optional<IntegralType>, causing
complile errors for something such as: `attribute unsigned long?`.
This commit is contained in:
Shannon Booth 2024-07-28 13:27:50 +12:00 committed by Andreas Kling
parent d6243abec3
commit ad32227c83
Notes: github-actions[bot] 2024-08-01 10:18:08 +00:00

View file

@ -412,9 +412,15 @@ static void generate_from_integral(SourceGenerator& scoped_generator, IDL::Type
VERIFY(it != idl_type_map.end());
scoped_generator.set("cpp_type"sv, it->cpp_type);
scoped_generator.append(R"~~~(
if (type.is_nullable()) {
scoped_generator.append(R"~~~(
@result_expression@ JS::Value(static_cast<@cpp_type@>(@value@.release_value()));
)~~~");
} else {
scoped_generator.append(R"~~~(
@result_expression@ JS::Value(static_cast<@cpp_type@>(@value@));
)~~~");
}
}
template<typename ParameterType>