StaticNodeList.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/StaticNodeList.h>
  7. namespace Web::DOM {
  8. StaticNodeList::StaticNodeList(NonnullRefPtrVector<Node>&& static_nodes)
  9. : m_static_nodes(move(static_nodes))
  10. {
  11. }
  12. // https://dom.spec.whatwg.org/#dom-nodelist-length
  13. u32 StaticNodeList::length() const
  14. {
  15. return m_static_nodes.size();
  16. }
  17. // https://dom.spec.whatwg.org/#dom-nodelist-item
  18. Node const* StaticNodeList::item(u32 index) const
  19. {
  20. // The item(index) method must return the indexth node in the collection. If there is no indexth node in the collection, then the method must return null.
  21. if (index >= m_static_nodes.size())
  22. return nullptr;
  23. return &m_static_nodes[index];
  24. }
  25. // https://dom.spec.whatwg.org/#ref-for-dfn-supported-property-indices
  26. bool StaticNodeList::is_supported_property_index(u32 index) const
  27. {
  28. // The object’s supported property indices are the numbers in the range zero to one less than the number of nodes represented by the collection.
  29. // If there are no such elements, then there are no supported property indices.
  30. return index < m_static_nodes.size();
  31. }
  32. }