Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c (C)

Code before:
  ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, new_len);

  if (ECMA_IS_VALUE_ERROR (set_length_value))
  {
    return set_length_value;
  }

  return ecma_make_number_value (new_len);
} /* ecma_builtin_array_prototype_object_unshift */

/**
 * The Array.prototype object's 'at' routine
 *
 * See also:
 *          ECMA-262 Stage 3 Draft
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_array_prototype_object_at (const ecma_value_t index, /**< index argument */
                                        ecma_object_t *obj_p, /**< object */
                                        ecma_length_t len) /**< object's length */
{

  ecma_number_t relative_index, k;
  ecma_value_t index_to_integer = ecma_op_to_integer (index, &relative_index);

  /* 3. */
  if (ECMA_IS_VALUE_ERROR (index_to_integer))
  {
    return ECMA_VALUE_ERROR;
  }

  /* 4. 5. */
  if (relative_index >= 0)
  {
    k = relative_index;
  }
  else
  {
    k = (ecma_number_t) len + relative_index;
  }

  /* 6. */
  if (k < 0 || k >= (ecma_number_t) len)
  {
    return ECMA_VALUE_UNDEFINED;
  }

  /* 7. */

Review comment (refactor):
The `k` variable can be defined just before its first usage. Please move this var's definition just before line 1638. In addition we can have "ecma_length_t" as its type.

Code after:
  ecma_value_t set_length_value = ecma_builtin_array_prototype_helper_set_length (obj_p, new_len);

  if (ECMA_IS_VALUE_ERROR (set_length_value))
  {
    return set_length_value;
  }

  return ecma_make_number_value (new_len);
} /* ecma_builtin_array_prototype_object_unshift */

/**
 * The Array.prototype object's 'at' routine
 *
 * See also:
 *          ECMA-262 Stage 3 Draft Relative Indexing Method proposal
 *          from: https://tc39.es/proposal-relative-indexing-method
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_array_prototype_object_at (const ecma_value_t index, /**< index argument */
                                        ecma_object_t *obj_p, /**< object */
                                        ecma_length_t len) /**< object's length */
{
  ecma_length_t res_index;
  ecma_value_t return_value = ecma_builtin_helper_calculate_index (index, len, &res_index);

  if (return_value != ECMA_VALUE_EMPTY)
  {
    return return_value;
  }

  return ecma_op_object_get_by_index (obj_p, res_index);
} /* ecma_builtin_array_prototype_object_at */

/**
 * The Array.prototype object's 'indexOf' routine
 *
 * See also:
 *          ECMA-262 v5, 15.4.4.14
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
static ecma_value_t
ecma_builtin_array_prototype_object_index_of (const ecma_value_t args[], /**< arguments list */
                                              uint32_t args_number, /**< number of arguments */
                                              ecma_object_t *obj_p, /**< object */
                                              ecma_length_t len) /**< object's length */
{