From ad32227c833e60c55b0f5460a4f9f9c1631ecd57 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 28 Jul 2024 13:27:50 +1200 Subject: [PATCH] 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, causing complile errors for something such as: `attribute unsigned long?`. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 81716fab1ab..a7b3406f1e2 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -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