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

Code before:
  {
    return ecma_builtin_helper_def_prop (obj_p,
                                         ECMA_CREATE_DIRECT_UINT32_STRING (index),
                                         value,
                                         opts);
  }

  ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index);
  ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p, index_str_p, value, opts);
  ecma_deref_ecma_string (index_str_p);

  return ret_value;
} /* ecma_builtin_helper_def_prop_by_index */

/**
 * Helper function for at() functions.
 *
 * See also:
 *          ECMA-262 Stage 3 Draft Relative Indexing Method proposal 3. 4. 5. 6.
 *
 * Used by:
 *         - The Array.prototype.at routine.
 *         - The String.prototype.at routine.
 *         - The TypedArray.prototype.at routine.
 *
 * @return ecma value
 *
 */
ecma_value_t
ecma_builtin_helper_check_index (ecma_value_t index, /**< index argument */
                                 ecma_number_t *len) /**< [out] object's length */
{
  ecma_number_t relative_index;
  ecma_value_t conversion_result = ecma_op_to_integer (index, &relative_index);

   /* 4. */
  if (ECMA_IS_VALUE_ERROR (conversion_result))
  {
    return ECMA_VALUE_ERROR;
  }

  /* 5. 6. */
  ecma_number_t k;

  if (relative_index >= 0)
  {
    k = relative_index;
  }
  else
  {
    k = (*len + relative_index);

Review comment (suggestion):
```
* @return ECMA_VALUE_ERROR - on conversion error
*         ECMA_VALUE_UNDEFINED - if the requested index is not exist
*         ECMA_VALUE_EMPTY - otherwise
*/              
```

Code after:
  {
    return ecma_builtin_helper_def_prop (obj_p,
                                         ECMA_CREATE_DIRECT_UINT32_STRING (index),
                                         value,
                                         opts);
  }

  ecma_string_t *index_str_p = ecma_new_ecma_string_from_length (index);
  ecma_value_t ret_value = ecma_builtin_helper_def_prop (obj_p, index_str_p, value, opts);
  ecma_deref_ecma_string (index_str_p);

  return ret_value;
} /* ecma_builtin_helper_def_prop_by_index */

/**
 * Helper function for at() functions.
 *
 * See also:
 *          ECMA-262 Stage 3 Draft Relative Indexing Method proposal 3. 4. 5. 6.
 *
 * Used by:
 *         - The Array.prototype.at routine.
 *         - The String.prototype.at routine.
 *         - The TypedArray.prototype.at routine.
 *
 * @return ECMA_VALUE_ERROR - on conversion error
 *         ECMA_VALUE_UNDEFINED - if the requested index is not exist
 *         ECMA_VALUE_EMPTY - otherwise
 */
ecma_value_t
ecma_builtin_helper_calculate_index (ecma_value_t index, /**< relative index argument */
                                     ecma_length_t length, /**< object's length */
                                     ecma_length_t *out_index) /**< calculated index */
{
  JERRY_ASSERT (out_index != NULL);

  ecma_number_t relative_index;
  ecma_value_t conversion_result = ecma_op_to_integer (index, &relative_index);

   /* 4. */
  if (ECMA_IS_VALUE_ERROR (conversion_result))
  {
    return ECMA_VALUE_ERROR;
  }

  /* 5. 6. */
  ecma_number_t k;

  if (relative_index >= 0)
  {
    k = relative_index;