mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
LibWeb: Convert throw_dom_exception_if_needed() to ThrowCompletionOr
This changes Web::Bindings::throw_dom_exception_if_needed() to return a JS::ThrowCompletionOr instead of an Optional. This allows callers to wrap the invocation with a TRY() macro instead of making a follow-up call to should_return_empty(). Further, this removes all invocations to vm.exception() in the generated bindings.
This commit is contained in:
parent
e3b7c305bc
commit
95e492de59
4 changed files with 84 additions and 168 deletions
|
@ -636,33 +636,31 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::screen_y_getter)
|
|||
return JS::Value(impl->screen_y());
|
||||
}
|
||||
|
||||
#define __ENUMERATE(attribute, event_name) \
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
|
||||
{ \
|
||||
auto* impl = TRY(impl_from(vm, global_object)); \
|
||||
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 = TRY(impl_from(vm, global_object)); \
|
||||
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 JS::throw_completion(vm.exception()->value()); \
|
||||
return JS::js_undefined(); \
|
||||
#define __ENUMERATE(attribute, event_name) \
|
||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::attribute##_getter) \
|
||||
{ \
|
||||
auto* impl = TRY(impl_from(vm, global_object)); \
|
||||
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 = TRY(impl_from(vm, global_object)); \
|
||||
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(); \
|
||||
} \
|
||||
TRY(throw_dom_exception_if_needed(global_object, [&] { \
|
||||
return impl->set_##attribute(cpp_value); \
|
||||
})); \
|
||||
return JS::js_undefined(); \
|
||||
}
|
||||
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
|
||||
#undef __ENUMERATE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue