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

Code before:

    iterator_kind = ext_obj_p->u.cls.u1.iterator_kind;

    if (iterator_kind == ECMA_ITERATOR_ENTRIES)
    {
      *is_key_value_p = true;
    }
  }
  else if (lit_id == LIT_MAGIC_STRING_MAP_UL || lit_id == LIT_MAGIC_STRING_WEAKMAP_UL)
  {
    *is_key_value_p = true;
  }

  bool is_key_value_container = *is_key_value_p;

  for (uint32_t i = index; i < entry_count; i+= entry_size)
  {
    ecma_value_t *entry_p = start_p + i;

    if (ecma_is_value_empty (*entry_p))
    {
      continue;
    }

    if (is_value_iterator)
    {
      ext_obj_p->u.cls.u2.iterator_index = (uint16_t) (i + entry_size);

      if (iterator_kind != ECMA_ITERATOR_ENTRIES)
      {
        ext_obj_p->u.cls.u2.iterator_index = (uint16_t) (i + entry_size);
      }
    }

    if (is_key_value_container)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (*entry_p));
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[1]));
    }
    else if (iterator_kind == ECMA_ITERATOR_VALUES)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[1]));
    }
    else
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (*entry_p));
    }

  }

  return ecma_op_new_array_object_from_collection (collection_buffer, false);

Review comment (suggestion):
At this point the `collection_buffer` is empty? If so do we need to create the `collection_buffer` that early? This seems to be a simple empty array return.

Code after:
} /* 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))
  {
    return jerry_throw (ecma_raise_type_error (container_needed));
  }

  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 (container_needed));
  }

  ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_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;

  *is_key_value_p = false;

  if (ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_MAP_ITERATOR
      || ext_obj_p->u.cls.type == ECMA_OBJECT_CLASS_SET_ITERATOR)
  {
    ecma_value_t iterated_value = ext_obj_p->u.cls.u3.iterated_value;

    if (ecma_is_value_empty (iterated_value))
    {
      return ecma_op_new_array_object_from_collection (ecma_new_collection (), false);