From 67a6c9246cb4d5ca23fa543ace0f3f70a39277fa Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Mon, 23 Dec 2024 15:57:06 -0700 Subject: [PATCH] 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. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 46e2da926cc..fdcd1fabbb4 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -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::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::ErrorType::BadArgCountOne, "@namespaced_name@ setter"); GC::Ptr window; if (this_value.is_object()) { if (is(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::ErrorType::NotAnObjectOfType, "@namespaced_name@"); + if (vm.argument_count() < 1) + return vm.throw_completion(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::ErrorType::BadArgCountOne, "@namespaced_name@ setter"); auto value = vm.argument(0); auto receiver = TRY(throw_dom_exception_if_needed(vm, [&]() { return impl->@attribute.cpp_name@(); }));