PromiseResolvingFunction.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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<Value(VM&, Promise&, AlreadyResolved&)>;
  22. static NonnullGCPtr<PromiseResolvingFunction> create(Realm&, Promise&, AlreadyResolved&, FunctionType);
  23. virtual void initialize(Realm&) override;
  24. virtual ~PromiseResolvingFunction() override = default;
  25. virtual ThrowCompletionOr<Value> call() override;
  26. private:
  27. explicit PromiseResolvingFunction(Promise&, AlreadyResolved&, FunctionType, Object& prototype);
  28. virtual void visit_edges(Visitor&) override;
  29. NonnullGCPtr<Promise> m_promise;
  30. NonnullGCPtr<AlreadyResolved> m_already_resolved;
  31. FunctionType m_native_function;
  32. };
  33. }