1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibWeb: Return undefined from event handler setters, not an empty value

This commit is contained in:
Linus Groh 2021-09-24 13:19:13 +02:00
parent a1a164e6b8
commit 1a7136b37a

View file

@ -682,35 +682,37 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::history_getter)
return wrap(global_object, impl->associated_document().history());
}
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
{ \
auto* impl = impl_from(vm, global_object); \
if (!impl) \
return {}; \
auto retval = impl->attribute(); \
if (retval.callback.is_null()) \
return JS::js_null(); \
return retval.callback.cell(); \
} \
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_setter) \
{ \
auto* impl = impl_from(vm, global_object); \
if (!impl) \
return {}; \
auto value = vm.argument(0); \
HTML::EventHandler cpp_value; \
if (value.is_function()) { \
cpp_value.callback = JS::make_handle(&value.as_function()); \
} else if (value.is_string()) { \
cpp_value.string = value.as_string().string(); \
} else { \
return {}; \
} \
(void)throw_dom_exception_if_needed(vm, global_object, [&] { \
return impl->set_##attribute(cpp_value); \
}); \
return {}; \
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
{ \
auto* impl = impl_from(vm, global_object); \
if (!impl) \
return {}; \
auto retval = impl->attribute(); \
if (retval.callback.is_null()) \
return JS::js_null(); \
return retval.callback.cell(); \
} \
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_setter) \
{ \
auto* impl = impl_from(vm, global_object); \
if (!impl) \
return {}; \
auto value = vm.argument(0); \
HTML::EventHandler cpp_value; \
if (value.is_function()) { \
cpp_value.callback = JS::make_handle(&value.as_function()); \
} else if (value.is_string()) { \
cpp_value.string = value.as_string().string(); \
} else { \
return JS::js_undefined(); \
} \
auto result = throw_dom_exception_if_needed(vm, global_object, [&] { \
return impl->set_##attribute(cpp_value); \
}); \
if (should_return_empty(result)) \
return {}; \
return JS::js_undefined(); \
}
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE