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

Code before:
  ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
  ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);

  // 1.
  // TODO: [[ContentType]] internal slot
  JERRY_ASSERT (ecma_is_typedarray (this_arg));

  // 2.
  ecma_builtin_id_t defaultConstructor = ecma_typedarray_helper_get_constructor_id (info.id);

  // 3.
  ecma_value_t constructor = ecma_op_species_constructor (typedarray_p, defaultConstructor);
  if (ECMA_IS_VALUE_ERROR (constructor))
  {
    return constructor;
  }
  ecma_object_t *constructor_proto_p = ecma_get_object_from_value (constructor);

  // 4.
  ecma_value_t result = ecma_typedarray_create (constructor_proto_p, arguments_list_p, arguments_list_len);
  if (ECMA_IS_VALUE_ERROR (result))
  {
    ecma_deref_object (constructor_proto_p);
    return result;
  }
  ecma_deref_object (constructor_proto_p);
  // 6.
#if ENABLED (JERRY_BUILTIN_BIGINT)
  ecma_object_t *result_p = ecma_get_object_from_value (result);
  ecma_typedarray_info_t result_info = ecma_typedarray_get_info (result_p);
  // Check result_info.id to to be either bigint type if info.id is one
  // or be neither of them is info.id is none of them as well.
  if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info.id) ^ ECMA_TYPEDARRAY_IS_BIGINT_TYPE (result_info.id))
  {
    ecma_free_value (result);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Source and result array does not match in [[ContentType]]"));
  }
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */
  return result;

} /* ecma_typedarray_species_create */

/**
 * Create a typedarray object based on the "type" and arraylength
 * The "type" is same with arg1
 *
 * @return ecma_value_t
 */
ecma_value_t
ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id, /** TypedArray id  */
                                                uint32_t array_length) /**< length of the typedarray */

Review comment (suggestion):
This can be performed directly after `typedarray_create.`

Code after:

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

  ecma_object_t *constructor_proto_p = ecma_get_object_from_value (constructor);

  ecma_value_t result = ecma_typedarray_create (constructor_proto_p, arguments_list_p, arguments_list_len);
  ecma_deref_object (constructor_proto_p);

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

#if ENABLED (JERRY_BUILTIN_BIGINT)
  ecma_object_t *result_p = ecma_get_object_from_value (result);
  ecma_typedarray_info_t result_info = ecma_typedarray_get_info (result_p);
  /*
   * Check result_info.id to to be either bigint type if info.id is one
   * or be neither of them is info.id is none of them as well.
   */
  if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info.id) ^ ECMA_TYPEDARRAY_IS_BIGINT_TYPE (result_info.id))
  {
    ecma_free_value (result);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Source and result array does not match in [[ContentType]]"));
  }
#endif /* ENABLED (JERRY_BUILTIN_BIGINT) */

  return result;
} /* ecma_typedarray_species_create */

/**
 * Create a typedarray object based on the "type" and arraylength
 * The "type" is same with arg1
 *
 * @return ecma_value_t
 */
ecma_value_t
ecma_op_create_typedarray_with_type_and_length (ecma_typedarray_type_t typedarray_id, /** TypedArray id  */
                                                uint32_t array_length) /**< length of the typedarray */
{
  // TODO: assert validate typedarray_id
  ecma_object_t *proto_p = ecma_builtin_get (ecma_typedarray_helper_get_prototype_id (typedarray_id));
  uint8_t element_size_shift = ecma_typedarray_helper_get_shift_size (typedarray_id);

  ecma_value_t new_obj = ecma_typedarray_create_object_with_length (array_length,
                                                                    NULL,
                                                                    proto_p,
                                                                    element_size_shift,