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

Code before:
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH:
    {
      return ecma_regexp_match_helper (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH_ALL:
    {
      return ecma_builtin_regexp_prototype_match_all (obj_p, 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:
    {
      if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL))
      {
        if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
        {
          return ecma_make_magic_string_value (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
        }

        return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a RegExp object"));
      }

      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:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL:
    {
      if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL))
      {
        if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
        {
          return ECMA_VALUE_UNDEFINED;
        }
        return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a RegExp object"));
      }

Review comment (suggestion):
`ecma_builtin_is ` is a widely used function, I think we should update it to properly support built-in objects from different realms. Maybe it would fix other testcases as well.

Code after:
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH:
    {
      return ecma_regexp_match_helper (this_arg, arguments_list_p[0]);
    }
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH_ALL:
    {
      return ecma_builtin_regexp_prototype_match_all (obj_p, 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:
    {
      if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL))
      {
        if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
        {
          return ecma_make_magic_string_value (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
        }

        return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a RegExp object"));
      }

      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:
    case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL:
    {
      if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL))
      {
        if (obj_p == ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP_PROTOTYPE))
        {
          return ECMA_VALUE_UNDEFINED;
        }

        return ecma_raise_type_error (ECMA_ERR_MSG ("Argument 'this' is not a RegExp object"));