NodeList.cpp 859 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/DOM/Node.h>
  8. #include <LibWeb/DOM/NodeList.h>
  9. namespace Web::DOM {
  10. NodeList::NodeList(JS::Realm& realm)
  11. : PlatformObject(realm)
  12. {
  13. m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
  14. }
  15. NodeList::~NodeList() = default;
  16. void NodeList::initialize(JS::Realm& realm)
  17. {
  18. Base::initialize(realm);
  19. WEB_SET_PROTOTYPE_FOR_INTERFACE(NodeList);
  20. }
  21. WebIDL::ExceptionOr<JS::Value> NodeList::item_value(size_t index) const
  22. {
  23. auto* node = item(index);
  24. if (!node)
  25. return JS::js_undefined();
  26. return const_cast<Node*>(node);
  27. }
  28. bool NodeList::is_supported_property_index(u32 index) const
  29. {
  30. return index < length();
  31. }
  32. }