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

Code before:
        || ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL)
    {
      is_key_value_pair = true;
    }
  }
  else
  {
    ecma_collection_free (collection_buffer);
    return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Value is not a Container or Iterator")));
  }

  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 (iterator_kind != ECMA_ITERATOR_VALUES)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[0])); //
    }

    if (is_key_value_pair || iterator_kind == ECMA_ITERATOR_VALUES)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[1]));
    }
  }
  *is_key_value_p = is_key_value_pair;
  return ecma_op_new_array_object_from_collection (collection_buffer, false);
#else /* JERRY_BUILTIN_CONTAINER */
  JERRY_UNUSED (value);
  JERRY_UNUSED (is_key_value_p);
  return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_container_not_supported_p)));
#endif
} /* jerry_get_array_from_container */

/**
 * @}
 */


Review comment (suggestion):
iterator_kind != ECMA_ITERATOR_KEYS or something?
This enum should have 3 values: keys, values, entries. The latter two only valid for maps, sets only have "keys". 
The first `if` is correct, the second should be simplified.

Code after:
    index = ext_obj_p->u.cls.u2.iterator_index;

    entry_size = ecma_op_container_entry_size (map_object_p->u.cls.u2.container_id);
    start_p = ECMA_CONTAINER_START (container_p);

    iterator_kind = ext_obj_p->u.cls.u1.iterator_kind;
  }
  else if (jerry_get_container_type (value) != JERRY_CONTAINER_TYPE_INVALID)
  {
    ecma_collection_t *container_p = ECMA_GET_INTERNAL_VALUE_POINTER (ecma_collection_t, ext_obj_p->u.cls.u3.value);
    entry_count = ECMA_CONTAINER_ENTRY_COUNT (container_p);
    entry_size = ecma_op_container_entry_size (ext_obj_p->u.cls.u2.container_id);

    index = 0;
    iterator_kind = ECMA_ITERATOR_KEYS;
    start_p = ECMA_CONTAINER_START (container_p);

    if (ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_MAP_UL
        || ext_obj_p->u.cls.u2.container_id == LIT_MAGIC_STRING_WEAKMAP_UL)
    {
      iterator_kind = ECMA_ITERATOR_ENTRIES;
    }
  }
  else
  {
    return jerry_throw (ecma_raise_type_error (container_needed));
  }

  *is_key_value_p = (iterator_kind == ECMA_ITERATOR_ENTRIES);
  ecma_collection_t *collection_buffer = ecma_new_collection ();

  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 (iterator_kind != ECMA_ITERATOR_VALUES)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[0]));
    }

    if (iterator_kind != ECMA_ITERATOR_KEYS)
    {
      ecma_collection_push_back (collection_buffer, ecma_copy_value_if_not_object (entry_p[1]));
    }
  }
  return ecma_op_new_array_object_from_collection (collection_buffer, false);