Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/operations/ecma-typedarray-object.c (C)

Code before:
    ret_value = ecma_make_object_value (new_typedarray_p);

    /* 6.e */
    for (uint32_t index = 0; index < values_p->item_count; index++)
    {
      ecma_value_t set_value = ecma_op_typedarray_from_helper (this_arg,
                                                               values_p->buffer_p[index],
                                                               index,
                                                               func_object_p,
                                                               &info,
                                                               setter_cb);

      if (ECMA_IS_VALUE_ERROR (set_value))
      {
        for (uint32_t j = index + 1; j < values_p->item_count; j++)
        {
          ecma_free_value (values_p->buffer_p[j]);
        }

        ret_value = set_value;
        break;
      }
    }

    ecma_collection_destroy (values_p);

    if (ECMA_IS_VALUE_ERROR (ret_value))
    {
      ecma_deref_object (new_typedarray_p);
    }

    return ret_value;
  }

  /* 8 */
  ecma_value_t arraylike_object_val = ecma_op_to_object (source_val);

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

  ecma_object_t *arraylike_object_p = ecma_get_object_from_value (arraylike_object_val);

  /* 9 */
  ecma_length_t length_index;
  ecma_value_t len_value = ecma_op_object_get_length (arraylike_object_p, &length_index);

  if (ECMA_IS_VALUE_ERROR (len_value))
  {
    ecma_deref_object (arraylike_object_p);

Review comment (refactor):
According to this, `ecma_op_typedarray_from_helper ` takes the reference from the passed values collection element. This neither should be documented or (what I'd personally prefer) change the reference management of the function to copy the incoming argument instead of taking it's reference.

Code after:

    ret_value = ecma_make_object_value (new_typedarray_p);

    /* 6.e */
    for (uint32_t index = 0; index < values_p->item_count; index++)
    {
      ecma_value_t set_value = ecma_op_typedarray_from_helper (this_arg,
                                                               values_p->buffer_p[index],
                                                               index,
                                                               func_object_p,
                                                               &info,
                                                               setter_cb);

      if (ECMA_IS_VALUE_ERROR (set_value))
      {
        for (uint32_t j = index + 1; j < values_p->item_count; j++)
        {
          ecma_free_value (values_p->buffer_p[j]);
        }

        ret_value = set_value;
        break;
      }
    }

    ecma_collection_destroy (values_p);

    if (ECMA_IS_VALUE_ERROR (ret_value))
    {
      ecma_deref_object (new_typedarray_p);
    }

    return ret_value;
  }

  /* 8 */
  ecma_value_t arraylike_object_val = ecma_op_to_object (source_val);

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

  ecma_object_t *arraylike_object_p = ecma_get_object_from_value (arraylike_object_val);

  /* 9 */
  ecma_length_t length_index;
  ecma_value_t len_value = ecma_op_object_get_length (arraylike_object_p, &length_index);

  if (ECMA_IS_VALUE_ERROR (len_value))
  {