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

Code before:

  if (require_regexp && !ecma_object_is_regexp_object (this_arg))
  {
    return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
  }

#if ENABLED (JERRY_BUILTIN_ANNEXB)
  if (builtin_routine_id == ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE)
  {
    if (!ecma_object_is_regexp_object (this_arg)
 #if !ENABLED (JERRY_ESNEXT)
       || ecma_get_object_from_value (this_arg) == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)
 #endif /* !ENABLED (JERRY_ESNEXT) */
     )
    {
      return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
    }
    {
      ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
      ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;

      return ecma_builtin_regexp_prototype_compile (obj_p, re_obj_p, arguments_list_p[0], arguments_list_p[1]);
    }
  }
#endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */

  /* 2. */
  ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);

  switch (builtin_routine_id)
  {
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST:
    {
      return ecma_builtin_regexp_prototype_test (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC:
    {
      return ecma_builtin_regexp_prototype_exec (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING:
    {
      return ecma_builtin_regexp_prototype_to_string (obj_p);
    }
#if ENABLED (JERRY_ESNEXT)
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SEARCH:
    {
      return ecma_regexp_search_helper (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH:
    {
      return ecma_regexp_match_helper (this_arg, arguments_list_p[0]);

Review comment (suggestion):
`this_arg` is already an object (checked above) `ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL)` is enough.

Code after:
 *         Returned value must be freed with ecma_free_value.
 */
ecma_value_t
ecma_builtin_regexp_prototype_dispatch_routine (uint16_t builtin_routine_id, /**< built-in wide routine
                                                                              *   identifier */
                                                ecma_value_t this_arg, /**< 'this' argument value */
                                                const ecma_value_t arguments_list_p[], /**< list of arguments
                                                                                        *   passed to routine */
                                                uint32_t arguments_number) /**< length of arguments' list */
{
  JERRY_UNUSED (arguments_number);

#if !ENABLED (JERRY_ESNEXT)
  bool require_regexp = builtin_routine_id <= ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING;
#else /* ENABLED (JERRY_ESNEXT) */
  bool require_regexp = builtin_routine_id < ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST;
#endif /* ENABLED (JERRY_ESNEXT) */

  ecma_object_t *obj_p = NULL;

  if (ecma_is_value_object (this_arg))
  {
    /* 2. */
    obj_p = ecma_get_object_from_value (this_arg);

    if (require_regexp && !ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL))
    {
      return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
    }
  }
  /* 1. */
  else
  {
    return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not an object"));
  }

  JERRY_ASSERT (obj_p != NULL);

  switch (builtin_routine_id)
  {
#if ENABLED (JERRY_BUILTIN_ANNEXB)
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE:
    {
      return ecma_builtin_regexp_prototype_compile (this_arg, arguments_list_p[0], arguments_list_p[1]);
    }
#endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST:
    {
      return ecma_builtin_regexp_prototype_test (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC: