HTMLCollectionWrapperCustom.cpp 961 B

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