AsyncGenerator.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Variant.h>
  8. #include <LibJS/Runtime/ExecutionContext.h>
  9. #include <LibJS/Runtime/Object.h>
  10. namespace JS {
  11. // 27.6.2 Properties of AsyncGenerator Instances, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-intances
  12. class AsyncGenerator final : public Object {
  13. JS_OBJECT(AsyncGenerator, Object);
  14. public:
  15. enum class State {
  16. SuspendedStart,
  17. SuspendedYield,
  18. Executing,
  19. AwaitingReturn,
  20. Completed,
  21. };
  22. virtual ~AsyncGenerator() override = default;
  23. private:
  24. explicit AsyncGenerator(Object& prototype);
  25. virtual void visit_edges(Cell::Visitor&) override;
  26. // At the time of constructing an AsyncGenerator, we still need to point to an
  27. // execution context on the stack, but later need to 'adopt' it.
  28. using ExecutionContextVariant = Variant<ExecutionContext, ExecutionContext*, Empty>;
  29. Optional<State> m_async_generator_state; // [[AsyncGeneratorState]]
  30. ExecutionContextVariant m_async_generator_context; // [[AsyncGeneratorContext]]
  31. Vector<AsyncGeneratorRequest> m_async_generator_queue; // [[AsyncGeneratorQueue]]
  32. Optional<String> m_generator_brand; // [[GeneratorBrand]]
  33. };
  34. }