Bug 1280818 part 2. Change console to capture the first non-self-hosted subsumed frame when it just needs a caller location, instead of capturing the first frame and then possibly failing to get useful location info out of it because it's self-hosted. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 21 Jul 2016 23:41:02 -0400
changeset 346255 3ad6f81739fb5ee9cfed230439415e1ce995f57e
parent 346254 0916f44729ff5048a81117573c627089946b0c1a
child 346256 33e19f0223e71ad6d87abe8bc9ecc7a4f10b9a67
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1280818
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1280818 part 2. Change console to capture the first non-self-hosted subsumed frame when it just needs a caller location, instead of capturing the first frame and then possibly failing to get useful location info out of it because it's self-hosted. r=baku
dom/bindings/Exceptions.cpp
dom/bindings/Exceptions.h
dom/console/Console.cpp
--- a/dom/bindings/Exceptions.cpp
+++ b/dom/bindings/Exceptions.cpp
@@ -198,17 +198,26 @@ GetCurrentJSStack(int32_t aMaxDepth)
 {
   // is there a current context available?
   JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
 
   if (!cx || !js::GetContextCompartment(cx)) {
     return nullptr;
   }
 
-  return dom::exceptions::CreateStack(cx, aMaxDepth);
+  static const unsigned MAX_FRAMES = 100;
+  if (aMaxDepth < 0) {
+    aMaxDepth = MAX_FRAMES;
+  }
+
+  JS::StackCapture captureMode = aMaxDepth == 0
+    ? JS::StackCapture(JS::AllFrames())
+    : JS::StackCapture(JS::MaxFrames(aMaxDepth));
+
+  return dom::exceptions::CreateStack(cx, mozilla::Move(captureMode));
 }
 
 namespace exceptions {
 
 class JSStackFrame : public nsIStackFrame
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@@ -660,28 +669,20 @@ NS_IMETHODIMP JSStackFrame::ToString(JSC
   _retval.AppendPrintf(format,
                        NS_ConvertUTF16toUTF8(filename).get(),
                        NS_ConvertUTF16toUTF8(funname).get(),
                        lineno);
   return NS_OK;
 }
 
 already_AddRefed<nsIStackFrame>
-CreateStack(JSContext* aCx, int32_t aMaxDepth)
+CreateStack(JSContext* aCx, JS::StackCapture&& aCaptureMode)
 {
-  static const unsigned MAX_FRAMES = 100;
-  if (aMaxDepth < 0) {
-    aMaxDepth = MAX_FRAMES;
-  }
-
   JS::Rooted<JSObject*> stack(aCx);
-  JS::StackCapture capture = aMaxDepth == 0
-    ? JS::StackCapture(JS::AllFrames())
-    : JS::StackCapture(JS::MaxFrames(aMaxDepth));
-  if (!JS::CaptureCurrentStack(aCx, &stack, mozilla::Move(capture))) {
+  if (!JS::CaptureCurrentStack(aCx, &stack, mozilla::Move(aCaptureMode))) {
     return nullptr;
   }
 
   if (!stack) {
     return nullptr;
   }
 
   nsCOMPtr<nsIStackFrame> frame = new JSStackFrame(stack);
--- a/dom/bindings/Exceptions.h
+++ b/dom/bindings/Exceptions.h
@@ -8,16 +8,17 @@
 #define mozilla_dom_Exceptions_h__
 
 // DOM exception throwing machinery (for both main thread and workers).
 
 #include <stdint.h>
 #include "jspubtd.h"
 #include "nsIException.h"
 #include "nsStringGlue.h"
+#include "jsapi.h"
 
 class nsIStackFrame;
 class nsPIDOMWindowInner;
 template <class T>
 struct already_AddRefed;
 
 namespace mozilla {
 namespace dom {
@@ -52,19 +53,16 @@ CreateException(JSContext* aCx, nsresult
 // value is -1, a default maximal depth will be selected.  Will return null if
 // there is no JS stack right now.
 already_AddRefed<nsIStackFrame>
 GetCurrentJSStack(int32_t aMaxDepth = -1);
 
 // Internal stuff not intended to be widely used.
 namespace exceptions {
 
-// aMaxDepth can be used to define a maximal depth for the stack trace. If the
-// value is -1, a default maximal depth will be selected.  Will return null if
-// there is no JS stack right now.
 already_AddRefed<nsIStackFrame>
-CreateStack(JSContext* aCx, int32_t aMaxDepth = -1);
+CreateStack(JSContext* aCx, JS::StackCapture&& aCaptureMode);
 
 } // namespace exceptions
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -1246,19 +1246,20 @@ Console::MethodInternal(JSContext* aCx, 
     nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
     if (NS_WARN_IF(!principal)) {
       return;
     }
 
     callData->SetOriginAttributes(BasePrincipal::Cast(principal)->OriginAttributesRef());
   }
 
-  uint32_t maxDepth = ShouldIncludeStackTrace(aMethodName) ?
-                      DEFAULT_MAX_STACKTRACE_DEPTH : 1;
-  nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, maxDepth);
+  JS::StackCapture captureMode = ShouldIncludeStackTrace(aMethodName) ?
+    JS::StackCapture(JS::MaxFrames(DEFAULT_MAX_STACKTRACE_DEPTH)) :
+    JS::StackCapture(JS::FirstSubsumedFrame(aCx));
+  nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, mozilla::Move(captureMode));
 
   if (stack) {
     callData->mTopStackFrame.emplace();
     nsresult rv = StackFrameToStackEntry(aCx, stack,
                                          *callData->mTopStackFrame);
     if (NS_FAILED(rv)) {
       return;
     }