ronantakizawa/codereview-bench huggingface dataset:
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-objects.c (C)

Code before:
ecma_op_object_get_prototype_of (ecma_object_t *obj_p) /**< input object */
{
  JERRY_ASSERT (obj_p != NULL);

#if ENABLED (JERRY_BUILTIN_PROXY)
  if (ECMA_OBJECT_IS_PROXY (obj_p))
  {
    ecma_value_t proto = ecma_proxy_object_get_prototype_of (obj_p);

    if (ECMA_IS_VALUE_ERROR (proto))
    {
      return ECMA_OBJECT_POINTER_ERROR;
    }
    else if (ecma_is_value_null (proto))
    {
      return NULL;
    }

    JERRY_ASSERT (ecma_is_value_object (proto));

    return ecma_get_object_from_value (proto);
  }
  else
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
  {
    ecma_object_t *proto = ECMA_GET_POINTER (ecma_object_t, ecma_op_ordinary_object_get_prototype_of (obj_p));
    if (proto != NULL)
    {
      ecma_ref_object (proto);
    }

    return proto;
  }
} /* ecma_op_object_get_prototype_of */

/**
 * Object's isPrototypeOf operation
 *
 * See also:
 *          ECMA-262 v5, 15.2.4.6; 3
 *
 * @return ECMA_VALUE_ERROR - if the operation fails
 *         ECMA_VALUE_TRUE - if the target object is prototype of the base object
 *         ECMA_VALUE_FALSE - if the target object is not prototype of the base object
 */
ecma_value_t
ecma_op_object_is_prototype_of (ecma_object_t *base_p, /**< base object */
                                ecma_object_t *target_p) /**< target object */
{
  ecma_ref_object (target_p);


Review comment (suggestion):
I see a double null check here, since `ECMA_GET_POINTER ` also checks for JMEM_CP_NULL. I suggest:

```c
jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (func_obj_p);

if (proto_cp == JMEM_CP_NULL)
{   
  return NULL;
}

ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
ecma_ref_object (proto_p );
return proto_p;
```

Code after:
} /* ecma_op_object_has_instance */

/**
 * General [[GetPrototypeOf]] abstract operation
 *
 * Note: returned valid object must be freed.
 *
 * @return ecma_object_t * - prototype of the input object.
 *         ECMA_OBJECT_POINTER_ERROR - error reported during Proxy resolve.
 *         NULL - the input object does not have a prototype.
 */
ecma_object_t *
ecma_op_object_get_prototype_of (ecma_object_t *obj_p) /**< input object */
{
  JERRY_ASSERT (obj_p != NULL);

#if ENABLED (JERRY_BUILTIN_PROXY)
  if (ECMA_OBJECT_IS_PROXY (obj_p))
  {
    ecma_value_t proto = ecma_proxy_object_get_prototype_of (obj_p);

    if (ECMA_IS_VALUE_ERROR (proto))
    {
      return ECMA_OBJECT_POINTER_ERROR;
    }
    if (ecma_is_value_null (proto))
    {
      return NULL;
    }

    JERRY_ASSERT (ecma_is_value_object (proto));

    return ecma_get_object_from_value (proto);
  }
  else
#endif /* ENABLED (JERRY_BUILTIN_PROXY) */
  {
    jmem_cpointer_t proto_cp = ecma_op_ordinary_object_get_prototype_of (obj_p);

    if (proto_cp == JMEM_CP_NULL)
    {
      return NULL;
    }

    ecma_object_t *proto_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, proto_cp);
    ecma_ref_object (proto_p);

    return proto_p;
  }
} /* ecma_op_object_get_prototype_of */
Repository: jerryscript-project/jerryscript
File: jerry-ext/debugger/debugger-tcp.c (C)

Code before:
{
  struct sockaddr_in addr;

  addr.sin_family = AF_INET;
  addr.sin_port = htons (port);
  addr.sin_addr.s_addr = INADDR_ANY;

  int opt_value = 1;

  if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, (const char *) &opt_value, sizeof (int)) != 0)
  {
    return false;
  }

  if (bind (server_socket, (struct sockaddr *) &addr, sizeof (struct sockaddr_in)) != 0)
  {
    return false;
  }

  if (listen (server_socket, 1) != 0)
  {
    return false;
  }

  return true;
} /* jerryx_debugger_tcp_configure_socket */

/**
 * Create a tcp connection.
 *
 * @return true if successful,
 *         false otherwise
 */
bool
jerryx_debugger_tcp_create (uint16_t port) /**< listening port */
{
#ifdef _WIN32
  WSADATA wsaData;
  int wsa_init_status = WSAStartup (MAKEWORD (2, 2), &wsaData);
  if (wsa_init_status != NO_ERROR)
  {
    JERRYX_ERROR_MSG ("WSA Error: %d\n", wsa_init_status);
    return false;
  }
#endif /* _WIN32*/

  jerryx_socket server_socket = socket (AF_INET, SOCK_STREAM, 0);
  if (server_socket == JERRYX_SOCKET_INVALID)
  {
    jerryx_debugger_tcp_log_error (jerryx_debugger_tcp_get_errno ());
    return false;

Review comment (suggestion):
The signature of `setsockopt` is also platform-dependent.
Windows: `int setsockopt(SOCKET s, int level, int optname, const char *optval, int optlen);`
Linux: `int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);`

So, I think it would be good to add yet another typedef, `jerryx_socket_opt_t` (extend the code suggested in the previous comment).

Code after:
  return true;
} /* jerryx_debugger_tcp_receive */

/**
 * Utility method to prepare the server socket to accept connections.
 *
 * The following steps are performed:
 *  * Configure address re-use.
 *  * Bind the socket to the given port
 *  * Start listening on the socket.
 *
 * @return true if everything is ok
 *         false if there was an error
 */
static bool
jerryx_debugger_tcp_configure_socket (jerryx_socket_t server_socket, /** < socket to configure */
                                      uint16_t port) /** < port number to be used for the socket */
{
  struct sockaddr_in addr;

  addr.sin_family = AF_INET;
  addr.sin_port = htons (port);
  addr.sin_addr.s_addr = INADDR_ANY;

  const int opt_value = 1;

  if (setsockopt (server_socket,
                  SOL_SOCKET, SO_REUSEADDR,
                  (const jerryx_socket_void_t *) &opt_value,
                  sizeof (int)) != 0)
  {
    return false;
  }

  if (bind (server_socket, (struct sockaddr *) &addr, sizeof (struct sockaddr_in)) != 0)
  {
    return false;
  }

  if (listen (server_socket, 1) != 0)
  {
    return false;
  }

  return true;
} /* jerryx_debugger_tcp_configure_socket */

/**
 * Create a tcp connection.
 *
 * @return true if successful,
Repository: jerryscript-project/jerryscript
File: jerry-ext/debugger/debugger-tcp.c (C)

Code before:
  return true;
} /* jerryx_debugger_tcp_receive */

/**
 * Utility method to prepare the server socket to accept connections.
 *
 * The following steps are performed:
 *  * Configure address re-use.
 *  * Bind the socket to the given port
 *  * Start listening on the socket.
 *
 * @return true if everything is ok
 *         false if there was an error
 */
static bool
jerryx_debugger_tcp_configure_socket (jerryx_socket_t server_socket, /** < socket to configure */
                                      uint16_t port) /** < port number to be used for the socket */
{
  struct sockaddr_in addr;

  addr.sin_family = AF_INET;
  addr.sin_port = htons (port);
  addr.sin_addr.s_addr = INADDR_ANY;

  const int opt_value = 1;
  const jerryx_socket_void_t *opt_value_p = (const jerryx_socket_void_t *) &opt_value;

  if (setsockopt (server_socket, SOL_SOCKET, SO_REUSEADDR, opt_value_p, sizeof (int)) != 0)
  {
    return false;
  }

  if (bind (server_socket, (struct sockaddr *) &addr, sizeof (struct sockaddr_in)) != 0)
  {
    return false;
  }

  if (listen (server_socket, 1) != 0)
  {
    return false;
  }

  return true;
} /* jerryx_debugger_tcp_configure_socket */

/**
 * Create a tcp connection.
 *
 * @return true if successful,
 *         false otherwise
 */

Review comment (suggestion):
This variable is unnecessary. Do the cast in the call to `setsockopt`.

Code after:
  }

  return true;
} /* jerryx_debugger_tcp_receive */

/**
 * Utility method to prepare the server socket to accept connections.
 *
 * The following steps are performed:
 *  * Configure address re-use.
 *  * Bind the socket to the given port
 *  * Start listening on the socket.
 *
 * @return true if everything is ok
 *         false if there was an error
 */
static bool
jerryx_debugger_tcp_configure_socket (jerryx_socket_t server_socket, /** < socket to configure */
                                      uint16_t port) /** < port number to be used for the socket */
{
  struct sockaddr_in addr;

  addr.sin_family = AF_INET;
  addr.sin_port = htons (port);
  addr.sin_addr.s_addr = INADDR_ANY;

  const int opt_value = 1;

  if (setsockopt (server_socket,
                  SOL_SOCKET, SO_REUSEADDR,
                  (const jerryx_socket_void_t *) &opt_value,
                  sizeof (int)) != 0)
  {
    return false;
  }

  if (bind (server_socket, (struct sockaddr *) &addr, sizeof (struct sockaddr_in)) != 0)
  {
    return false;
  }

  if (listen (server_socket, 1) != 0)
  {
    return false;
  }

  return true;
} /* jerryx_debugger_tcp_configure_socket */

/**
 * Create a tcp connection.
Repository: jerryscript-project/jerryscript
File: jerry-math/expm1.c (C)

Code before:
    e -= hxs;
    if (k == -1)
    {
      return 0.5 * (x - e) - 0.5;
    }
    if (k == 1)
    {
      if (x < -0.25)
      {
        return -2.0 * (e - (x + 0.5));
      }
      else
      {
        return one + 2.0 * (x - e);
      }
    }
    if ((k <= -2) || (k > 56))
    {
      /* suffice to return exp(x)-1 */
      y = one - (e - x);
      if (k == 1024)
      {
        double_accessor const_0x1p1023;
        const_0x1p1023.as_int.hi = 0x7fe00000;
        const_0x1p1023.as_int.lo = 0;
        y = y * 2.0 * const_0x1p1023.dbl;
      }
      else
      {
        y = y * twopk.dbl;
      }
      return y - one;
    }
    t.dbl = one;
    if (k < 20)
    {
      t.as_int.hi = (0x3ff00000 - (0x200000 >> k)); /* t=1-2^-k */
      y = t.dbl - (e - x);
      y = y * twopk.dbl;
    }
    else
    {
      t.as_int.hi = ((0x3ff - k) << 20); /* 2^-k */
      y = x - (e + t.dbl);
      y += one;
      y = y * twopk.dbl;
    }
  }
  return y;
} /* expm1 */


Review comment (suggestion):
I'd prefer a slightly different approach:
```c
        const double twop1023 = ((double_accessor) { .as_int = { .hi = 0x7fe00000, .lo = 0 } }).dbl; // 0x1p1023
        y = y * 2.0 * twop1023;
```

Code after:
    e -= hxs;
    if (k == -1)
    {
      return 0.5 * (x - e) - 0.5;
    }
    if (k == 1)
    {
      if (x < -0.25)
      {
        return -2.0 * (e - (x + 0.5));
      }
      else
      {
        return one + 2.0 * (x - e);
      }
    }
    if ((k <= -2) || (k > 56))
    {
      /* suffice to return exp(x)-1 */
      y = one - (e - x);
      if (k == 1024)
      {
        const double twop1023 = ((double_accessor)
          {
            .as_int = { .hi = 0x7fe00000, .lo = 0 }
          }
        ).dbl; /* 0x1p1023 */
        y = y * 2.0 * twop1023;
      }
      else
      {
        y = y * twopk.dbl;
      }
      return y - one;
    }
    t.dbl = one;
    if (k < 20)
    {
      t.as_int.hi = (0x3ff00000 - (0x200000 >> k)); /* t=1-2^-k */
      y = t.dbl - (e - x);
      y = y * twopk.dbl;
    }
    else
    {
      t.as_int.hi = ((0x3ff - k) << 20); /* 2^-k */
      y = x - (e + t.dbl);
      y += one;
      y = y * twopk.dbl;
    }
  }
  return y;
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-promise-object.h (C/C++)

Code before:
 * limitations under the License.
 */

#ifndef ECMA_PROMISE_OBJECT_H
#define ECMA_PROMISE_OBJECT_H

#if JERRY_BUILTIN_PROMISE
#include "ecma-globals.h"

/** \addtogroup ecma ECMA
 * @{
 *
 * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines
 * @{
 */

/**
 * The PromiseState of promise object.
 */
typedef enum
{
  ECMA_PROMISE_IS_PENDING = (1 << 0), /**< pending state */
  ECMA_PROMISE_IS_FULFILLED = (1 << 1), /**< fulfilled state */
  ECMA_PROMISE_ALREADY_RESOLVED = (1 << 2), /**< already resolved */
#if JERRY_PROMISE_CALLBACK
  ECMA_PROMISE_UNHANDLED_REJECT = (1 << 3), /**< a Promise is rejected without a catch handler */
#endif /* JERRY_PROMISE_CALLBACK */
} ecma_promise_flags_t;

/**
 * Description of a promise resolving function.
 */
typedef struct
{
  ecma_extended_object_t header;
  ecma_value_t promise;
} ecma_promise_resolver_t;

/**
 * Description of the promise object.
 * It need more space than normal object to store builtin properties.
 */
typedef struct
{
  ecma_extended_object_t header; /**< extended object part */
  ecma_collection_t *reactions; /**< list of promise reactions */
} ecma_promise_object_t;

/**
 * Description of the finally function object
 */

Review comment (suggestion):
So this bit is used for the `[[PromiseIsHandled]]` ? Could we add the ES reference into the comment? So we can grep for if someone looks for it.

Code after:
 * limitations under the License.
 */

#ifndef ECMA_PROMISE_OBJECT_H
#define ECMA_PROMISE_OBJECT_H

#if JERRY_BUILTIN_PROMISE
#include "ecma-globals.h"

/** \addtogroup ecma ECMA
 * @{
 *
 * \addtogroup ecmaarraybufferobject ECMA ArrayBuffer object related routines
 * @{
 */

/**
 * The PromiseState of promise object.
 */
typedef enum
{
  ECMA_PROMISE_IS_PENDING = (1 << 0), /**< pending state */
  ECMA_PROMISE_IS_FULFILLED = (1 << 1), /**< fulfilled state */
  ECMA_PROMISE_ALREADY_RESOLVED = (1 << 2), /**< already resolved */
#if JERRY_PROMISE_CALLBACK
  ECMA_PROMISE_UNHANDLED_REJECT = (1 << 3), /**< a Promise is rejected without a catch handler,
                                             *   related to ES11: 25.6.6 [[PromiseIsHandled]] */
#endif /* JERRY_PROMISE_CALLBACK */
} ecma_promise_flags_t;

/**
 * Description of a promise resolving function.
 */
typedef struct
{
  ecma_extended_object_t header;
  ecma_value_t promise;
} ecma_promise_resolver_t;

/**
 * Description of the promise object.
 * It need more space than normal object to store builtin properties.
 */
typedef struct
{
  ecma_extended_object_t header; /**< extended object part */
  ecma_collection_t *reactions; /**< list of promise reactions */
} ecma_promise_object_t;

/**
 * Description of the finally function object
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/typedarray/ecma-builtin-typedarray-prototype.c (C)

Code before:
  if (args_number == 0
      || (!ecma_is_value_number (args[0]) && !is_bigint)
      || info_p->length == 0)
  {
    return ECMA_VALUE_FALSE;
  }

  uint32_t from_index = 0;

  if (args_number > 1)
  {
    if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &from_index)))
    {
      return ECMA_VALUE_ERROR;
    }
  }

  ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id);

  uint32_t search_pos = (uint32_t) from_index * info_p->element_size;

  while (search_pos < limit)
  {
    ecma_value_t element = getter_cb (info_p->buffer_p + search_pos);

    if (ecma_arraybuffer_is_detached (info_p->array_buffer_p))
    {
      ecma_free_value (element);
      return ecma_raise_type_error (ECMA_ERR_MSG ("ArrayBuffer has been detached"));
    }

    if (ecma_op_same_value_zero (args[0], element, false))
    {
      ecma_free_value (element);
      return ECMA_VALUE_TRUE;
    }

    ecma_free_value (element);
    search_pos += info_p->element_size;
  }

  return ECMA_VALUE_FALSE;
} /* ecma_builtin_typedarray_prototype_includes */

/**
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_typedarray_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide

Review comment (suggestion):
According to the standard https://262.ecma-international.org/11.0/#sec-%typedarray%.prototype.fill this must be outsode of this loop.

Code after:
      || (!ecma_is_value_number (args[0]) && !is_bigint)
      || info_p->length == 0)
  {
    return ECMA_VALUE_FALSE;
  }

  uint32_t from_index = 0;

  if (args_number > 1)
  {
    if (ECMA_IS_VALUE_ERROR (ecma_builtin_helper_uint32_index_normalize (args[1], info_p->length, &from_index)))
    {
      return ECMA_VALUE_ERROR;
    }
  }

  ecma_typedarray_getter_fn_t getter_cb = ecma_get_typedarray_getter_fn (info_p->id);

  uint32_t search_pos = (uint32_t) from_index * info_p->element_size;

  if (ecma_arraybuffer_is_detached (info_p->array_buffer_p))
  {
    return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached));
  }

  while (search_pos < limit)
  {
    ecma_value_t element = getter_cb (info_p->buffer_p + search_pos);

    if (ecma_op_same_value_zero (args[0], element, false))
    {
      ecma_free_value (element);
      return ECMA_VALUE_TRUE;
    }

    ecma_free_value (element);
    search_pos += info_p->element_size;
  }

  return ECMA_VALUE_FALSE;
} /* ecma_builtin_typedarray_prototype_includes */

/**
 *
 * @return ecma value
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_typedarray_prototype_dispatch_routine (uint8_t builtin_routine_id, /**< built-in wide
                                                                                 *   routine identifier */
                                                    ecma_value_t this_arg, /**< 'this' argument value */
Repository: jerryscript-project/jerryscript
File: tests/jerry/es.next/typedarray-prototype-at.js (JavaScript)

Code before:
  new Uint8Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint8ClampedArray([0, 1, 2, 3, 0, 5, 6]),
  new Int16Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint16Array([0, 1, 2, 3, 0, 5, 6]),
  new Int32Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint32Array([0, 1, 2, 3, 0, 5, 6]),
  new Float32Array([0.5, 1.5, 2.5, 3.5, 0.5, 5.5, 6.5]),
  new Float64Array([1.5, 2.5, 3.5, 0.5, 5.5, 6.5, 2.5]),
  new BigInt64Array([1n, 10n, 2n, 3n, 4n, 5n, 6n]),
  new BigUint64Array([3n, 1n, 2n, 3n, 33n, 5n, 6n])
];

var index = normal_typedarrays[0].at(0);
assert(index === 0);
assert(normal_typedarrays[index].at(0) === 0);

assert(normal_typedarrays[1].at(normal_typedarrays[1].length) === undefined);
assert(normal_typedarrays[2].at(normal_typedarrays[2].length+1) === undefined);
assert(normal_typedarrays[3].at(normal_typedarrays[3].length-1) === 6);
assert(normal_typedarrays[4].at("1") === 1);
assert(normal_typedarrays[5].at(-1) === 6);
assert(normal_typedarrays[6].at("-1") === 6);
assert(normal_typedarrays[7].at("-20") === undefined);
assert(normal_typedarrays[8].at(0) === 1.5);
assert(normal_typedarrays[9].at(-1) === 6n);
assert(normal_typedarrays[10].at() === 3n);

normal_typedarrays.forEach(function(e){
  try {
    e.prototype.at.call(undefined);
    assert(false);
  } catch(e) {
    assert(e instanceof TypeError);
  }
});


Review comment (suggestion):
This only tests each array for a specific case. All tests should be run executed for all of the typedarrays.

Code after:
  new Int8Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint8Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint8ClampedArray([0, 1, 2, 3, 0, 5, 6]),
  new Int16Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint16Array([0, 1, 2, 3, 0, 5, 6]),
  new Int32Array([0, 1, 2, 3, 0, 5, 6]),
  new Uint32Array([0, 1, 2, 3, 0, 5, 6]),
];

/* Float */
var float_typedarrays = [
  new Float32Array([1.5, 1.5, 2.5, 3.5, 0.5, 5.5, 10.5]),
  new Float64Array([1.5, 2.5, 3.5, 0.5, 5.5, 6.5, 10.5]),
];

/* BigInt */
var bigint_typedarrays = [
  new BigInt64Array([3n, 10n, 2n, 3n, 4n, 5n, 6n]),
  new BigUint64Array([3n, 1n, 2n, 3n, 33n, 5n, 6n])
];

var index = normal_typedarrays[0].at(0);
assert(index === 0);
assert(normal_typedarrays[index].at(0) === 0);

/* Integer input */
normal_typedarrays.forEach(function(e){
  assert(e.at(normal_typedarrays[1].length) === undefined);
  assert(e.at(normal_typedarrays[2].length+1) === undefined);
  assert(e.at(normal_typedarrays[3].length-1) === 6);
  assert(e.at(0) === 0);
  assert(e.at("-1") === 6);
  assert(e.at(-1) === 6);
  assert(e.at("-20") === undefined);
  assert(e.at(100) === undefined)
});

/* Float input */
float_typedarrays.forEach(function(f){
  assert(f.at(float_typedarrays[1].length) === undefined);
  assert(f.at(0) === 1.5);
  assert(f.at("-1") === 10.5);
  assert(f.at(-1) === 10.5);
  assert(f.at("-20") === undefined);
  assert(f.at(100) === undefined)
});

/* BigInt input */
bigint_typedarrays.forEach(function(b){
  assert(b.at(bigint_typedarrays[1].length) === undefined);
  assert(b.at(0) === 3n);
Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c (C)

Code before:
  }

  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 number
 *
 */
ecma_number_t
ecma_builtin_helper_check_index (ecma_value_t index, /**< index argument */
                                 ecma_number_t len) /**< 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);
  }

  /* 7. */
  if (k < 0 || k >= (len))
  {

Review comment (refactor):
this method must return with ecma_value_t since it may raises error what need to be checked at the caller site..

How about this one?
```
ecma_value_t
ecma_builtin_helper_check_index (ecma_value_t index,
                                 ecma_number_t* len)
```


Code after:
  }

  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;
  }
  else
  {
    k = ((ecma_number_t) length + relative_index);
  }