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:
@@ -2290,15 +2290,13 @@ ecma_builtin_array_prototype_object_find (ecma_value_t predicate, /**< callback
|
|||||||
for (uint32_t index = 0; index < len; index++)
|
for (uint32_t index = 0; index < len; index++)
|
||||||
{
|
{
|
||||||
/* 8.a - 8.c */
|
/* 8.a - 8.c */
|
||||||
ecma_value_t get_value = ecma_op_object_find_by_uint32_index (obj_p, index);
|
ecma_value_t get_value = ecma_op_object_get_by_uint32_index (obj_p, index);
|
||||||
|
|
||||||
if (ECMA_IS_VALUE_ERROR (get_value))
|
if (ECMA_IS_VALUE_ERROR (get_value))
|
||||||
{
|
{
|
||||||
return get_value;
|
return get_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecma_is_value_found (get_value))
|
|
||||||
{
|
|
||||||
/* 8.d - 8.e */
|
/* 8.d - 8.e */
|
||||||
ecma_value_t current_index = ecma_make_uint32_value (index);
|
ecma_value_t current_index = ecma_make_uint32_value (index);
|
||||||
|
|
||||||
@@ -2332,7 +2330,6 @@ ecma_builtin_array_prototype_object_find (ecma_value_t predicate, /**< callback
|
|||||||
ecma_free_value (get_value);
|
ecma_free_value (get_value);
|
||||||
ecma_free_value (current_index);
|
ecma_free_value (current_index);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* 9. */
|
/* 9. */
|
||||||
return is_find ? ECMA_VALUE_UNDEFINED : ecma_make_integer_value (-1);
|
return is_find ? ECMA_VALUE_UNDEFINED : ecma_make_integer_value (-1);
|
||||||
|
|||||||
@@ -153,3 +153,10 @@ function func (element) {
|
|||||||
var arr = [0, 1, 2, 3];
|
var arr = [0, 1, 2, 3];
|
||||||
Object.defineProperty(arr, '0', { 'get' : f });
|
Object.defineProperty(arr, '0', { 'get' : f });
|
||||||
Array.prototype.findIndex.call(arr, func);
|
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];
|
var arr = [0, 1, 2, 3];
|
||||||
Object.defineProperty(arr, '0', { 'get' : f });
|
Object.defineProperty(arr, '0', { 'get' : f });
|
||||||
Array.prototype.find.call(arr, func);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user