LibJS: Implement convenience helper Value::as<T>()

For simplifying code that has an is<T> assertion followed by a
cast, analagous to AK::as<T>.
This commit is contained in:
Shannon Booth 2026-02-28 12:36:03 +01:00 committed by Tim Flynn
parent bc0cff8a59
commit 4c8723e2d8

View file

@ -184,6 +184,22 @@ public:
}
}
template<DerivedFrom<Object> T>
[[nodiscard]] ALWAYS_INLINE T& as()
{
auto ptr = as_if<T>();
VERIFY(ptr);
return *ptr;
}
template<DerivedFrom<Object> T>
[[nodiscard]] ALWAYS_INLINE T const& as() const
{
auto ptr = as_if<T>();
VERIFY(ptr);
return *ptr;
}
constexpr Value()
: Value(UNDEFINED_TAG << GC::TAG_SHIFT, (u64)0)
{