1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:37:34 +00:00

LibJS: Remove is_nan() check in as_size_t() and fix to_size_t()

We need to call as_double() on the freshly converted number, not the
value itself.
This commit is contained in:
Linus Groh 2020-05-18 10:03:08 +01:00 committed by Andreas Kling
parent 3bc3f36cfe
commit eb72ba2466
2 changed files with 6 additions and 4 deletions

View file

@ -250,8 +250,6 @@ i32 Value::as_i32() const
size_t Value::as_size_t() const
{
ASSERT(as_double() >= 0);
if (is_nan())
return 0;
return min((double)(i32)as_double(), MAX_ARRAY_LIKE_INDEX);
}
@ -278,7 +276,9 @@ size_t Value::to_size_t(Interpreter& interpreter) const
auto number = to_number(interpreter);
if (interpreter.exception())
return 0;
if (as_double() <= 0)
if (number.is_nan())
return 0;
if (number.as_double() <= 0)
return 0;
return number.as_size_t();
}