ArrayIterator.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Object.h>
  8. namespace JS {
  9. class ArrayIterator final : public Object {
  10. JS_OBJECT(ArrayIterator, Object);
  11. GC_DECLARE_ALLOCATOR(ArrayIterator);
  12. public:
  13. static GC::Ref<ArrayIterator> create(Realm&, Value array, Object::PropertyKind iteration_kind);
  14. virtual ~ArrayIterator() override = default;
  15. Value array() const { return m_array; }
  16. Object::PropertyKind iteration_kind() const { return m_iteration_kind; }
  17. size_t index() const { return m_index; }
  18. private:
  19. friend class ArrayIteratorPrototype;
  20. ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype);
  21. virtual bool is_array_iterator() const override { return true; }
  22. virtual void visit_edges(Cell::Visitor&) override;
  23. Value m_array;
  24. Object::PropertyKind m_iteration_kind;
  25. size_t m_index { 0 };
  26. };
  27. template<>
  28. inline bool Object::fast_is<ArrayIterator>() const { return is_array_iterator(); }
  29. }