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:
parent
805f8496be
commit
894834b5d5
1 changed files with 9 additions and 0 deletions
|
@ -134,6 +134,15 @@ public:
|
||||||
VERIFY(!value.is_empty());
|
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(); }
|
[[nodiscard]] bool is_throw_completion() const { return m_throw_completion.has_value(); }
|
||||||
Completion const& throw_completion() const { return *m_throw_completion; }
|
Completion const& throw_completion() const { return *m_throw_completion; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue