1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PromiseDebugging_h
8 #define mozilla_dom_PromiseDebugging_h
10 #include "js/TypeDecls.h"
12 #include "mozilla/RefPtr.h"
20 struct PromiseDebuggingStateHolder
;
22 class UncaughtRejectionObserver
;
23 class FlushRejections
;
26 void TriggerFlushRejections();
28 class PromiseDebugging
{
31 static void Shutdown();
33 static void GetState(GlobalObject
&, JS::Handle
<JSObject
*> aPromise
,
34 PromiseDebuggingStateHolder
& aState
, ErrorResult
& aRv
);
36 static void GetPromiseID(GlobalObject
&, JS::Handle
<JSObject
*>, nsString
&,
39 static void GetAllocationStack(GlobalObject
&, JS::Handle
<JSObject
*> aPromise
,
40 JS::MutableHandle
<JSObject
*> aStack
,
42 static void GetRejectionStack(GlobalObject
&, JS::Handle
<JSObject
*> aPromise
,
43 JS::MutableHandle
<JSObject
*> aStack
,
45 static void GetFullfillmentStack(GlobalObject
&,
46 JS::Handle
<JSObject
*> aPromise
,
47 JS::MutableHandle
<JSObject
*> aStack
,
50 // Mechanism for watching uncaught instances of Promise.
51 static void AddUncaughtRejectionObserver(
52 GlobalObject
&, UncaughtRejectionObserver
& aObserver
);
53 static bool RemoveUncaughtRejectionObserver(
54 GlobalObject
&, UncaughtRejectionObserver
& aObserver
);
56 // Mark a Promise as having been left uncaught at script completion.
57 static void AddUncaughtRejection(JS::HandleObject
);
58 // Mark a Promise previously added with `AddUncaughtRejection` as
59 // eventually consumed.
60 static void AddConsumedRejection(JS::HandleObject
);
61 // Propagate the informations from AddUncaughtRejection
62 // and AddConsumedRejection to observers.
63 static void FlushUncaughtRejections();
66 static void FlushUncaughtRejectionsInternal();
67 friend class FlushRejections
;
68 friend class mozilla::dom::WorkerPrivate
;
71 // Identity of the process.
73 // - set during initialization of the layout module,
74 // prior to any Worker using it;
75 // - read by both the main thread and the Workers;
76 // - unset during shutdown of the layout module,
77 // after any Worker has been shutdown.
78 static nsString sIDPrefix
;
82 } // namespace mozilla
84 #endif // mozilla_dom_PromiseDebugging_h