GeneratorObject.h 974 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Object.h>
  8. #include <LibJS/Runtime/OrdinaryFunctionObject.h>
  9. namespace JS {
  10. class GeneratorObject final : public Object {
  11. JS_OBJECT(GeneratorObject, Object);
  12. public:
  13. static GeneratorObject* create(GlobalObject&, Value, OrdinaryFunctionObject*, Environment*, Bytecode::RegisterWindow);
  14. GeneratorObject(GlobalObject&, Object& prototype);
  15. virtual void initialize(GlobalObject&) override;
  16. virtual ~GeneratorObject() override;
  17. void visit_edges(Cell::Visitor&) override;
  18. Value next_impl(VM&, GlobalObject&, Optional<Value> value_to_throw);
  19. void set_done() { m_done = true; }
  20. private:
  21. Environment* m_environment { nullptr };
  22. OrdinaryFunctionObject* m_generating_function { nullptr };
  23. Value m_previous_value;
  24. Bytecode::RegisterWindow m_frame;
  25. bool m_done { false };
  26. };
  27. }