mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibJS: Treat missing arg in Array.prototype.{indexOf,lastIndexOf}() as undefined
This commit is contained in:
parent
a3e4dfdf98
commit
6a4280e6e5
Notes:
sideshowbarker
2024-07-19 06:14:40 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/6a4280e6e52 Pull-request: https://github.com/SerenityOS/serenity/pull/2332
3 changed files with 7 additions and 2 deletions
|
@ -357,7 +357,7 @@ Value ArrayPrototype::index_of(Interpreter& interpreter)
|
|||
return {};
|
||||
|
||||
i32 array_size = static_cast<i32>(array->elements().size());
|
||||
if (interpreter.argument_count() == 0 || array_size == 0)
|
||||
if (array_size == 0)
|
||||
return Value(-1);
|
||||
|
||||
i32 from_index = 0;
|
||||
|
@ -411,7 +411,7 @@ Value ArrayPrototype::last_index_of(Interpreter& interpreter)
|
|||
return {};
|
||||
|
||||
i32 array_size = static_cast<i32>(array->elements().size());
|
||||
if (interpreter.argument_count() == 0 || array_size == 0)
|
||||
if (array_size == 0)
|
||||
return Value(-1);
|
||||
|
||||
i32 from_index = 0;
|
||||
|
|
|
@ -20,6 +20,8 @@ try {
|
|||
assert([].indexOf('serenity') === -1);
|
||||
assert([].indexOf('serenity', 10) === -1);
|
||||
assert([].indexOf('serenity', -10) === -1);
|
||||
assert([].indexOf() === -1);
|
||||
assert([undefined].indexOf() === 0);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
|
@ -15,6 +15,9 @@ try {
|
|||
assert([].lastIndexOf('hello') === -1);
|
||||
assert([].lastIndexOf('hello', 10) === -1);
|
||||
assert([].lastIndexOf('hello', -10) === -1);
|
||||
assert([].lastIndexOf() === -1);
|
||||
assert([undefined].lastIndexOf() === 0);
|
||||
assert([undefined, undefined, undefined].lastIndexOf() === 2);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue