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

Code before:

  // 1. Let newTypedArray be ? Construct(constructor, argumentList).
  ecma_value_t ret_val = ecma_op_function_construct (constructor_p,
                                                     constructor_p,
                                                     arguments_list_p,
                                                     length);
  if (ECMA_IS_VALUE_ERROR (ret_val))
  {
    return ret_val;
  }

  // 2. Perform ? ValidateTypedArray(newTypedArray).
  if (!ecma_is_typedarray (ret_val))
  {
    ecma_free_value (ret_val);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Constructed object is not TypedArray."));
  }

  // 3. If argumentList is a List of a single Number, then
  ecma_object_t *typedarray_p = ecma_get_object_from_value (ret_val);
  ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);

  if ((arguments_list_len == 1) && (info.length < num))
  {
    ecma_free_value (ret_val);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Constructed typedarray is smaller than filter call result"));
  }
  return ret_val;
} /* ecma_typedarray_create */

/* Specify the creation of a new TypedArray object
 * using a constructor function that is derived from this_arg.
 *
 * See also: ES11 22.2.4.7
 *
 * @return ecma value of the new typedarray object, constructed by default or species constructor
 */
ecma_value_t
ecma_typedarray_species_create (ecma_value_t this_arg, /**< this argument */
                                ecma_value_t *arguments_list_p) /**< the arg list passed to typedarray construct */
{
  ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
  ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);

  // 1. Assert: exemplar is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots.
  // TODO: [[ContentType]] internal slot
  JERRY_ASSERT (ecma_is_typedarray (this_arg));

  // 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);


Review comment (suggestion):
```c
if (arguments_list_len == 1 && ecma_is_value_number (arguments_list_p[0]))
{
  // get the typedarray info 

 // get number from arguments_list_p[0]

  // perform validation.
}
```

Code after:
                                                     arguments_list_p,
                                                     arguments_list_len);
  if (ECMA_IS_VALUE_ERROR (ret_val))
  {
    return ret_val;
  }

  if (!ecma_is_typedarray (ret_val))
  {
    ecma_free_value (ret_val);
    return ecma_raise_type_error (ECMA_ERR_MSG ("Constructed object is not TypedArray."));
  }

  ecma_object_t *typedarray_p = ecma_get_object_from_value (ret_val);

  if ((arguments_list_len == 1) && (ecma_is_value_number (arguments_list_p[0])))
  {
    ecma_number_t num = ecma_get_number_from_value (arguments_list_p[0]);
    ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);

    if (info.length < num)
    {
      ecma_free_value (ret_val);
      return ecma_raise_type_error (ECMA_ERR_MSG ("Constructed typedarray is smaller than filter call result"));
    }
  }
  return ret_val;
} /* ecma_typedarray_create */

/* Specify the creation of a new TypedArray object
 * using a constructor function that is derived from this_arg.
 *
 * See also: ES11 22.2.4.7
 *
 * @return ecma value of the new typedarray object, constructed by default or species constructor
 */
ecma_value_t
ecma_typedarray_species_create (ecma_value_t this_arg, /**< this argument */
                                ecma_value_t *arguments_list_p, /**< the arg list passed to typedarray construct */
                                uint32_t arguments_list_len) /**< length of the the arg list */
{
  ecma_object_t *typedarray_p = ecma_get_object_from_value (this_arg);
  ecma_typedarray_info_t info = ecma_typedarray_get_info (typedarray_p);

  JERRY_ASSERT (ecma_is_typedarray (this_arg));

  ecma_builtin_id_t default_constructor = ecma_typedarray_helper_get_constructor_id (info.id);

  ecma_value_t constructor = ecma_op_species_constructor (typedarray_p, default_constructor);

  if (ECMA_IS_VALUE_ERROR (constructor))