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 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 + ThrowCompletionOr(WrappedValueType value) requires(!IsPOD) + : 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; }