mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibJS: Take advantage of Value::Type::Int32 in a bunch of functions
If a JS::Value has type Int32, we know it's a finite, 32-bit integer. Use this information to avoid converting it to a double if possible.
This commit is contained in:
parent
5b1f697460
commit
e67155638c
2 changed files with 65 additions and 21 deletions
|
@ -580,18 +580,6 @@ u64 Value::to_bigint_uint64(GlobalObject& global_object) const
|
|||
return bigint->big_integer().to_u64();
|
||||
}
|
||||
|
||||
// FIXME: These two conversions are wrong for JS, and seem likely to be footguns
|
||||
i32 Value::as_i32() const
|
||||
{
|
||||
return static_cast<i32>(as_double());
|
||||
}
|
||||
|
||||
u32 Value::as_u32() const
|
||||
{
|
||||
VERIFY(as_double() >= 0);
|
||||
return (u32)min(as_double(), (double)NumericLimits<u32>::max());
|
||||
}
|
||||
|
||||
double Value::to_double(GlobalObject& global_object) const
|
||||
{
|
||||
auto number = to_number(global_object);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue