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

Code before:
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE:
    {
      ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;

      return ecma_builtin_regexp_prototype_get_source (re_obj_p);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE:
    {
      if (!ecma_object_is_regexp_object (this_arg))
      {
        return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object"));
      }

      uint16_t flags = RE_FLAG_EMPTY;
      ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;

      ecma_value_t ret_value = ecma_builtin_regexp_prototype_flags_helper (re_obj_p, &flags);
      if (ECMA_IS_VALUE_ERROR (ret_value))
      {
        return ret_value;
      }

      static const uint16_t re_flags[] =
      {
        RE_FLAG_GLOBAL, RE_FLAG_IGNORE_CASE,
        RE_FLAG_MULTILINE, RE_FLAG_STICKY, RE_FLAG_UNICODE
      };
      uint16_t padded_index = (uint16_t) (builtin_routine_id - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL);
      return ecma_make_boolean_value (flags & re_flags[padded_index]);
    }
#endif /* ENABLED (JERRY_ESNEXT) */
    default:
    {
      JERRY_UNREACHABLE ();
    }
  }
} /* ecma_builtin_regexp_prototype_dispatch_routine */
/**
 * @}
 * @}
 * @}
 */

#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */


Review comment (suggestion):
If you would place these routine indices before `ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING` the  `ecma_object_is_regexp_object` check would be performed for these flag getters as well.

Code after:
    {
      return ecma_regexp_match_helper (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_REPLACE:
    {
      return ecma_regexp_replace_helper (this_arg, arguments_list_p[0], arguments_list_p[1]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SPLIT:
    {
      return ecma_regexp_split_helper (this_arg, arguments_list_p[0], arguments_list_p[1]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_FLAGS:
    {
      return ecma_builtin_regexp_prototype_get_flags (obj_p);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE:
    {
      ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;

      return ecma_builtin_regexp_prototype_get_source (re_obj_p);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE:
    {
      ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p;

      return ecma_builtin_regexp_prototype_flags_helper (re_obj_p, builtin_routine_id);
    }
#endif /* ENABLED (JERRY_ESNEXT) */
    default:
    {
      JERRY_UNREACHABLE ();
    }
  }
} /* ecma_builtin_regexp_prototype_dispatch_routine */
/**
 * @}
 * @}
 * @}
 */

#endif /* ENABLED (JERRY_BUILTIN_REGEXP) */