Repository: jerryscript-project/jerryscript
File: jerry-core/ecma/builtin-objects/ecma-builtin-intrinsic.c (C)

Code before:
    }
    case ECMA_INTRINSIC_DATE_TO_UTC_STRING:
    {
      if (!ecma_is_value_object (this_arg)
          || !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
      {
        return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a Date object"));
      }

      ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) ecma_get_object_from_value (this_arg);
      ecma_number_t *prim_value_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
                                                                     ext_object_p->u.class_prop.u.value);

      if (ecma_number_is_nan (*prim_value_p))
      {
        return ecma_make_magic_string_value (LIT_MAGIC_STRING_INVALID_DATE_UL);
      }

      return ecma_date_value_to_utc_string (*prim_value_p);
    }
    case ECMA_INTRINSIC_STRING_TRIM_START:
    case ECMA_INTRINSIC_STRING_TRIM_END:
    {
      if (!ecma_op_require_object_coercible (this_arg))
      {
        return ecma_raise_type_error (ECMA_ERR_MSG ("Argument cannot be converted to an object."));
      }

      ecma_string_t *to_str_p = ecma_op_to_string (this_arg);
      if (to_str_p == NULL)
      {
        return ECMA_VALUE_ERROR;
      }

      ECMA_STRING_TO_UTF8_STRING (to_str_p, start_p, input_start_size);

      lit_utf8_size_t size;
      const lit_utf8_byte_t *input_start_p = start_p;
      const lit_utf8_byte_t *input_str_end_p = start_p + input_start_size;

      ecma_string_t *ret_str_p;
      if (builtin_routine_id == ECMA_INTRINSIC_STRING_TRIM_START)
      {
        const lit_utf8_byte_t *new_start_p = ecma_string_trim_front (input_start_p, input_str_end_p);
        size = (lit_utf8_size_t) (input_str_end_p - new_start_p);
        ret_str_p = ecma_new_ecma_string_from_utf8 (new_start_p, size);
      }
      else
      {
        const lit_utf8_byte_t *new_end_p = ecma_string_trim_back (input_start_p, input_str_end_p);
        size = (lit_utf8_size_t) (new_end_p - input_start_p);

Review comment (suggestion):
I'd keep the error raise in `ecma_op_require_object_coercible`

Code after:
    }
    case ECMA_INTRINSIC_DATE_TO_UTC_STRING:
    {
      if (!ecma_is_value_object (this_arg)
          || !ecma_object_class_is (ecma_get_object_from_value (this_arg), LIT_MAGIC_STRING_DATE_UL))
      {
        return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a Date object"));
      }

      ecma_extended_object_t *ext_object_p = (ecma_extended_object_t *) ecma_get_object_from_value (this_arg);
      ecma_number_t *prim_value_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_number_t,
                                                                     ext_object_p->u.class_prop.u.value);

      if (ecma_number_is_nan (*prim_value_p))
      {
        return ecma_make_magic_string_value (LIT_MAGIC_STRING_INVALID_DATE_UL);
      }

      return ecma_date_value_to_utc_string (*prim_value_p);
    }
    case ECMA_INTRINSIC_STRING_TRIM_START:
    case ECMA_INTRINSIC_STRING_TRIM_END:
    {
      if (!ecma_op_require_object_coercible (this_arg))
      {
        return ECMA_VALUE_ERROR;
      }

      ecma_string_t *to_str_p = ecma_op_to_string (this_arg);
      if (to_str_p == NULL)
      {
        return ECMA_VALUE_ERROR;
      }

      ECMA_STRING_TO_UTF8_STRING (to_str_p, start_p, input_start_size);

      lit_utf8_size_t size;
      const lit_utf8_byte_t *input_start_p = start_p;
      const lit_utf8_byte_t *input_str_end_p = start_p + input_start_size;

      ecma_string_t *ret_str_p;
      if (builtin_routine_id == ECMA_INTRINSIC_STRING_TRIM_START)
      {
        const lit_utf8_byte_t *new_start_p = ecma_string_trim_front (input_start_p, input_str_end_p);
        size = (lit_utf8_size_t) (input_str_end_p - new_start_p);
        ret_str_p = ecma_new_ecma_string_from_utf8 (new_start_p, size);
      }
      else
      {
        const lit_utf8_byte_t *new_end_p = ecma_string_trim_back (input_start_p, input_str_end_p);
        size = (lit_utf8_size_t) (new_end_p - input_start_p);