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

Code before:
    case ECMA_STRING_ENDS_WITH:
    {
      if (start == 0)
      {
        start = original_len;
      }

      lit_utf8_size_t search_str_len = ecma_string_get_length (search_str_p);

      if (search_str_len == 0)
      {
        ret_value = ECMA_VALUE_TRUE;
        break;
      }

      int32_t start_ends_with = (int32_t) (start - search_str_len);

      if (start_ends_with < 0)
      {
        break;
      }
      ecma_value_t index = ecma_builtin_helper_string_find_index (original_str_p,
                                                 search_str_p,
                                                 (uint32_t) start_ends_with);

      if (index != UINT32_MAX)
      {
        ret_value = ecma_make_boolean_value (index  == (uint32_t) start_ends_with);
      }
      break;
    }
#endif /* ENABLED (JERRY_ESNEXT) */

    case ECMA_STRING_INDEX_OF:
    {
      /* 8 (indexOf) -- 9 (lastIndexOf) */
      ecma_value_t find_index = ecma_builtin_helper_string_find_index (original_str_p, search_str_p, start);
      if (find_index != UINT32_MAX)
      {
        ret_num = ((ecma_number_t) find_index);
      }
      ret_value = ecma_make_number_value (ret_num);
      break;
    }

    case ECMA_STRING_LAST_INDEX_OF:
    {
      ret_value = ecma_builtin_helper_string_find_last_index (original_str_p, search_str_p, arg2);

      ecma_deref_ecma_string (search_str_p);


Review comment (refactor):
I don't think this check is necessary, you could do
```
ecma_value_t index = ecma_builtin_helper_string_find_index (...)
ret_value = ecma_make_boolean_value (index == (uint32_t) start_ends_with);
break;
```

Code after:
                                                              search_str_p,
                                                              (uint32_t) start_ends_with);
      ret_value = ecma_make_boolean_value (index  == (uint32_t) start_ends_with);
      break;
    }
#endif /* ENABLED (JERRY_ESNEXT) */

    case ECMA_STRING_INDEX_OF:
    {
      /* 8 (indexOf) -- 9 (lastIndexOf) */
      ecma_value_t find_index = ecma_builtin_helper_string_find_index (original_str_p, search_str_p, start);

      if (find_index != UINT32_MAX)
      {
        ret_num = ((ecma_number_t) find_index);
      }
      ret_value = ecma_make_number_value (ret_num);
      break;
    }

    case ECMA_STRING_LAST_INDEX_OF:
    {
      uint32_t index = ecma_builtin_helper_string_find_last_index (original_str_p, search_str_p, start);

      if (index != UINT32_MAX)
      {
        ret_num = ((ecma_number_t) index);
      }
      ret_value = ecma_make_number_value (ret_num);
      break;
    }

    default:
    {
      JERRY_UNREACHABLE ();
    }
  }

  ecma_deref_ecma_string (search_str_p);

  return ret_value;
} /* ecma_builtin_helper_string_prototype_object_index_of */

/**
 * Helper function for finding index of a search string
 *
 * This function clamps the given index to the [0, length] range.
 * If the index is negative, 0 value is used.
 * If the index is greater than the length of the string, the normalized index will be the length of the string.
 *
 * See also: