AsyncGenerator.h 1.4 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/AsyncGeneratorRequest.h>
  9. #include <LibJS/Runtime/ExecutionContext.h>
  10. #include <LibJS/Runtime/Object.h>
  11. namespace JS {
  12. // 27.6.2 Properties of AsyncGenerator Instances, https://tc39.es/ecma262/#sec-properties-of-asyncgenerator-intances
  13. class AsyncGenerator final : public Object {
  14. JS_OBJECT(AsyncGenerator, Object);
  15. public:
  16. enum class State {
  17. SuspendedStart,
  18. SuspendedYield,
  19. Executing,
  20. AwaitingReturn,
  21. Completed,
  22. };
  23. explicit AsyncGenerator(Object& prototype);
  24. virtual ~AsyncGenerator() override = default;
  25. private:
  26. virtual void visit_edges(Cell::Visitor&) override;
  27. // At the time of constructing an AsyncGenerator, we still need to point to an
  28. // execution context on the stack, but later need to 'adopt' it.
  29. using ExecutionContextVariant = Variant<ExecutionContext, ExecutionContext*, Empty>;
  30. Optional<State> m_async_generator_state; // [[AsyncGeneratorState]]
  31. ExecutionContextVariant m_async_generator_context; // [[AsyncGeneratorContext]]
  32. Vector<AsyncGeneratorRequest> m_async_generator_queue; // [[AsyncGeneratorQueue]]
  33. Optional<String> m_generator_brand; // [[GeneratorBrand]]
  34. };
  35. }