summaryrefslogtreecommitdiff
path: root/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-22 17:34:52 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-23 00:02:13 +0200
commit6a4280e6e52533a9fc242826dacd91c1c43142c8 (patch)
tree7b94d9701e2d98035964b6e7b9254270b78e6cea /Libraries/LibJS
parenta3e4dfdf9859a9b955bf4728328f740a47de5851 (diff)
downloadserenity-6a4280e6e52533a9fc242826dacd91c1c43142c8.zip
LibJS: Treat missing arg in Array.prototype.{indexOf,lastIndexOf}() as undefined
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) {