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

Code before:
ecma_typedarray_create (ecma_object_t *constructor_p, /**< constructor function */
                                     ecma_value_t *arguments_list_p, /**< argument list */
                                     uint32_t arguments_list_len) /**< length of argument list */
{
  ecma_value_t ret_val = ecma_op_function_construct (constructor_p,
                                                     constructor_p,
                                                     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]);
    if (ECMA_IS_VALUE_ERROR (num))
    {
      ecma_free_value (ret_val);
      return ECMA_VALUE_ERROR;
    }
    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 */

Review comment (suggestion):
`if (ECMA_IS_VALUE_ERROR (num))` this if in unnecessary.

Code after:
ecma_typedarray_create (ecma_object_t *constructor_p, /**< constructor function */
                        ecma_value_t *arguments_list_p, /**< argument list */
                        uint32_t arguments_list_len) /**< length of argument list */
{
  ecma_value_t ret_val = ecma_op_function_construct (constructor_p,
                                                     constructor_p,
                                                     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));