Fix undefined fromIndex in Array.prototype.lastIndexOf()
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com
This commit is contained in:
@@ -1862,10 +1862,11 @@ ecma_builtin_array_prototype_object_index_of (ecma_value_t this_arg, /**< this a
|
||||
*/
|
||||
static ecma_completion_value_t
|
||||
ecma_builtin_array_prototype_object_last_index_of (ecma_value_t this_arg, /**< this argument */
|
||||
ecma_value_t arg1, /**< searchElement */
|
||||
ecma_value_t arg2) /**< fromIndex */
|
||||
const ecma_value_t args[], /**< arguments list */
|
||||
ecma_length_t args_number) /**< number of arguments */
|
||||
{
|
||||
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
|
||||
ecma_value_t search_element = (args_number > 0) ? args[0] : ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED);
|
||||
|
||||
/* 1. */
|
||||
ECMA_TRY_CATCH (obj_this,
|
||||
@@ -1898,9 +1899,9 @@ ecma_builtin_array_prototype_object_last_index_of (ecma_value_t this_arg, /**< t
|
||||
uint32_t from_idx = len - 1;
|
||||
|
||||
/* 5. */
|
||||
if (!ecma_is_value_undefined (arg2))
|
||||
if (args_number > 1)
|
||||
{
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_from_idx, arg2, ret_value);
|
||||
ECMA_OP_TO_NUMBER_TRY_CATCH (arg_from_idx, args[1], ret_value);
|
||||
|
||||
if (!ecma_number_is_nan (arg_from_idx))
|
||||
{
|
||||
@@ -1972,7 +1973,7 @@ ecma_builtin_array_prototype_object_last_index_of (ecma_value_t this_arg, /**< t
|
||||
ECMA_TRY_CATCH (get_value, ecma_op_object_get (obj_p, idx_str_p), ret_value);
|
||||
|
||||
/* 8.b.ii */
|
||||
if (ecma_op_strict_equality_compare (arg1, get_value))
|
||||
if (ecma_op_strict_equality_compare (search_element, get_value))
|
||||
{
|
||||
*num_p = ecma_uint32_to_number (from_idx);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ ROUTINE (LIT_MAGIC_STRING_SORT, ecma_builtin_array_prototype_object_sort, 1, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SPLICE, ecma_builtin_array_prototype_object_splice, NON_FIXED, 2)
|
||||
ROUTINE (LIT_MAGIC_STRING_UNSHIFT, ecma_builtin_array_prototype_object_unshift, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_INDEX_OF_UL, ecma_builtin_array_prototype_object_index_of, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_array_prototype_object_last_index_of, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_LAST_INDEX_OF_UL, ecma_builtin_array_prototype_object_last_index_of, NON_FIXED, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_EVERY, ecma_builtin_array_prototype_object_every, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_SOME, ecma_builtin_array_prototype_object_some, 2, 1)
|
||||
ROUTINE (LIT_MAGIC_STRING_FOR_EACH_UL, ecma_builtin_array_prototype_object_for_each, 2, 1)
|
||||
|
||||
@@ -41,6 +41,10 @@ var arr = [];
|
||||
arr[4294967294] = "foo";
|
||||
assert(arr.lastIndexOf("foo", -1) === 4294967294)
|
||||
|
||||
var arr = [1,2];
|
||||
assert(arr.lastIndexOf(2, undefined) === -1);
|
||||
assert(arr.lastIndexOf(2) === 1);
|
||||
|
||||
// Checking behavior when unable to get length
|
||||
var obj = { lastIndexOf : Array.prototype.lastIndexOf}
|
||||
Object.defineProperty(obj, 'length', { 'get' : function () { throw new ReferenceError ("foo"); } });
|
||||
|
||||
Reference in New Issue
Block a user