AsyncFunctionDriverWrapper.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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/Bytecode/Interpreter.h>
  8. #include <LibJS/Runtime/ECMAScriptFunctionObject.h>
  9. #include <LibJS/Runtime/GeneratorObject.h>
  10. #include <LibJS/Runtime/Object.h>
  11. #include <LibJS/Runtime/Promise.h>
  12. namespace JS {
  13. class AsyncFunctionDriverWrapper final : public Promise {
  14. JS_OBJECT(AsyncFunctionDriverWrapper, Promise);
  15. public:
  16. enum class IsInitialExecution {
  17. No,
  18. Yes,
  19. };
  20. static ThrowCompletionOr<Value> create(Realm&, GeneratorObject*);
  21. virtual ~AsyncFunctionDriverWrapper() override = default;
  22. void visit_edges(Cell::Visitor&) override;
  23. void continue_async_execution(VM&, Value, bool is_successful, IsInitialExecution is_initial_execution = IsInitialExecution::No);
  24. private:
  25. AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
  26. ThrowCompletionOr<void> await(Value);
  27. NonnullGCPtr<GeneratorObject> m_generator_object;
  28. NonnullGCPtr<Promise> m_top_level_promise;
  29. GCPtr<Promise> m_current_promise { nullptr };
  30. Handle<AsyncFunctionDriverWrapper> m_self_handle;
  31. Optional<ExecutionContext> m_suspended_execution_context;
  32. };
  33. }