Bug 1109608 - Log.stackTrace should use human-readable task stack traces if available. r=Yoric
authorRavi Shankar <wafflespeanut@gmail.com>
Wed, 11 Mar 2015 03:21:00 -0400
changeset 233395 f69c5955f8c77791dfe66e3636880173ee4a4a08
parent 233394 a5c70a2fab90dbfdbdc972cf7aee791afe79f6af
child 233396 6a6d063004937b2c3a5f2b4818769be09fd528bf
push id56829
push userryanvm@gmail.com
push dateThu, 12 Mar 2015 22:35:09 +0000
treeherdermozilla-inbound@42afc7ef5ccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1109608
milestone39.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 1109608 - Log.stackTrace should use human-readable task stack traces if available. r=Yoric
toolkit/modules/Log.jsm
toolkit/modules/tests/xpcshell/test_Log.js
--- a/toolkit/modules/Log.jsm
+++ b/toolkit/modules/Log.jsm
@@ -189,18 +189,18 @@ this.Log = {
           output.push(str);
         }
         frame = frame.caller;
       }
       return "Stack trace: " + output.join(" < ");
     }
     // Standard JS exception
     if (e.stack) {
-      return "JS Stack trace: " + e.stack.trim().replace(/\n/g, " < ").
-        replace(/@[^@]*?([^\/\.]+\.\w+:)/g, "@$1");
+      return "JS Stack trace: " + Task.Debugging.generateReadableStack(e.stack).trim()
+        .replace(/\n/g, " < ").replace(/@[^@]*?([^\/\.]+\.\w+:)/g, "@$1");
     }
 
     return "No traceback available";
   }
 };
 
 /*
  * LogMessage
--- a/toolkit/modules/tests/xpcshell/test_Log.js
+++ b/toolkit/modules/tests/xpcshell/test_Log.js
@@ -1,16 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 const {utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 
+Cu.import("resource://gre/modules/Promise.jsm")
 Cu.import("resource://gre/modules/Log.jsm");
 
 let testFormatter = {
   format: function format(message) {
     return message.loggerName + "\t" +
       message.levelDesc + "\t" +
       message.message;
   }
@@ -568,18 +569,24 @@ add_task(function format_errors() {
   err = new ReferenceError("Ref Error", "ERROR_FILE", 28);
   str = pFormat.format(err);
   do_check_true(str.contains("ReferenceError"));
   do_check_true(str.contains("ERROR_FILE:28"));
   do_check_true(str.contains("Ref Error"));
 
   // Test that JS-generated Errors are recognized and formatted.
   try {
+    yield Promise.resolve();  // Scrambles the stack
     eval("javascript syntax error");
   }
   catch (e) {
     str = pFormat.format(e);
     do_check_true(str.contains("SyntaxError: missing ;"));
     // Make sure we identified it as an Error and formatted the error location as
     // lineNumber:columnNumber.
     do_check_true(str.contains(":1:11)"));
+    // Make sure that we use human-readable stack traces
+    // Check that the error doesn't contain any reference to "Promise.jsm" or "Task.jsm"
+    do_check_false(str.contains("Promise.jsm"));
+    do_check_false(str.contains("Task.jsm"));
+    do_check_true(str.contains("format_errors"));
   }
 });