mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Fix Array.prototype.indexOf fromIndex negative
If negative fromIndex considers displacement from the end of the array without decreasing 1 of de size.
This commit is contained in:
parent
edd8abc4cf
commit
6d308113b8
Notes:
sideshowbarker
2024-07-19 07:23:06 +09:00
Author: https://github.com/kessejones Commit: https://github.com/SerenityOS/serenity/commit/6d308113b8a Pull-request: https://github.com/SerenityOS/serenity/pull/1913
2 changed files with 4 additions and 1 deletions
|
@ -321,7 +321,7 @@ Value ArrayPrototype::index_of(Interpreter& interpreter)
|
|||
if (from_index < negative_min_index)
|
||||
from_index = 0;
|
||||
else if (from_index < 0)
|
||||
from_index = (array_size - 1) + from_index;
|
||||
from_index = array_size + from_index;
|
||||
}
|
||||
|
||||
auto search_element = interpreter.argument(0);
|
||||
|
|
|
@ -14,6 +14,9 @@ try {
|
|||
assert(array.indexOf(1, 1000) === -1);
|
||||
assert(array.indexOf(1, -1000) === 2);
|
||||
assert(array.indexOf('serenity') === -1);
|
||||
assert(array.indexOf(false, -1) === 4);
|
||||
assert(array.indexOf(2, -1) === -1);
|
||||
assert(array.indexOf(2, -2) === 3);
|
||||
assert([].indexOf('serenity') === -1);
|
||||
assert([].indexOf('serenity', 10) === -1);
|
||||
assert([].indexOf('serenity', -10) === -1);
|
||||
|
|
Loading…
Add table
Reference in a new issue