PromiseDebugging.h (2944B)
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/. */ 6 7 #ifndef mozilla_dom_PromiseDebugging_h 8 #define mozilla_dom_PromiseDebugging_h 9 10 #include "js/TypeDecls.h" 11 #include "nsTArray.h" 12 13 namespace mozilla { 14 15 class ErrorResult; 16 17 namespace dom { 18 class Promise; 19 struct PromiseDebuggingStateHolder; 20 class GlobalObject; 21 class UncaughtRejectionObserver; 22 class FlushRejections; 23 class WorkerPrivate; 24 25 void TriggerFlushRejections(); 26 27 class PromiseDebugging { 28 public: 29 static void Init(); 30 static void Shutdown(); 31 32 static void GetState(GlobalObject&, JS::Handle<JSObject*> aPromise, 33 PromiseDebuggingStateHolder& aState, ErrorResult& aRv); 34 35 static void GetPromiseID(GlobalObject&, JS::Handle<JSObject*>, nsString&, 36 ErrorResult&); 37 38 static void GetAllocationStack(GlobalObject&, JS::Handle<JSObject*> aPromise, 39 JS::MutableHandle<JSObject*> aStack, 40 ErrorResult& aRv); 41 static void GetRejectionStack(GlobalObject&, JS::Handle<JSObject*> aPromise, 42 JS::MutableHandle<JSObject*> aStack, 43 ErrorResult& aRv); 44 static void GetFullfillmentStack(GlobalObject&, 45 JS::Handle<JSObject*> aPromise, 46 JS::MutableHandle<JSObject*> aStack, 47 ErrorResult& aRv); 48 49 // Mechanism for watching uncaught instances of Promise. 50 static void AddUncaughtRejectionObserver( 51 GlobalObject&, UncaughtRejectionObserver& aObserver); 52 static bool RemoveUncaughtRejectionObserver( 53 GlobalObject&, UncaughtRejectionObserver& aObserver); 54 55 // Mark a Promise as having been left uncaught at script completion. 56 static void AddUncaughtRejection(JS::Handle<JSObject*>); 57 // Mark a Promise previously added with `AddUncaughtRejection` as 58 // eventually consumed. 59 static void AddConsumedRejection(JS::Handle<JSObject*>); 60 // Propagate the informations from AddUncaughtRejection 61 // and AddConsumedRejection to observers. 62 static void FlushUncaughtRejections(); 63 64 protected: 65 static void FlushUncaughtRejectionsInternal(); 66 friend class FlushRejections; 67 friend class mozilla::dom::WorkerPrivate; 68 69 private: 70 // Identity of the process. 71 // This property is: 72 // - set during initialization of the layout module, 73 // prior to any Worker using it; 74 // - read by both the main thread and the Workers; 75 // - unset during shutdown of the layout module, 76 // after any Worker has been shutdown. 77 static nsString sIDPrefix; 78 }; 79 80 } // namespace dom 81 } // namespace mozilla 82 83 #endif // mozilla_dom_PromiseDebugging_h