Fix Array.find and Array.findIndex omitting empty values. (#3563)

Empty values in array were omitted. Predicate should be called
for every element from 0 to length.

JerryScript-DCO-1.0-Signed-off-by: Rafal Walczyna r.walczyna@samsung.com
This commit is contained in:
rwalczyna
2020-02-18 15:19:53 +01:00
committed by GitHub
parent 181570ff41
commit 0ff664cab6
3 changed files with 42 additions and 31 deletions
@@ -149,7 +149,14 @@ function func (element) {
/* ES v6.0 22.1.3.9.8.c
Checking behavior when the first element deletes the second */
function f() { delete arr[1]; };
var arr = [0, 1, 2, 3];
Object.defineProperty(arr, '0', { 'get' : f });
Array.prototype.findIndex.call(arr, func);
function f() { delete arr[1]; };
var arr = [0, 1, 2, 3];
Object.defineProperty(arr, '0', { 'get' : f });
Array.prototype.findIndex.call(arr, func);
/* ES v6.0 22.1.3.9.8
Checking whether predicate is called also for empty elements */
var count = 0;
[,,,].findIndex(function() { count++; return false; });
assert (count == 3);
@@ -146,3 +146,10 @@ function f() { delete arr[1]; };
var arr = [0, 1, 2, 3];
Object.defineProperty(arr, '0', { 'get' : f });
Array.prototype.find.call(arr, func);
/* ES v6.0 22.1.3.8.8
Checking whether predicate is called also for empty elements */
var count = 0;
[,,,].find(function() { count++; return false; });
assert (count == 3);