From 8865d18a6715480c186141ecfe2e182405a7eb93 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 22 Aug 2024 14:40:11 -0400 Subject: [PATCH] LibWeb: Allow callback parameters to be nullable This is needed for DataTransferItem's getAsString(callback?) prototype. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index c1c058a3d41..469f573ec53 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -903,16 +903,16 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter // An ECMAScript value V is converted to an IDL callback function type value by running the following algorithm: // 1. If the result of calling IsCallable(V) is false and the conversion to an IDL value is not being performed due to V being assigned to an attribute whose type is a nullable callback function that is annotated with [LegacyTreatNonObjectAsNull], then throw a TypeError. - if (!callback_function.is_legacy_treat_non_object_as_null) { + if (!parameter.type->is_nullable() && !callback_function.is_legacy_treat_non_object_as_null) { callback_function_generator.append(R"~~~( if (!@js_name@@js_suffix@.is_function()) return vm.throw_completion(JS::ErrorType::NotAFunction, @js_name@@js_suffix@.to_string_without_side_effects()); )~~~"); } // 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context. - if (callback_function.is_legacy_treat_non_object_as_null) { + if (parameter.type->is_nullable() || callback_function.is_legacy_treat_non_object_as_null) { callback_function_generator.append(R"~~~( - WebIDL::CallbackType* @cpp_name@ = nullptr; + JS::GCPtr @cpp_name@; if (@js_name@@js_suffix@.is_object()) @cpp_name@ = vm.heap().allocate_without_realm(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object(), @operation_returns_promise@); )~~~");