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

Code before:

  // 2. Let defaultConstructor be the intrinsic object listed in column one of Table 62 for exemplar.[[TypedArrayName]].
  ecma_builtin_id_t defaultConstructor = ecma_typedarray_helper_get_constructor_id (info.id);

  // 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
  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. Let result be ? TypedArrayCreate(constructor, argumentList).
  ecma_value_t result = ecma_typedarray_create (constructor_proto_p, arguments_list_p, 1);
  if (ECMA_IS_VALUE_ERROR (result))
  {
    ecma_deref_object (constructor_proto_p);
    return result;
  }
  // 6. Assert: result has [[TypedArrayName]] and [[ContentType]] internal slots.
#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_TYPEDARRAY_IS_BIGINT_TYPE (info.id) && ECMA_TYPEDARRAY_IS_BIGINT_TYPE (result_info.id)))
  {
    ecma_deref_object (constructor_proto_p);
    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) */
  ecma_deref_object (constructor_proto_p);
  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);

Review comment (suggestion):
```c
if (ECMA_TYPEDARRAY_IS_BIGINT_TYPE (info.id) ^ ECMA_TYPEDARRAY_IS_BIGINT_TYPE (result_info.id))
{
 // throw Error
}
```

Code after:

  ecma_value_t constructor = ecma_op_species_constructor (typedarray_p, default_constructor);

  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,