mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-23 01:38:56 +00:00
LibWeb: Implement optional function IDL arguments
This allows us to run some more view transitions WPT tests, one of which has been imported.
This commit is contained in:
parent
4559d5f6f6
commit
fa3c45d0b4
Notes:
github-actions[bot]
2025-09-10 13:51:13 +00:00
Author: https://github.com/Psychpsyo
Commit: fa3c45d0b4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6141
2 changed files with 7 additions and 3 deletions
|
@ -6679,7 +6679,6 @@ void Document::set_onvisibilitychange(WebIDL::CallbackType* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition
|
// https://drafts.csswg.org/css-view-transitions-1/#dom-document-startviewtransition
|
||||||
// FIXME: Calling document.startViewTransition() without arguments throws TypeError instead of calling this.
|
|
||||||
GC::Ptr<ViewTransition::ViewTransition> Document::start_view_transition(ViewTransition::ViewTransitionUpdateCallback update_callback)
|
GC::Ptr<ViewTransition::ViewTransition> Document::start_view_transition(ViewTransition::ViewTransitionUpdateCallback update_callback)
|
||||||
{
|
{
|
||||||
// The method steps for startViewTransition(updateCallback) are as follows:
|
// The method steps for startViewTransition(updateCallback) are as follows:
|
||||||
|
|
|
@ -1089,17 +1089,22 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
// 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.
|
// 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 (!parameter.type->is_nullable() && !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"~~~(
|
callback_function_generator.append(R"~~~(
|
||||||
if (!@js_name@@js_suffix@.is_function())
|
if (!@js_name@@js_suffix@.is_function()
|
||||||
|
)~~~");
|
||||||
|
if (optional)
|
||||||
|
callback_function_generator.append("&& !@js_name@@js_suffix@.is_undefined()");
|
||||||
|
callback_function_generator.append(R"~~~()
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAFunction, @js_name@@js_suffix@.to_string_without_side_effects());
|
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 realm as the callback context.
|
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent realm as the callback context.
|
||||||
if (parameter.type->is_nullable() || callback_function.is_legacy_treat_non_object_as_null) {
|
if (optional || parameter.type->is_nullable() || callback_function.is_legacy_treat_non_object_as_null) {
|
||||||
callback_function_generator.append(R"~~~(
|
callback_function_generator.append(R"~~~(
|
||||||
GC::Ptr<WebIDL::CallbackType> @cpp_name@;
|
GC::Ptr<WebIDL::CallbackType> @cpp_name@;
|
||||||
if (@js_name@@js_suffix@.is_object())
|
if (@js_name@@js_suffix@.is_object())
|
||||||
@cpp_name@ = vm.heap().allocate<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_realm(), @operation_returns_promise@);
|
@cpp_name@ = vm.heap().allocate<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_realm(), @operation_returns_promise@);
|
||||||
)~~~");
|
)~~~");
|
||||||
|
// FIXME: Handle default value for optional parameter here.
|
||||||
} else {
|
} else {
|
||||||
callback_function_generator.append(R"~~~(
|
callback_function_generator.append(R"~~~(
|
||||||
auto @cpp_name@ = vm.heap().allocate<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_realm(), @operation_returns_promise@);
|
auto @cpp_name@ = vm.heap().allocate<WebIDL::CallbackType>(@js_name@@js_suffix@.as_object(), HTML::incumbent_realm(), @operation_returns_promise@);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue