1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
7 /* This is a utility namespace for promise-debugging functionality */
10 dictionary PromiseDebuggingStateHolder {
11 PromiseDebuggingState state = "pending";
15 enum PromiseDebuggingState { "pending", "fulfilled", "rejected" };
18 * An observer for Promise that _may_ be leaking uncaught rejections.
20 * It is generally a programming error to leave a Promise rejected and
21 * not consume its rejection. The information exposed by this
22 * interface is designed to allow clients to track down such Promise,
23 * i.e. Promise that are currently
24 * - in `rejected` state;
25 * - last of their chain.
27 * Note, however, that a promise in such a state at the end of a tick
28 * may eventually be consumed in some ulterior tick. Implementers of
29 * this interface are responsible for presenting the information
30 * in a meaningful manner.
33 callback interface UncaughtRejectionObserver {
35 * A Promise has been left in `rejected` state and is the
36 * last in its chain. If this callback returns true, the rejection
37 * will not be reported.
39 * @param p A currently uncaught Promise. If `p` is is eventually
40 * caught, i.e. if its `then` callback is called, `onConsumed` will
43 boolean onLeftUncaught(object p);
46 * A Promise previously left uncaught is not the last in its
49 * @param p A Promise that was previously left in uncaught state is
50 * now caught, i.e. it is not the last in its chain anymore.
52 undefined onConsumed(object p);
55 [ChromeOnly, Exposed=Window]
56 namespace PromiseDebugging {
58 * The various functions on this interface all expect to take promises but
59 * don't want the WebIDL behavior of assimilating random passed-in objects
60 * into promises. They also want to treat Promise subclass instances as
61 * promises instead of wrapping them in a vanilla Promise, which is what the
62 * IDL spec says to do. So we list all our arguments as "object" instead of
63 * "Promise" and check for them being a Promise internally.
67 * Get the current state of the given promise.
70 PromiseDebuggingStateHolder getState(object p);
73 * Return an identifier for a promise. This identifier is guaranteed
74 * to be unique to the current process.
77 DOMString getPromiseID(object p);
80 * Return the stack to the promise's allocation point. This can
81 * return null if the promise was not created from script.
84 object? getAllocationStack(object p);
87 * Return the stack to the promise's rejection point, if the
88 * rejection happened from script. This can return null if the
89 * promise has not been rejected or was not rejected from script.
92 object? getRejectionStack(object p);
95 * Return the stack to the promise's fulfillment point, if the
96 * fulfillment happened from script. This can return null if the
97 * promise has not been fulfilled or was not fulfilled from script.
100 object? getFullfillmentStack(object p);
103 * Watching uncaught rejections on the current thread.
105 * Adding an observer twice will cause it to be notified twice
108 undefined addUncaughtRejectionObserver(UncaughtRejectionObserver o);
109 boolean removeUncaughtRejectionObserver(UncaughtRejectionObserver o);