2022-09-22 23:36:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
2023-02-13 11:58:39 +01:00
|
|
|
* Copyright (c) 2023, networkException <networkexception@serenityos.org>
|
2022-09-22 23:36:09 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibJS/Forward.h>
|
2023-04-07 13:47:41 -04:00
|
|
|
#include <LibJS/Runtime/PromiseCapability.h>
|
2023-02-25 10:42:45 -07:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2022-09-22 23:36:09 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
2024-03-08 15:37:28 +00:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2022-09-22 23:36:09 +01:00
|
|
|
|
|
|
|
namespace Web::WebIDL {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
using ReactionSteps = GC::Function<WebIDL::ExceptionOr<JS::Value>(JS::Value)>;
|
2022-09-22 23:36:09 +01:00
|
|
|
|
2023-02-13 11:58:39 +01:00
|
|
|
// https://webidl.spec.whatwg.org/#es-promise
|
|
|
|
using Promise = JS::PromiseCapability;
|
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
WEB_API GC::Ref<Promise> create_promise(JS::Realm&);
|
|
|
|
WEB_API GC::Ref<Promise> create_resolved_promise(JS::Realm&, JS::Value);
|
|
|
|
WEB_API GC::Ref<Promise> create_rejected_promise(JS::Realm&, JS::Value);
|
|
|
|
WEB_API void resolve_promise(JS::Realm&, Promise const&, JS::Value = JS::js_undefined());
|
|
|
|
WEB_API void reject_promise(JS::Realm&, Promise const&, JS::Value);
|
|
|
|
WEB_API GC::Ref<Promise> react_to_promise(Promise const&, GC::Ptr<ReactionSteps> on_fulfilled_callback, GC::Ptr<ReactionSteps> on_rejected_callback);
|
|
|
|
WEB_API GC::Ref<Promise> upon_fulfillment(Promise const&, GC::Ref<ReactionSteps>);
|
|
|
|
WEB_API GC::Ref<Promise> upon_rejection(Promise const&, GC::Ref<ReactionSteps>);
|
|
|
|
WEB_API void mark_promise_as_handled(Promise const&);
|
|
|
|
WEB_API bool is_promise_fulfilled(Promise const&);
|
|
|
|
WEB_API void wait_for_all(JS::Realm&, Vector<GC::Ref<Promise>> const& promises, Function<void(Vector<JS::Value> const&)> success_steps, Function<void(JS::Value)> failure_steps);
|
|
|
|
WEB_API GC::Ref<Promise> get_promise_for_wait_for_all(JS::Realm&, Vector<GC::Ref<Promise>> const& promises);
|
2022-09-22 23:36:09 +01:00
|
|
|
|
2024-03-08 15:37:28 +00:00
|
|
|
// Non-spec, convenience method.
|
2025-07-19 19:35:33 -07:00
|
|
|
WEB_API GC::Ref<Promise> create_rejected_promise_from_exception(JS::Realm&, Exception);
|
2024-03-08 15:37:28 +00:00
|
|
|
|
2022-09-22 23:36:09 +01:00
|
|
|
}
|