From 5db9becc4a52c9dc84f88cb156b5cdf90d2ac75b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 21 May 2020 20:50:53 +0100 Subject: [PATCH] LibJS: Treat missing arg in Array.prototype.includes() as undefined --- Libraries/LibJS/Runtime/ArrayPrototype.cpp | 4 ++-- Libraries/LibJS/Tests/Array.prototype.includes.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 911b7be389..487e832c91 100644 --- a/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -422,8 +422,8 @@ Value ArrayPrototype::includes(Interpreter& interpreter) if (!array) return {}; - i32 array_size = static_cast(array->elements().size()); - if (interpreter.argument_count() == 0 || array_size == 0) + i32 array_size = array->elements().size(); + if (array_size == 0) return Value(false); i32 from_index = 0; diff --git a/Libraries/LibJS/Tests/Array.prototype.includes.js b/Libraries/LibJS/Tests/Array.prototype.includes.js index 8510bd4a85..3c1df81bbd 100644 --- a/Libraries/LibJS/Tests/Array.prototype.includes.js +++ b/Libraries/LibJS/Tests/Array.prototype.includes.js @@ -5,6 +5,8 @@ try { var array = ['hello', 'friends', 1, 2, false]; + assert([].includes() === false); + assert([undefined].includes() === true); assert(array.includes('hello') === true); assert(array.includes(1) === true); assert(array.includes(1, -3) === true);