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

Code before:
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Container is not an object.")));
  }

  ecma_object_t *obj_p = ecma_get_object_from_value (container);

  if (ecma_get_object_type (obj_p) != ECMA_OBJECT_TYPE_CLASS)
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Container is not an object.")));
  }
  uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id;
  ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type);

  if (container_object_p == NULL)
  {
    return ecma_create_error_reference_from_context ();
  }

  const char *incorrect_type_call = ECMA_ERR_MSG ("Operator called on incorrect container type");
  if (type == LIT_MAGIC_STRING_SET_UL || (type == LIT_MAGIC_STRING_WEAKSET_UL))
  {
    if (operation == JERRY_CONTAINER_OP_GET || operation == JERRY_CONTAINER_OP_SET)
    {
      return jerry_throw (ecma_raise_type_error (incorrect_type_call));
    }
    if (type == LIT_MAGIC_STRING_WEAKSET_UL && operation == JERRY_CONTAINER_OP_CLEAR)
    {
      return jerry_throw (ecma_raise_type_error (incorrect_type_call));
    }
  }

  if (type == LIT_MAGIC_STRING_MAP_UL || (type == LIT_MAGIC_STRING_WEAKMAP_UL))
  {
    if (operation == JERRY_CONTAINER_OP_ADD)
    {
      return jerry_throw (ecma_raise_type_error (incorrect_type_call));
    }
    if (type == LIT_MAGIC_STRING_WEAKMAP_UL && operation == JERRY_CONTAINER_OP_CLEAR)
    {
      return jerry_throw (ecma_raise_type_error (incorrect_type_call));
    }
  }

  switch (arguments_number)
  {
    case 0:
    {
      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)));
      }

Review comment (suggestion):
Why these are not combined with one check:
```
if ((type == LIT_MAGIC_STRING_SET_UL || type == LIT_MAGIC_STRING_WEAKSET_UL)
    && (operation == JERRY_CONTAINER_OP_GET
        || operation == JERRY_CONTAINER_OP_SET
        || (type == LIT_MAGIC_STRING_WEAKSET_UL && operation == JERRY_CONTAINER_OP_CLEAR))
{
...
}
```
Similar case below.

Code after:
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Container is not a container object.")));
  }
  uint16_t type = ((ecma_extended_object_t *) obj_p)->u.cls.u2.container_id;
  ecma_extended_object_t *container_object_p = ecma_op_container_get_object (container, type);

  if (container_object_p == NULL)
  {
    return ecma_create_error_reference_from_context ();
  }

  switch (operation)
  {
    case JERRY_CONTAINER_OP_ADD:
    case JERRY_CONTAINER_OP_DELETE:
    case JERRY_CONTAINER_OP_GET:
    case JERRY_CONTAINER_OP_HAS:
    {
      if (arguments_number != 1 || ecma_is_value_error_reference (arguments[0]))
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }
      break;
    }
    case JERRY_CONTAINER_OP_SET:
    {
      if (arguments_number != 2
          || ecma_is_value_error_reference (arguments[0])
          || ecma_is_value_error_reference (arguments[1]))
      {
        return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_wrong_args_msg_p)));
      }
      break;
    }
    case JERRY_CONTAINER_OP_CLEAR:
    case JERRY_CONTAINER_OP_SIZE:
    {
      if (arguments_number != 0)
      {
        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;
  const char *incorrect_type_call = ECMA_ERR_MSG ("Operator called on incorrect container type");