[broadway] Add stacktrace debugging functions

This commit is contained in:
Alexander Larsson 2011-04-12 10:13:38 +02:00
parent 2934569781
commit 840df5c7c1

View File

@ -11,6 +11,62 @@ function log(str) {
logDiv.appendChild(document.createElement('br'));
}
function getStackTrace()
{
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0;
} catch(e) {
if (e.stack) { // Firefox
var lines = e.stack.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
callstack.push(lines[i]);
}
}
// Remove call to getStackTrace()
callstack.shift();
isCallstackPopulated = true;
} else if (window.opera && e.message) { // Opera
var lines = e.message.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
var entry = lines[i];
// Append next line also since it has the file info
if (lines[i+1]) {
entry += " at " + lines[i+1];
i++;
}
callstack.push(entry);
}
}
// Remove call to getStackTrace()
callstack.shift();
isCallstackPopulated = true;
}
}
if (!isCallstackPopulated) { //IE and Safari
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous";
callstack.push(fname);
currentFunction = currentFunction.caller;
}
}
return callstack;
}
function logStackTrace(len) {
var callstack = getStackTrace();
var end = callstack.length;
if (len > 0)
end = Math.min(len + 1, end);
for (var i = 1; i < end; i++)
log(callstack[i]);
}
var base64Values = [
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,