summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r--Libraries/LibJS/Runtime/ArrayPrototype.cpp4
-rw-r--r--Libraries/LibJS/Tests/Array.prototype.indexOf.js2
-rw-r--r--Libraries/LibJS/Tests/Array.prototype.lastIndexOf.js3
3 files changed, 7 insertions, 2 deletions
diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index ecd14217c1..edfa930ed2 100644
--- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -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;
diff --git a/Libraries/LibJS/Tests/Array.prototype.indexOf.js b/Libraries/LibJS/Tests/Array.prototype.indexOf.js
index 630745c283..12cc3e7333 100644
--- a/Libraries/LibJS/Tests/Array.prototype.indexOf.js
+++ b/Libraries/LibJS/Tests/Array.prototype.indexOf.js
@@ -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) {
diff --git a/Libraries/LibJS/Tests/Array.prototype.lastIndexOf.js b/Libraries/LibJS/Tests/Array.prototype.lastIndexOf.js
index 642c897292..1ae10c4e55 100644
--- a/Libraries/LibJS/Tests/Array.prototype.lastIndexOf.js
+++ b/Libraries/LibJS/Tests/Array.prototype.lastIndexOf.js
@@ -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) {