PromiseResolvingFunction.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/StringView.h>
  8. #include <LibJS/Runtime/NativeFunction.h>
  9. namespace JS {
  10. struct AlreadyResolved final : public Cell {
  11. JS_CELL(AlreadyResolved, Cell);
  12. bool value { false };
  13. protected:
  14. // Allocated cells must be >= sizeof(FreelistEntry), which is 24 bytes -
  15. // but AlreadyResolved is only 16 bytes without this.
  16. u8 dummy[8];
  17. };
  18. class PromiseResolvingFunction final : public NativeFunction {
  19. JS_OBJECT(PromiseResolvingFunction, NativeFunction);
  20. public:
  21. using FunctionType = Function<ThrowCompletionOr<Value>(VM&, Promise&, AlreadyResolved&)>;
  22. static PromiseResolvingFunction* create(Realm&, Promise&, AlreadyResolved&, FunctionType);
  23. explicit PromiseResolvingFunction(Promise&, AlreadyResolved&, FunctionType, Object& prototype);
  24. virtual void initialize(Realm&) override;
  25. virtual ~PromiseResolvingFunction() override = default;
  26. virtual ThrowCompletionOr<Value> call() override;
  27. private:
  28. virtual void visit_edges(Visitor&) override;
  29. Promise& m_promise;
  30. AlreadyResolved& m_already_resolved;
  31. FunctionType m_native_function;
  32. };
  33. }