Bug 1133191 - Part 0: Add indentation variant to JS::BuildStackString. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Fri, 07 Aug 2015 08:14:05 +0900
changeset 264996 632e3de508dd7e5cafb3dc7ba78a0c1acfe6f1c4
parent 264995 28dda1c9988d040d3ca173275d8b5ba4939b4fb5
child 264997 706f10f6c21b057e98f0bd42764c64352fe897d2
push id65815
push userarai_a@mac.com
push dateTue, 29 Sep 2015 17:09:14 +0000
treeherdermozilla-inbound@706f10f6c21b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1133191
milestone44.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 1133191 - Part 0: Add indentation variant to JS::BuildStackString. r=jandem
js/src/jsapi.h
js/src/vm/SavedStacks.cpp
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -5395,19 +5395,22 @@ GetSavedFrameParent(JSContext* cx, Handl
 /*
  * Given a SavedFrame JSObject stack, stringify it in the same format as
  * Error.prototype.stack. The stringified stack out parameter is placed in the
  * cx's compartment. Defaults to the empty string.
  *
  * The same notes above about SavedFrame accessors applies here as well: cx
  * doesn't need to be in stack's compartment, and stack can be null, a
  * SavedFrame object, or a wrapper (CCW or Xray) around a SavedFrame object.
+ *
+ * Optional indent parameter specifies the number of white spaces to indent
+ * each line.
  */
 extern JS_PUBLIC_API(bool)
-BuildStackString(JSContext* cx, HandleObject stack, MutableHandleString stringp);
+BuildStackString(JSContext* cx, HandleObject stack, MutableHandleString stringp, size_t indent = 0);
 
 } /* namespace JS */
 
 
 /* Stopwatch-based CPU monitoring. */
 
 namespace js {
 
--- a/js/src/vm/SavedStacks.cpp
+++ b/js/src/vm/SavedStacks.cpp
@@ -732,17 +732,17 @@ GetSavedFrameParent(JSContext* cx, Handl
     if (subsumedParent && !(subsumedParent->getAsyncCause() || skippedAsync))
         parentp.set(parent);
     else
         parentp.set(nullptr);
     return SavedFrameResult::Ok;
 }
 
 JS_PUBLIC_API(bool)
-BuildStackString(JSContext* cx, HandleObject stack, MutableHandleString stringp)
+BuildStackString(JSContext* cx, HandleObject stack, MutableHandleString stringp, size_t indent)
 {
     js::StringBuffer sb(cx);
 
     // Enter a new block to constrain the scope of possibly entering the stack's
     // compartment. This ensures that when we finish the StringBuffer, we are
     // back in the cx's original compartment, and fulfill our contract with
     // callers to place the output string in the cx's current compartment.
     {
@@ -759,17 +759,18 @@ BuildStackString(JSContext* cx, HandleOb
             MOZ_ASSERT(SavedFrameSubsumedByCaller(cx, frame));
 
             if (!frame->isSelfHosted()) {
                 RootedString asyncCause(cx, frame->getAsyncCause());
                 if (!asyncCause && skippedAsync)
                     asyncCause.set(cx->names().Async);
 
                 js::RootedAtom name(cx, frame->getFunctionDisplayName());
-                if ((asyncCause && (!sb.append(asyncCause) || !sb.append('*')))
+                if ((indent && !sb.appendN(' ', indent))
+                    || (asyncCause && (!sb.append(asyncCause) || !sb.append('*')))
                     || (name && !sb.append(name))
                     || !sb.append('@')
                     || !sb.append(frame->getSource())
                     || !sb.append(':')
                     || !NumberValueToStringBuffer(cx, NumberValue(frame->getLine()), sb)
                     || !sb.append(':')
                     || !NumberValueToStringBuffer(cx, NumberValue(frame->getColumn()), sb)
                     || !sb.append('\n'))