1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

LibJS: Make Array.prototype.lastIndexOf slightly more spec compliant

This commit is contained in:
davidot 2021-06-25 16:52:57 +02:00 committed by Linus Groh
parent 44174a44bd
commit c7aaf40a35

View file

@ -1047,13 +1047,16 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of)
return Value(-1); return Value(-1);
i32 from_index = length - 1; i32 from_index = length - 1;
if (vm.argument_count() >= 2) { if (vm.argument_count() >= 2) {
from_index = vm.argument(1).to_i32(global_object); double from_argument = vm.argument(1).to_integer_or_infinity(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
if (from_index >= 0) if (vm.argument(1).is_negative_infinity()) {
from_index = min(from_index, length - 1); return Value(-1);
}
if (from_argument >= 0)
from_index = min(from_argument, length - 1.);
else else
from_index = length + from_index; from_index = length + from_argument;
} }
auto search_element = vm.argument(0); auto search_element = vm.argument(0);
for (i32 i = from_index; i >= 0; --i) { for (i32 i = from_index; i >= 0; --i) {