PromiseDebugging.h 3.0 KB

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