mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibWeb: Allow returning JS::ThrowCompletionOr<T> from wrapped functions
In some cases, we need more nuance than what DOM::ExceptionOr<T> offers.
This commit is contained in:
parent
252ed8ad18
commit
ba87f23f22
1 changed files with 12 additions and 1 deletions
|
@ -20,6 +20,12 @@ constexpr bool IsExceptionOr = false;
|
|||
template<typename T>
|
||||
constexpr bool IsExceptionOr<DOM::ExceptionOr<T>> = true;
|
||||
|
||||
template<typename>
|
||||
constexpr bool IsThrowCompletionOr = false;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool IsThrowCompletionOr<JS::ThrowCompletionOr<T>> = true;
|
||||
|
||||
namespace Detail {
|
||||
|
||||
template<typename T>
|
||||
|
@ -32,6 +38,11 @@ struct ExtractExceptionOrValueType<DOM::ExceptionOr<T>> {
|
|||
using Type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct ExtractExceptionOrValueType<JS::ThrowCompletionOr<T>> {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ExtractExceptionOrValueType<void> {
|
||||
using Type = JS::Value;
|
||||
|
@ -79,7 +90,7 @@ using ExtractExceptionOrValueType = typename Detail::ExtractExceptionOrValueType
|
|||
// void or ExceptionOr<void>: JS::ThrowCompletionOr<JS::Value>, always returns JS::js_undefined()
|
||||
// ExceptionOr<T>: JS::ThrowCompletionOr<T>
|
||||
// T: JS::ThrowCompletionOr<T>
|
||||
template<typename F, typename T = decltype(declval<F>()()), typename Ret = Conditional<!IsExceptionOr<T> && !IsVoid<T>, T, ExtractExceptionOrValueType<T>>>
|
||||
template<typename F, typename T = decltype(declval<F>()()), typename Ret = Conditional<!IsExceptionOr<T> && !IsVoid<T> && !IsThrowCompletionOr<T>, T, ExtractExceptionOrValueType<T>>>
|
||||
JS::ThrowCompletionOr<Ret> throw_dom_exception_if_needed(auto&& global_object, F&& fn)
|
||||
{
|
||||
if constexpr (IsExceptionOr<T>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue