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.
This commit is contained in:
Shannon Booth 2025-01-14 10:45:06 +13:00 committed by Tim Ledbetter
parent f3ec727555
commit ba382c454a
Notes: github-actions[bot] 2025-02-10 17:06:19 +00:00

View file

@ -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<decltype(@value@)&>(@value@).release_value());
)~~~");
} else {
scoped_generator.append(R"~~~(