Bug 920116 - Part 1: Add full stacktrace to console.error/exception/assert() in the Console API. r=bz
authorMihai Sucan <mihai.sucan@gmail.com>
Thu, 10 Apr 2014 23:02:37 +0300
changeset 178164 50ed9e6646ad8985e47eb74bbc8a2bcced84a1cf
parent 178163 597f5b9dba63e2310e1ee676a6bbed08c29c5b70
child 178165 5ec886a84e94d4dae9defc11c28b8709c8382746
push id26578
push userryanvm@gmail.com
push dateSun, 13 Apr 2014 23:27:40 +0000
treeherdermozilla-central@989bcc65f883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs920116
milestone31.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 920116 - Part 1: Add full stacktrace to console.error/exception/assert() in the Console API. r=bz
dom/base/Console.cpp
dom/base/Console.h
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -786,18 +786,18 @@ Console::Method(JSContext* aCx, MethodNa
     }
 
     nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
     MOZ_ASSERT(loadContext);
 
     loadContext->GetUsePrivateBrowsing(&callData->mPrivate);
   }
 
-  uint32_t maxDepth = aMethodName == MethodTrace ?
-                       DEFAULT_MAX_STACKTRACE_DEPTH : 1;
+  uint32_t maxDepth = ShouldIncludeStackrace(aMethodName) ?
+                      DEFAULT_MAX_STACKTRACE_DEPTH : 1;
   nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, maxDepth);
 
   if (!stack) {
     Throw(aCx, NS_ERROR_FAILURE);
     return;
   }
 
   // nsIStackFrame is not thread-safe so we take what we need and we store in
@@ -974,17 +974,17 @@ Console::ProcessCallData(ConsoleCallData
                        event.mStyles.Value());
       break;
 
     default:
       event.mArguments.Construct();
       ArgumentsToValueList(aData->mArguments, event.mArguments.Value());
   }
 
-  if (aData->mMethodName == MethodTrace) {
+  if (ShouldIncludeStackrace(aData->mMethodName)) {
     event.mStacktrace.Construct();
     event.mStacktrace.Value().SwapElements(aData->mStack);
   }
 
   else if (aData->mMethodName == MethodGroup ||
            aData->mMethodName == MethodGroupCollapsed ||
            aData->mMethodName == MethodGroupEnd) {
     ComposeGroupName(cx, aData->mArguments, event.mGroupName);
@@ -1474,10 +1474,24 @@ Console::IncreaseCounter(JSContext* aCx,
 void
 Console::ClearConsoleData()
 {
   while (ConsoleCallData* data = mQueuedCalls.popFirst()) {
     delete data;
   }
 }
 
+bool
+Console::ShouldIncludeStackrace(MethodName aMethodName)
+{
+  switch (aMethodName) {
+    case MethodError:
+    case MethodException:
+    case MethodAssert:
+    case MethodTrace:
+      return true;
+    default:
+      return false;
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/Console.h
+++ b/dom/base/Console.h
@@ -186,16 +186,19 @@ private:
 
   JS::Value
   IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
                    const nsTArray<JS::Heap<JS::Value>>& aArguments);
 
   void
   ClearConsoleData();
 
+  bool
+  ShouldIncludeStackrace(MethodName aMethodName);
+
   nsCOMPtr<nsPIDOMWindow> mWindow;
   nsCOMPtr<nsITimer> mTimer;
   nsCOMPtr<nsIConsoleAPIStorage> mStorage;
 
   LinkedList<ConsoleCallData> mQueuedCalls;
   nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
   nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;