Bug 1083851 part 4. Expose promise stacks on PromiseDebugging.
authorBoris Zbarsky <bzbarsky@mit.edu>
Sun, 19 Oct 2014 22:27:12 -0400
changeset 211159 68942e4d2ddf3c9eca8770949ba56a2d547f38e3
parent 211158 49b03421e1cf56d37db28bca6a0c818101d75ab5
child 211160 652e8de626d23cc31eb5d0801b305faee49ac4c4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs1083851
milestone36.0a1
Bug 1083851 part 4. Expose promise stacks on PromiseDebugging.
dom/promise/PromiseDebugging.cpp
dom/promise/PromiseDebugging.h
dom/webidl/PromiseDebugging.webidl
--- a/dom/promise/PromiseDebugging.cpp
+++ b/dom/promise/PromiseDebugging.cpp
@@ -31,10 +31,31 @@ PromiseDebugging::GetState(GlobalObject&
   case Promise::Rejected:
     aState.mState = PromiseDebuggingState::Rejected;
     JS::ExposeValueToActiveJS(aPromise.mResult);
     aState.mReason = aPromise.mResult;
     break;
   }
 }
 
+/* static */ void
+PromiseDebugging::GetAllocationStack(GlobalObject&, Promise& aPromise,
+                                     JS::MutableHandle<JSObject*> aStack)
+{
+  aStack.set(aPromise.mAllocationStack);
+}
+
+/* static */ void
+PromiseDebugging::GetRejectionStack(GlobalObject&, Promise& aPromise,
+                                    JS::MutableHandle<JSObject*> aStack)
+{
+  aStack.set(aPromise.mRejectionStack);
+}
+
+/* static */ void
+PromiseDebugging::GetFullfillmentStack(GlobalObject&, Promise& aPromise,
+                                       JS::MutableHandle<JSObject*> aStack)
+{
+  aStack.set(aPromise.mFullfillmentStack);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/promise/PromiseDebugging.h
+++ b/dom/promise/PromiseDebugging.h
@@ -2,26 +2,35 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_PromiseDebugging_h
 #define mozilla_dom_PromiseDebugging_h
 
+#include "js/TypeDecls.h"
+
 namespace mozilla {
 namespace dom {
 
 class Promise;
 struct PromiseDebuggingStateHolder;
 class GlobalObject;
 
 class PromiseDebugging
 {
 public:
   static void GetState(GlobalObject&, Promise& aPromise,
                        PromiseDebuggingStateHolder& aState);
+
+  static void GetAllocationStack(GlobalObject&, Promise& aPromise,
+                                 JS::MutableHandle<JSObject*> aStack);
+  static void GetRejectionStack(GlobalObject&, Promise& aPromise,
+                                JS::MutableHandle<JSObject*> aStack);
+  static void GetFullfillmentStack(GlobalObject&, Promise& aPromise,
+                                   JS::MutableHandle<JSObject*> aStack);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_PromiseDebugging_h
--- a/dom/webidl/PromiseDebugging.webidl
+++ b/dom/webidl/PromiseDebugging.webidl
@@ -12,9 +12,29 @@ dictionary PromiseDebuggingStateHolder {
   any value;
   any reason;
 };
 enum PromiseDebuggingState { "pending", "fulfilled", "rejected" };
 
 [ChromeOnly, Exposed=(Window,System)]
 interface PromiseDebugging {
   static PromiseDebuggingStateHolder getState(Promise<any> p);
+
+  /**
+   * Return the stack to the promise's allocation point.  This can
+   * return null if the promise was not created from script.
+   */
+  static object? getAllocationStack(Promise<any> p);
+
+  /**
+   * Return the stack to the promise's rejection point, if the
+   * rejection happened from script.  This can return null if the
+   * promise has not been rejected or was not rejected from script.
+   */
+  static object? getRejectionStack(Promise<any> p);
+
+  /**
+   * Return the stack to the promise's fulfillment point, if the
+   * fulfillment happened from script.  This can return null if the
+   * promise has not been fulfilled or was not fulfilled from script.
+   */
+  static object? getFullfillmentStack(Promise<any> p);
 };