summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-24 13:19:13 +0200
committerLinus Groh <mail@linusgroh.de>2021-09-24 13:19:13 +0200
commit1a7136b37a02c973f4157fb4cf61d401eb37dd16 (patch)
tree017d84defdb28ca21d3bf837fe4c9ec5281fb580
parenta1a164e6b8d107f9bc5edd58b210b34c096d6b66 (diff)
downloadserenity-1a7136b37a02c973f4157fb4cf61d401eb37dd16.zip
LibWeb: Return undefined from event handler setters, not an empty value
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.cpp60
1 files changed, 31 insertions, 29 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
index 3369221024..eeda0b978d 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -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