NodeList.cpp 814 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. : LegacyPlatformObject(realm)
  12. {
  13. }
  14. NodeList::~NodeList() = default;
  15. void NodeList::initialize(JS::Realm& realm)
  16. {
  17. Base::initialize(realm);
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeListPrototype>(realm, "NodeList"));
  19. }
  20. WebIDL::ExceptionOr<JS::Value> NodeList::item_value(size_t index) const
  21. {
  22. auto* node = item(index);
  23. if (!node)
  24. return JS::js_undefined();
  25. return const_cast<Node*>(node);
  26. }
  27. bool NodeList::is_supported_property_index(u32 index) const
  28. {
  29. return index < length();
  30. }
  31. }