diff options
author | Linus Groh <mail@linusgroh.de> | 2021-10-20 19:16:01 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 09:02:23 +0100 |
commit | 894834b5d5fe1621271ca11439e2c753d3b25724 (patch) | |
tree | 3e1d4299fc7d13cfc4e7c5ed0b6244ec471cc0b5 /Userland | |
parent | 805f8496be43f2c00d1cc5ded8794c22cb48a1d4 (diff) | |
download | serenity-894834b5d5fe1621271ca11439e2c753d3b25724.zip |
LibJS: Allow construction of ThrowCompletionOr<Value> from non-Value
TL;DR: Instead of this:
return { TRY(my_object()) };
we can now do:
return TRY(my_object());
just like we mostly did for Value return types before ThrowCompletionOr.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Completion.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index 9874d42f8e..1486aba275 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -134,6 +134,15 @@ public: VERIFY(!value.is_empty()); } + // Allows implicit construction of ThrowCompletionOr<T> from a type U if T(U) is a supported constructor. + // Most commonly: Value from Object* or similar, so we can omit the curly braces from "return { TRY(...) };". + // Disabled for POD types to avoid weird conversion shenanigans. + template<typename WrappedValueType> + ThrowCompletionOr(WrappedValueType value) requires(!IsPOD<ValueType>) + : m_value(move(value)) + { + } + [[nodiscard]] bool is_throw_completion() const { return m_throw_completion.has_value(); } Completion const& throw_completion() const { return *m_throw_completion; } |