LibWeb: Throw when a setter is called with less than one argument

Some WPT tests expect that if you go out of your way to
Object.getOwnPropertyDescriptor on an interface object and extract
the setter out of it, that they throw when called with no arguments.
This commit is contained in:
Andrew Kaster 2024-12-23 15:57:06 -07:00 committed by Ali Mohammad Pur
commit 67a6c9246c
Notes: github-actions[bot] 2024-12-24 14:21:30 +00:00

View file

@ -3906,6 +3906,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
WebIDL::log_trace(vm, "@class_name@::@attribute.setter_callback@");
[[maybe_unused]] auto& realm = *vm.current_realm();
auto* impl = TRY(impl_from(vm));
if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
auto value = vm.argument(0);
)~~~");
@ -4033,6 +4035,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
{
WebIDL::log_trace(vm, "@class_name@::@attribute.setter_callback@");
auto this_value = vm.this_value();
if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
GC::Ptr<Window> window;
if (this_value.is_object()) {
if (is<WindowProxy>(this_value.as_object())) {
@ -4060,6 +4064,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
auto this_value = vm.this_value();
if (!this_value.is_object() || !is<@fully_qualified_name@>(this_value.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@namespaced_name@");
if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
TRY(this_value.as_object().internal_define_own_property("@attribute.name@", JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }));
return JS::js_undefined();
}
@ -4074,6 +4080,8 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
{
WebIDL::log_trace(vm, "@class_name@::@attribute.setter_callback@");
auto* impl = TRY(impl_from(vm));
if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "@namespaced_name@ setter");
auto value = vm.argument(0);
auto receiver = TRY(throw_dom_exception_if_needed(vm, [&]() { return impl->@attribute.cpp_name@(); }));