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

Code before:
        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 is a
 * key-value structure and `false` if not.
 *
 * Note:
 *     the returned value must be freed with a jerry_release_value call
 *
 * @return jerry_value_t representing an array containing the elemets of the map.
 *         jerry_value_t representing an empty array, if the Iterator is finished/empty.
 *         Error if the value is not a Container or Container Iterator.
 *         `undefined` if the `value` is undefined or null.
 */
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_value_is_undefined (value) || jerry_value_is_null (value))
  {
    return jerry_create_undefined ();
  }

#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_collection_t *collection_buffer = ecma_new_collection ();

  ecma_object_t *obj_p = ecma_get_object_from_value (value);
  ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p;
  ecma_object_type_t type = ecma_get_object_type (obj_p);

  ecma_collection_t *container_p;

Review comment (suggestion):
I would siplify this:
`@ return an array of items for maps/sets or their iterators, error otherwise`
Passing an undefined as value is an error.

Code after:
    }
#endif /* JERRY_BUILTIN_WEAKMAP */
#if JERRY_BUILTIN_WEAKSET
    case JERRY_CONTAINER_TYPE_WEAKSET:
    {
      lit_id = LIT_MAGIC_STRING_WEAKSET_UL;
      proto_id = ECMA_BUILTIN_ID_WEAKSET_PROTOTYPE;
      ctor_id = ECMA_BUILTIN_ID_WEAKSET;
      break;
    }
#endif /* JERRY_BUILTIN_WEAKSET */
    default:
    {
      return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG ("Invalid container type")));
    }
  }
  ecma_object_t * old_new_target_p = JERRY_CONTEXT (current_new_target_p);

  if (old_new_target_p == NULL)
  {
    JERRY_CONTEXT (current_new_target_p) = ecma_builtin_get (ctor_id);
  }

  ecma_value_t container_value = ecma_op_container_create (arguments_list_p,
                                                           arguments_list_len,
                                                           lit_id,
                                                           proto_id);

  JERRY_CONTEXT (current_new_target_p) = old_new_target_p;
  return container_value;
#else /* !JERRY_BUILTIN_CONTAINER */
  JERRY_UNUSED (arguments_list_p);
  JERRY_UNUSED (arguments_list_len);
  JERRY_UNUSED (container_type);
  return jerry_throw (ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_container_not_supported_p)));
#endif /* JERRY_BUILTIN_CONTAINER */
} /* jerry_create_container */

/**
 * Get the type of the given container object.
 *
 * @return Corresponding type to the given container object.
 */
jerry_container_type_t
jerry_get_container_type (const jerry_value_t value) /**< the container object */
{
  jerry_assert_api_available ();

#if JERRY_BUILTIN_CONTAINER
  if (ecma_is_value_object (value))
  {