Iterator.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Runtime/Completion.h>
  9. #include <LibJS/Runtime/Object.h>
  10. #include <LibJS/Runtime/Value.h>
  11. namespace JS {
  12. // 7.4.1 Iterator Records, https://tc39.es/ecma262/#sec-iterator-records
  13. struct IteratorRecord {
  14. GCPtr<Object> iterator; // [[Iterator]]
  15. Value next_method; // [[NextMethod]]
  16. bool done { false }; // [[Done]]
  17. };
  18. class Iterator : public Object {
  19. JS_OBJECT(Iterator, Object);
  20. public:
  21. static ThrowCompletionOr<NonnullGCPtr<Iterator>> create(Realm&, Object& prototype, IteratorRecord iterated);
  22. IteratorRecord const& iterated() const { return m_iterated; }
  23. private:
  24. Iterator(Object& prototype, IteratorRecord iterated);
  25. explicit Iterator(Object& prototype);
  26. IteratorRecord m_iterated; // [[Iterated]]
  27. };
  28. ThrowCompletionOr<IteratorRecord> get_iterator_direct(VM&, Object&);
  29. ThrowCompletionOr<IteratorRecord> get_iterator_flattenable(VM&, Value);
  30. }