Repository: jerryscript-project/jerryscript
File: jerry-core/api/jerry.c (C)

Code before:
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }
      break;
    }
    case 1:
    {
      if (ecma_is_value_error_reference (arguments[0]))
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }

      if (operation == JERRY_CONTAINER_OP_SIZE || operation == JERRY_CONTAINER_OP_CLEAR)
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }

      if (operation == JERRY_CONTAINER_OP_SET)
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }
      break;
    }
    case 2:
    {
      if (ecma_is_value_error_reference (arguments[0]))
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }

      if (operation != JERRY_CONTAINER_OP_SET)
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }
      break;
    }
    default:
    {
      return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
    }
  }

  jerry_value_t result;

  switch (operation)
  {
    case JERRY_CONTAINER_OP_ADD:
    {
      result = ecma_op_container_set (container_object_p, arguments[0], arguments[0], type);
      break;
    }

Review comment (suggestion):
`ecma_is_value_error_reference (arguments[0]) || ecma_is_value_error_reference (arguments[1])`

Code after:

  jerry_value_t result;
  const char *incorrect_type_call = ECMA_ERR_MSG ("Operator called on incorrect container type");

  switch (operation)
  {
    case JERRY_CONTAINER_OP_ADD:
    {
      if (type == LIT_MAGIC_STRING_MAP_UL || type == LIT_MAGIC_STRING_WEAKMAP_UL)
      {
        return jerry_throw (ecma_raise_type_error (incorrect_type_call));
      }
      result = ecma_op_container_set (container_object_p, arguments[0], arguments[0], type);
      break;
    }
    case JERRY_CONTAINER_OP_GET:
    {
      if (type == LIT_MAGIC_STRING_SET_UL || type == LIT_MAGIC_STRING_WEAKSET_UL)
      {
        return jerry_throw (ecma_raise_type_error (incorrect_type_call));
      }
      result = ecma_op_container_get (container_object_p, arguments[0], type);
      break;
    }
    case JERRY_CONTAINER_OP_SET:
    {
      if (type == LIT_MAGIC_STRING_SET_UL || type == LIT_MAGIC_STRING_WEAKSET_UL)
      {
        return jerry_throw (ecma_raise_type_error (incorrect_type_call));
      }
      result = ecma_op_container_set (container_object_p, arguments[0], arguments[1], type);
      break;
    }
    case JERRY_CONTAINER_OP_HAS:
    {
      result = ecma_op_container_has (container_object_p, arguments[0], type);
      break;
    }
    case JERRY_CONTAINER_OP_DELETE:
    {
      if (type == LIT_MAGIC_STRING_WEAKMAP_UL || type == LIT_MAGIC_STRING_WEAKSET_UL)
      {
        result = ecma_op_container_delete_weak (container_object_p, arguments[0], type);
        break;
      }
      result = ecma_op_container_delete (container_object_p, arguments[0], type);
      break;
    }
    case JERRY_CONTAINER_OP_SIZE:
    {
      result = ecma_op_container_size (container_object_p);