BindingsGenerator: Return the exact typed array member type for unions

Allows definition of:
`typedef (Float32Array or sequence<GLfloat>) Float32List;`

which did fail to compile before, because `GC::Root<JS::Object>` fails
to implicitly cast into
`AK::Variant<GC::Root<JS::Float32Array>, AK::Vector<float>>`.
This commit is contained in:
Aliaksandr Kalenik 2025-09-30 02:53:58 +02:00 committed by Alexander Kalenik
parent a098b5fcc4
commit 22075c08e4

View File

@ -1449,11 +1449,17 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
// 8. If Type(V) is Object and V has a [[TypedArrayName]] internal slot, then:
// 1. If types includes a typed array type whose name is the value of Vs [[TypedArrayName]] internal slot, then return the result of converting V to that type.
// 2. If types includes object, then return the IDL value that is a reference to the object V.
auto has_typed_array_name = any_of(types, [](auto const& type) {
auto typed_array_name = types.find_if([](auto const& type) {
return type->name().is_one_of("Int8Array"sv, "Int16Array"sv, "Int32Array"sv, "Uint8Array"sv, "Uint16Array"sv, "Uint32Array"sv, "Uint8ClampedArray"sv, "BigInt64Array"sv, "BigUint64Array"sv, "Float16Array"sv, "Float32Array"sv, "Float64Array"sv);
});
if (has_typed_array_name || includes_object) {
if (typed_array_name != types.end()) {
union_generator.set("typed_array_type", (*typed_array_name)->name());
union_generator.append(R"~~~(
if (auto* typed_array = as_if<JS::@typed_array_type@>(@js_name@@js_suffix@_object))
return GC::make_root(*typed_array);
)~~~");
} else if (includes_object) {
union_generator.append(R"~~~(
if (is<JS::TypedArrayBase>(@js_name@@js_suffix@_object))
return GC::make_root(@js_name@@js_suffix@_object);