/* * Copyright (c) 2023, 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); JS_DECLARE_ALLOCATOR(IteratorHelper); public: using Closure = JS::HeapFunction(VM&, IteratorHelper&)>; using AbruptClosure = JS::HeapFunction(VM&, IteratorHelper&, Completion const&)>; static ThrowCompletionOr> create(Realm&, NonnullGCPtr, NonnullGCPtr, GCPtr = {}); IteratorRecord& underlying_iterator() { return m_underlying_iterator; } IteratorRecord const& underlying_iterator() const { return m_underlying_iterator; } size_t counter() const { return m_counter; } void increment_counter() { ++m_counter; } Value result(Value); ThrowCompletionOr close_result(VM&, Completion); private: IteratorHelper(Realm&, Object& prototype, NonnullGCPtr, NonnullGCPtr, GCPtr); virtual void visit_edges(Visitor&) override; virtual ThrowCompletionOr execute(VM&, JS::Completion const& completion) override; NonnullGCPtr m_underlying_iterator; // [[UnderlyingIterator]] NonnullGCPtr m_closure; GCPtr m_abrupt_closure; size_t m_counter { 0 }; bool m_done { false }; }; }