HTMLCollectionWrapperCustom.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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::get(JS::PropertyName const& name, JS::Value receiver, bool without_side_effects) const
  13. {
  14. if (!name.is_string())
  15. return Base::get(name, receiver, without_side_effects);
  16. auto* item = const_cast<DOM::HTMLCollection&>(impl()).named_item(name.to_string());
  17. if (!item)
  18. return Base::get(name, receiver, without_side_effects);
  19. return JS::Value { wrap(global_object(), *item) };
  20. }
  21. JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index, bool without_side_effects) const
  22. {
  23. auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index);
  24. if (!item)
  25. return Base::get_by_index(property_index, without_side_effects);
  26. return wrap(global_object(), *item);
  27. }
  28. }