mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +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:
parent
3bc3f36cfe
commit
eb72ba2466
Notes:
sideshowbarker
2024-07-19 06:31:40 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/eb72ba24663 Pull-request: https://github.com/SerenityOS/serenity/pull/2277 Reviewed-by: https://github.com/awesomekling
2 changed files with 6 additions and 4 deletions
|
@ -118,7 +118,9 @@ Value StringPrototype::repeat(Interpreter& interpreter)
|
|||
return interpreter.throw_exception<RangeError>("repeat count must be a positive number");
|
||||
if (count_value.is_infinity())
|
||||
return interpreter.throw_exception<RangeError>("repeat count must be a finite number");
|
||||
auto count = count_value.as_size_t();
|
||||
auto count = count_value.to_size_t(interpreter);
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
StringBuilder builder;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
builder.append(string);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue