diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c index 8030ccd8c..4fc03e1bb 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c @@ -2290,48 +2290,45 @@ ecma_builtin_array_prototype_object_find (ecma_value_t predicate, /**< callback for (uint32_t index = 0; index < len; index++) { /* 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)) { return get_value; } - if (ecma_is_value_found (get_value)) + /* 8.d - 8.e */ + ecma_value_t current_index = ecma_make_uint32_value (index); + + ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) }; + + ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); + + if (ECMA_IS_VALUE_ERROR (call_value)) { - /* 8.d - 8.e */ - ecma_value_t current_index = ecma_make_uint32_value (index); + ecma_free_value (get_value); + return call_value; + } - ecma_value_t call_args[] = { get_value, current_index, ecma_make_object_value (obj_p) }; + bool call_value_to_bool = ecma_op_to_boolean (call_value); - ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); + ecma_free_value (call_value); - if (ECMA_IS_VALUE_ERROR (call_value)) + if (call_value_to_bool) + { + /* 8.f */ + if (is_find) { - ecma_free_value (get_value); - return call_value; - } - - bool call_value_to_bool = ecma_op_to_boolean (call_value); - - ecma_free_value (call_value); - - if (call_value_to_bool) - { - /* 8.f */ - if (is_find) - { - ecma_free_value (current_index); - return get_value; - } - - ecma_free_value (get_value); - return current_index; + ecma_free_value (current_index); + return get_value; } ecma_free_value (get_value); - ecma_free_value (current_index); + return current_index; } + + ecma_free_value (get_value); + ecma_free_value (current_index); } /* 9. */ diff --git a/tests/jerry/es2015/array-prototype-find-index.js b/tests/jerry/es2015/array-prototype-find-index.js index 8a763144c..16227cdea 100644 --- a/tests/jerry/es2015/array-prototype-find-index.js +++ b/tests/jerry/es2015/array-prototype-find-index.js @@ -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); diff --git a/tests/jerry/es2015/array-prototype-find.js b/tests/jerry/es2015/array-prototype-find.js index a034c56da..c987301c2 100644 --- a/tests/jerry/es2015/array-prototype-find.js +++ b/tests/jerry/es2015/array-prototype-find.js @@ -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);