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

Code before:
  JERRY_UNUSED (value);
#endif /* JERRY_BUILTIN_CONTAINER */
  return JERRY_CONTAINER_TYPE_INVALID;
} /* jerry_get_container_type */

/**
 * Return a new array containing elements from a Container or a Container Iterator.
 * Sets the boolean input value to `true` if the container object is a
 * key-value structure and `false` if not.
 *
 * Note:
 *     the returned value must be freed with a jerry_release_value call
 *
 * @return an array of items for maps/sets or their iterators, error otherwise
 */
jerry_value_t
jerry_get_array_from_container (jerry_value_t value, /**< the container or iterator object */
                                bool *is_key_value_p) /**< [out] is key-value structure */
{
  jerry_assert_api_available ();

#if JERRY_BUILTIN_CONTAINER

  if (!ecma_is_value_object (value))
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Value is not a Container or Iterator")));
  }

  ecma_object_t *obj_p = ecma_get_object_from_value (value);

  if (ecma_get_object_type (obj_p) != ECMA_OBJECT_TYPE_CLASS)
  {
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Value is not a Container or Iterator")));
  }

  ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;

  ecma_collection_t *collection_buffer = ecma_new_collection ();
  ecma_collection_t *container_p;
  uint32_t entry_count;
  uint8_t entry_size;

  uint32_t index = 0;
  uint8_t iterator_kind = ECMA_ITERATOR__COUNT;
  ecma_value_t *start_p;

  bool is_key_value_pair = false;

  if (ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
      || ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
  {

Review comment (suggestion):
You could put this error message to a local value and use it here and below:
`const char *container_needed = ECMA_ERR_MSG ("Value is not a Container or Iterator"));`

Code after:
#if JERRY_BUILTIN_SET
        case LIT_MAGIC_STRING_SET_UL:
        {
          return JERRY_CONTAINER_TYPE_SET;
        }
#endif /* JERRY_BUILTIN_SET */
#if JERRY_BUILTIN_WEAKMAP
        case LIT_MAGIC_STRING_WEAKMAP_UL:
        {
          return JERRY_CONTAINER_TYPE_WEAKMAP;
        }
#endif /* JERRY_BUILTIN_WEAKMAP */
#if JERRY_BUILTIN_WEAKSET
        case LIT_MAGIC_STRING_WEAKSET_UL:
        {
          return JERRY_CONTAINER_TYPE_WEAKSET;
        }
#endif /* JERRY_BUILTIN_WEAKSET */
        default:
        {
          return JERRY_CONTAINER_TYPE_INVALID;
        }
      }
    }
  }

#else /* !JERRY_BUILTIN_CONTAINER */
  JERRY_UNUSED (value);
#endif /* JERRY_BUILTIN_CONTAINER */
  return JERRY_CONTAINER_TYPE_INVALID;
} /* jerry_get_container_type */

/**
 * Return a new array containing elements from a Container or a Container Iterator.
 * Sets the boolean input value to `true` if the container object has key/value pairs.
 *
 * Note:
 *     the returned value must be freed with a jerry_release_value call
 *
 * @return an array of items for maps/sets or their iterators, error otherwise
 */
jerry_value_t
jerry_get_array_from_container (jerry_value_t value, /**< the container or iterator object */
                                bool *is_key_value_p) /**< [out] is key-value structure */
{
  jerry_assert_api_available ();

#if JERRY_BUILTIN_CONTAINER
  const char *container_needed = ECMA_ERR_MSG ("Value is not a Container or Iterator");

  if (!ecma_is_value_object (value))