mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
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:
parent
a098b5fcc4
commit
22075c08e4
|
|
@ -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 V’s [[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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user