NodeList.cpp 872 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/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. JS::ThrowCompletionOr<void> NodeList::initialize(JS::Realm& realm)
  16. {
  17. MUST_OR_THROW_OOM(Base::initialize(realm));
  18. set_prototype(&Bindings::ensure_web_prototype<Bindings::NodeListPrototype>(realm, "NodeList"));
  19. return {};
  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. }