1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

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.
This commit is contained in:
Linus Groh 2021-10-20 19:16:01 +01:00
parent 805f8496be
commit 894834b5d5

View file

@ -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; }