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:
parent
bc0cff8a59
commit
4c8723e2d8
1 changed files with 16 additions and 0 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue