/* * Copyright (c) 2023-2025, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS { class IteratorHelper final : public GeneratorObject { JS_OBJECT(IteratorHelper, GeneratorObject); GC_DECLARE_ALLOCATOR(IteratorHelper); public: using Closure = GC::Function(VM&, IteratorHelper&)>; using AbruptClosure = GC::Function(VM&, Completion const&)>; static GC::Ref create(Realm&, ReadonlySpan>, GC::Ref, GC::Ptr = {}); ReadonlySpan> underlying_iterators() const { return m_underlying_iterators; } size_t counter() const { return m_counter; } void increment_counter() { ++m_counter; } private: IteratorHelper(Realm&, Object& prototype, ReadonlySpan>, GC::Ref, GC::Ptr); virtual void visit_edges(Visitor&) override; virtual ThrowCompletionOr execute(VM&, JS::Completion const& completion) override; Vector> m_underlying_iterators; // [[UnderlyingIterators]] GC::Ref m_closure; GC::Ptr m_abrupt_closure; size_t m_counter { 0 }; bool m_done { false }; }; }