1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:47: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:
Timothy Flynn 2021-10-31 13:07:52 -04:00 committed by Linus Groh
parent e3b7c305bc
commit 95e492de59
4 changed files with 84 additions and 168 deletions

View file

@ -80,30 +80,6 @@ public:
return m_exception.template downcast<SimpleException, NonnullRefPtr<DOMException>>();
}
auto materialized_exception(JS::GlobalObject& global_object) const
{
#define E(x) JS::x*,
using ResultType = Variant<ENUMERATE_SIMPLE_WEBIDL_EXCEPTION_TYPES(E) NonnullRefPtr<DOMException>>;
#undef E
return m_exception.visit(
[&](SimpleException& exception) -> ResultType {
switch (exception.type) {
#define E(x) \
case SimpleExceptionType::x: \
return JS::x::create(global_object, exception.message);
ENUMERATE_SIMPLE_WEBIDL_EXCEPTION_TYPES(E)
#undef E
default:
VERIFY_NOT_REACHED();
}
},
[&](NonnullRefPtr<DOMException> const& exception) -> ResultType { return exception; },
[](Empty) -> ResultType { VERIFY_NOT_REACHED(); });
}
bool is_exception() const
{
return !m_exception.template has<Empty>();