mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
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:
committed by
Shannon Booth
parent
9cd2daea3f
commit
9d1f727f43
Notes:
github-actions[bot]
2026-02-27 16:21:20 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/9d1f727f43f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8208 Reviewed-by: https://github.com/shannonbooth ✅
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user