/* * Copyright (c) 2021, Ali Mohammad Pur * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace JS { class GeneratorObject final : public Object { JS_OBJECT(GeneratorObject, Object); public: static ThrowCompletionOr> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow); virtual ThrowCompletionOr initialize(Realm&) override; virtual ~GeneratorObject() override = default; void visit_edges(Cell::Visitor&) override; ThrowCompletionOr resume(VM&, Value value, Optional generator_brand); ThrowCompletionOr resume_abrupt(VM&, JS::Completion abrupt_completion, Optional generator_brand); private: GeneratorObject(Realm&, Object& prototype, ExecutionContext); enum class GeneratorState { SuspendedStart, SuspendedYield, Executing, Completed, }; ThrowCompletionOr validate(VM&, Optional const& generator_brand); ThrowCompletionOr execute(VM&, JS::Completion const& completion); ExecutionContext m_execution_context; ECMAScriptFunctionObject* m_generating_function { nullptr }; Value m_previous_value; Optional m_frame; GeneratorState m_generator_state { GeneratorState::SuspendedStart }; Optional m_generator_brand; }; }