Permalink
Browse files

Properly handle XPCOM exceptions and correctly order traceback.

  • Loading branch information...
1 parent 9e0e59a commit 25885083e51e64565a91eaf5c5a974471f51f5b5 @Mossop committed Dec 14, 2012
Showing with 11 additions and 6 deletions.
  1. +1 −1 lib/sdk/console/traceback.js
  2. +5 −4 lib/sdk/test/harness.js
  3. +5 −1 lib/toolkit/loader.js
@@ -30,7 +30,7 @@ function nsIStackFramesToJSON(frame) {
while (frame) {
if (frame.filename) {
- stack.push({
+ stack.unshift({
fileName: sourceURI(frame.filename),
lineNumber: frame.lineNumber,
name: frame.name
@@ -15,7 +15,7 @@ const { setTimeout } = require('../timers');
const memory = require('../deprecated/memory');
const { PlainTextConsole } = require("../console/plain-text");
const { when: unload } = require("../system/unload");
-const { format } = require("../console/traceback");
+const { format, fromException } = require("../console/traceback");
const system = require("../system");
// Trick manifest builder to make it think we need these modules ?
@@ -327,7 +327,7 @@ var runTests = exports.runTests = function runTests(options) {
nextIteration();
} catch (e) {
- let frames = parseStack(e.stack).reverse().reduce(function(frames, frame) {
+ let frames = fromException(e).reverse().reduce(function(frames, frame) {
if (frame.fileName.split("/").pop() === "unit-test-finder.js")
frames.done = true
if (!frames.done) frames.push(frame)
@@ -337,13 +337,14 @@ var runTests = exports.runTests = function runTests(options) {
let prototype = typeof(e) === "object" ? e.constructor.prototype :
Error.prototype;
- let stack = serializeStack(frames);
+ let stack = serializeStack(frames.reverse());
let error = Object.create(prototype, {
message: { value: e.message, writable: true, configurable: true },
fileName: { value: e.fileName, writable: true, configurable: true },
lineNumber: { value: e.lineNumber, writable: true, configurable: true },
- stack: { value: stack, writable: true, configurable: true }
+ stack: { value: stack, writable: true, configurable: true },
+ toString: { value: function() e.message, writable: true, configurable: true },
});
print("Error: " + error + " \n " + format(error));
@@ -237,6 +237,9 @@ const load = iced(function load(loader, module) {
try {
evaluate(sandbox, module.uri);
} catch (error) {
+ // If there is no JS stack to filter then just throw the real error
+ if (!error.stack)
+ throw error;
let { message, fileName, lineNumber, stack } = error;
let frames = parseStack(stack).filter(isntLoaderFrame);
@@ -258,7 +261,8 @@ const load = iced(function load(loader, module) {
message: message,
fileName: fileName,
lineNumber: lineNumber,
- stack: serializeStack(frames)
+ stack: serializeStack(frames),
+ toString: function() message
}));
}

0 comments on commit 2588508

Please sign in to comment.