NodeList.cpp 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/Bindings/NodeListPrototype.h>
  8. #include <LibWeb/DOM/Node.h>
  9. #include <LibWeb/DOM/NodeList.h>
  10. namespace Web::DOM {
  11. NodeList::NodeList(JS::Realm& realm)
  12. : PlatformObject(realm)
  13. {
  14. m_legacy_platform_object_flags = LegacyPlatformObjectFlags { .supports_indexed_properties = true };
  15. }
  16. NodeList::~NodeList() = default;
  17. void NodeList::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(NodeList);
  21. }
  22. WebIDL::ExceptionOr<JS::Value> NodeList::item_value(size_t index) const
  23. {
  24. auto* node = item(index);
  25. if (!node)
  26. return JS::js_undefined();
  27. return const_cast<Node*>(node);
  28. }
  29. bool NodeList::is_supported_property_index(u32 index) const
  30. {
  31. return index < length();
  32. }
  33. }