Bug 533315 - Show the stack trace of 'e' in do_thow(e) if 'e' is already an exception object. r=ted
authoraceman <acelists@atlas.sk>
Tue, 07 May 2013 22:37:49 -0400
changeset 142160 6ce9acf7e78fe2b7894b7173a62003a5aea1eeea
parent 142159 5a6829c755b70b6e8ccba2af0fa87b4da7796e82
child 142161 ba8cfb0179f14f088111561b9f745daf61ddbb6b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs533315
milestone23.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 533315 - Show the stack trace of 'e' in do_thow(e) if 'e' is already an exception object. r=ted
testing/xpcshell/head.js
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -458,29 +458,55 @@ function do_execute_soon(callback, aName
       }
       finally {
         do_test_finished(funcName);
       }
     }
   }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
 }
 
-function do_throw(text, stack) {
-  if (!stack)
-    stack = Components.stack.caller;
+/**
+ * Shows an error message and the current stack and aborts the test.
+ *
+ * @param error  A message string or an Error object.
+ * @param stack  null or nsIStackFrame object or a string containing
+ *               \n separated stack lines (as in Error().stack).
+ */
+function do_throw(error, stack) {
+  let filename = "";
+  if (!stack) {
+    if (error instanceof Error) {
+      // |error| is an exception object
+      filename = error.fileName;
+      stack = error.stack;
+    } else {
+      stack = Components.stack.caller;
+    }
+  }
+
+  if (stack instanceof Components.interfaces.nsIStackFrame)
+    filename = stack.filename;
+
+  _dump("TEST-UNEXPECTED-FAIL | " + filename + " | " + error +
+        " - See following stack:\n");
+
+  if (stack instanceof Components.interfaces.nsIStackFrame) {
+    let frame = stack;
+    while (frame != null) {
+      _dump(frame + "\n");
+      frame = frame.caller;
+    }
+  } else if (typeof stack == "string") {
+    let stackLines = stack.split("\n");
+    for (let line of stackLines) {
+      _dump(line + "\n");
+    }
+  }
 
   _passed = false;
-  _dump("TEST-UNEXPECTED-FAIL | " + stack.filename + " | " + text +
-        " - See following stack:\n");
-  var frame = Components.stack;
-  while (frame != null) {
-    _dump(frame + "\n");
-    frame = frame.caller;
-  }
-
   _do_quit();
   throw Components.results.NS_ERROR_ABORT;
 }
 
 function do_throw_todo(text, stack) {
   if (!stack)
     stack = Components.stack.caller;