diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-09 14:31:51 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-09 16:43:00 +0100 |
commit | ba87f23f22b274232d83e9c8ce3b537a7e486f32 (patch) | |
tree | d028e5b8ffb68e461f89a3dba3786835726ab20d /Userland/Libraries/LibWeb | |
parent | 252ed8ad18c6d1a880eebd5dcd98b6984e4aa8ff (diff) | |
download | serenity-ba87f23f22b274232d83e9c8ce3b537a7e486f32.zip |
LibWeb: Allow returning JS::ThrowCompletionOr<T> from wrapped functions
In some cases, we need more nuance than what DOM::ExceptionOr<T> offers.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h index 2fa51c1f11..c023c362d6 100644 --- a/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h +++ b/Userland/Libraries/LibWeb/Bindings/ExceptionOrUtils.h @@ -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>) { |