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 178655 50ed9e6646ad8985e47eb74bbc8a2bcced84a1cf
parent 178654 597f5b9dba63e2310e1ee676a6bbed08c29c5b70
child 178656 5ec886a84e94d4dae9defc11c28b8709c8382746
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbz
bugs920116
milestone31.0a1
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;