AsyncFunctionDriverWrapper.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. static ThrowCompletionOr<Value> create(Realm&, GeneratorObject*);
  17. virtual ~AsyncFunctionDriverWrapper() override = default;
  18. void visit_edges(Cell::Visitor&) override;
  19. void continue_async_execution(VM&, Value, bool is_successful);
  20. private:
  21. AsyncFunctionDriverWrapper(Realm&, NonnullGCPtr<GeneratorObject>, NonnullGCPtr<Promise> top_level_promise);
  22. bool m_expect_promise { false };
  23. NonnullGCPtr<GeneratorObject> m_generator_object;
  24. NonnullGCPtr<NativeFunction> m_on_fulfillment;
  25. NonnullGCPtr<NativeFunction> m_on_rejection;
  26. NonnullGCPtr<Promise> m_top_level_promise;
  27. GCPtr<Promise> m_current_promise { nullptr };
  28. Handle<AsyncFunctionDriverWrapper> m_self_handle;
  29. };
  30. }