Bug 1060161 - Add stack trace to console.assert,error,trace messages. r=janx

This commit is contained in:
Eric Rahm 2014-09-12 14:02:54 -07:00
parent 5345e91818
commit 789b89e789

View File

@ -30,6 +30,12 @@ function log(msg) {
//dump('ProcessGlobal: ' + msg + '\n');
}
function formatStackFrame(aFrame) {
let functionName = aFrame.functionName || '<anonymous>';
return ' at ' + functionName +
' (' + aFrame.filename + ':' + aFrame.lineNumber + ')';
}
const gFactoryResetFile = "/persist/__post_reset_cmd__";
function ProcessGlobal() {}
@ -112,11 +118,21 @@ ProcessGlobal.prototype = {
// Pipe `console` log messages to the nsIConsoleService which
// writes them to logcat on Gonk.
let message = subject.wrappedJSObject;
let prefix = ('Content JS ' + message.level.toUpperCase() +
' at ' + message.filename + ':' + message.lineNumber +
' in ' + (message.functionName || 'anonymous') + ': ');
Services.console.logStringMessage(prefix + Array.join(message.arguments,
' '));
let args = message.arguments;
let stackTrace = '';
if (message.level == 'assert' || message.level == 'error' || message.level == 'trace') {
stackTrace = Array.map(message.stacktrace, formatStackFrame).join('\n');
} else {
stackTrace = formatStackFrame(message);
}
if (stackTrace) {
args.push('\n' + stackTrace);
}
let prefix = 'Content JS ' + message.level.toUpperCase() + ': ';
Services.console.logStringMessage(prefix + Array.join(args, ' '));
break;
}
}