mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb: Allow callback parameters to be nullable
This is needed for DataTransferItem's getAsString(callback?) prototype.
This commit is contained in:
parent
b978dba8bd
commit
8865d18a67
Notes:
github-actions[bot]
2024-08-23 09:11:38 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/8865d18a671 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1163 Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 3 additions and 3 deletions
|
@ -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::TypeError>(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<WebIDL::CallbackType> @cpp_name@;
|
||||
if (@js_name@@js_suffix@.is_object())
|
||||
@cpp_name@ = vm.heap().allocate_without_realm<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_settings_object(), @operation_returns_promise@);
|
||||
)~~~");
|
||||
|
|
Loading…
Reference in a new issue