Promise.h 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2023, networkException <networkexception@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibJS/Forward.h>
  9. #include <LibJS/Runtime/PromiseCapability.h>
  10. #include <LibJS/Runtime/Value.h>
  11. #include <LibJS/SafeFunction.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::WebIDL {
  14. using ReactionSteps = JS::SafeFunction<WebIDL::ExceptionOr<JS::Value>(JS::Value)>;
  15. // https://webidl.spec.whatwg.org/#es-promise
  16. using Promise = JS::PromiseCapability;
  17. JS::NonnullGCPtr<Promise> create_promise(JS::Realm&);
  18. JS::NonnullGCPtr<Promise> create_resolved_promise(JS::Realm&, JS::Value);
  19. JS::NonnullGCPtr<Promise> create_rejected_promise(JS::Realm&, JS::Value);
  20. void resolve_promise(JS::Realm&, Promise const&, JS::Value = JS::js_undefined());
  21. void reject_promise(JS::Realm&, Promise const&, JS::Value);
  22. JS::NonnullGCPtr<JS::Promise> react_to_promise(Promise const&, Optional<ReactionSteps> on_fulfilled_callback, Optional<ReactionSteps> on_rejected_callback);
  23. JS::NonnullGCPtr<JS::Promise> upon_fulfillment(Promise const&, ReactionSteps);
  24. JS::NonnullGCPtr<JS::Promise> upon_rejection(Promise const&, ReactionSteps);
  25. void mark_promise_as_handled(Promise const&);
  26. }