mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
LibJS: Add Value::to_i32() helper function
This commit is contained in:
parent
57646e362f
commit
d02c37f3e3
2 changed files with 13 additions and 2 deletions
|
@ -89,6 +89,18 @@ Value Value::to_object(Heap& heap) const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i32 Value::to_i32() const
|
||||||
|
{
|
||||||
|
switch (m_type) {
|
||||||
|
case Type::Boolean:
|
||||||
|
return m_value.as_bool;
|
||||||
|
case Type::Number:
|
||||||
|
return static_cast<i32>(m_value.as_double);
|
||||||
|
default:
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Value greater_than(Value lhs, Value rhs)
|
Value greater_than(Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
ASSERT(lhs.is_number());
|
ASSERT(lhs.is_number());
|
||||||
|
@ -209,8 +221,6 @@ Value typed_eq(Value lhs, Value rhs)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const LogStream& operator<<(const LogStream& stream, const Value& value)
|
const LogStream& operator<<(const LogStream& stream, const Value& value)
|
||||||
{
|
{
|
||||||
return stream << value.to_string();
|
return stream << value.to_string();
|
||||||
|
|
|
@ -133,6 +133,7 @@ public:
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
bool to_boolean() const;
|
bool to_boolean() const;
|
||||||
|
i32 to_i32() const;
|
||||||
|
|
||||||
Value to_object(Heap&) const;
|
Value to_object(Heap&) const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue