HTMLCollectionWrapperCustom.cpp 934 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLCollectionWrapper.h>
  7. #include <LibWeb/Bindings/NodeWrapper.h>
  8. #include <LibWeb/Bindings/NodeWrapperFactory.h>
  9. #include <LibWeb/DOM/Element.h>
  10. namespace Web::Bindings {
  11. JS::Value HTMLCollectionWrapper::internal_get(JS::PropertyName const& property_name, JS::Value receiver) const
  12. {
  13. if (property_name.is_symbol())
  14. return Base::internal_get(property_name, receiver);
  15. DOM::Element* item = nullptr;
  16. if (property_name.is_string())
  17. item = const_cast<DOM::HTMLCollection&>(impl()).named_item(property_name.to_string());
  18. else if (property_name.is_number())
  19. item = const_cast<DOM::HTMLCollection&>(impl()).item(property_name.as_number());
  20. if (!item)
  21. return Base::internal_get(property_name, receiver);
  22. return wrap(global_object(), *item);
  23. }
  24. }