From be8489fb04b1c4d297e44725c27bbf8e623212e8 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Tue, 19 Dec 2023 23:15:32 +0100 Subject: [PATCH] LibWeb/IDL/Codegen: Handle BufferSource in union types --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 31f71cf628..13b6b804f4 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1205,6 +1205,17 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter )~~~"); } + // Note: This covers steps 6-8 for when Buffersource is in a union with a type other than "object". + // Since in that case, the return type would be Handle, and not Handle. + if (any_of(types, [](auto const& type) { return type->name() == "BufferSource"; }) && !includes_object) { + union_generator.append(R"~~~( + if (is(@js_name@@js_suffix@_object) || is(@js_name@@js_suffix@_object) || is(@js_name@@js_suffix@_object)) { + JS::NonnullGCPtr source_object = vm.heap().allocate(realm, @js_name@@js_suffix@_object); + return JS::make_handle(source_object); + } +)~~~"); + } + // 6. If Type(V) is Object and V has an [[ArrayBufferData]] internal slot, then // 1. If types includes ArrayBuffer, then return the result of converting V to ArrayBuffer. // 2. If types includes object, then return the IDL value that is a reference to the object V.