From ba382c454a53b1ac47b36b26c655f54bb916daab Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 14 Jan 2025 10:45:06 +1300 Subject: [PATCH] LibWeb/Bindings: Allow optional string returned in a union This is not a very pleasant fix, but matches a similar const_cast that we do to return JS objects returned in a union. Ideally we would 'simply' remove the const from the value being visited in the variant, but that opens up a whole can of worms where we are currently relying on temporary lifetime extension so that interfaces can return a Variant of GC::Ref's to JS::Objects. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index f1938be7ef3..f18c5a7e249 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1821,8 +1821,11 @@ static void generate_wrap_statement(SourceGenerator& generator, ByteString const if (type.is_string()) { if (type.is_nullable() || is_optional) { + // FIXME: Ideally we would not need to do this const_cast, but we currently rely on temporary + // lifetime extension to allow Variants to compile and handle an interface returning a + // GC::Ref while the generated code will visit it as a GC::Root. scoped_generator.append(R"~~~( - @result_expression@ JS::PrimitiveString::create(vm, @value@.release_value()); + @result_expression@ JS::PrimitiveString::create(vm, const_cast(@value@).release_value()); )~~~"); } else { scoped_generator.append(R"~~~(