LibJS: Add Value::is<T> to align with Value::as_if<T>

We can also use concepts in the template type instead of static asserts.
This commit is contained in:
Timothy Flynn
2026-02-27 08:15:10 -05:00
committed by Shannon Booth
parent 9cd2daea3f
commit 9d1f727f43
Notes: github-actions[bot] 2026-02-27 16:21:20 +00:00
2 changed files with 11 additions and 8 deletions

View File

@@ -154,19 +154,23 @@ public:
return !is_nan() && !is_infinity();
}
template<typename T>
template<DerivedFrom<Object> T>
[[nodiscard]] ALWAYS_INLINE bool is() const
{
return is_object() && ::is<T>(as_object());
}
template<DerivedFrom<Object> T>
ALWAYS_INLINE T* as_if()
{
static_assert(IsBaseOf<Object, T>);
if (!is_object())
return nullptr;
return ::as_if<T>(as_object());
}
template<typename T>
template<DerivedFrom<Object> T>
ALWAYS_INLINE T const* as_if() const
{
static_assert(IsBaseOf<Object, T>);
if (!is_object())
return nullptr;
return ::as_if<T>(as_object());