LibWeb/Bindings: Generate undefined in a union as 'Empty'

This can only ever be undefined, and no other JS value, so it makes
sense to use undefined to represent this case.
This commit is contained in:
Shannon Booth 2025-01-12 22:50:03 +13:00 committed by Tim Ledbetter
commit dfdcfc8e88
Notes: github-actions[bot] 2025-01-12 18:40:27 +00:00
5 changed files with 13 additions and 7 deletions

View file

@ -231,9 +231,15 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
if (type.name() == "long" && !type.is_nullable())
return { .name = "WebIDL::Long", .sequence_storage_type = SequenceStorageType::Vector };
if (type.name() == "any" || type.name() == "undefined")
if (type.name() == "any")
return { .name = "JS::Value", .sequence_storage_type = SequenceStorageType::RootVector };
// NOTE: undefined is a somewhat special case that may be used in a union to represent the javascript 'undefined' (and
// only ever js_undefined). Therefore, we say that the type is Empty here, so that a union of (T, undefined) is
// generated as Variant<T, Empty>, which is then returned in the Variant's visit as undefined if it is Empty.
if (type.name() == "undefined")
return { .name = "Empty", .sequence_storage_type = SequenceStorageType::RootVector };
if (type.name() == "object")
return { .name = "GC::Root<JS::Object>", .sequence_storage_type = SequenceStorageType::Vector };