Skip to content

Instantly share code, notes, and snippets.

@snaka
Created March 8, 2009 04:27
Show Gist options
  • Save snaka/75567 to your computer and use it in GitHub Desktop.
Save snaka/75567 to your computer and use it in GitHub Desktop.
<html><head><title>JS Stack trace for IE</title>
<script type="text/javascript">
// --- stack trace ---
function stackTrace() {
var caller = arguments.callee.caller;
var stack = funcName(caller) + '<br/>' +
walker(caller.arguments.callee.caller);
window.open().document.write(stack);
function walker(caller) {
if (!caller) return;
var result = ' ... ' + funcName(caller) + '<br/>';
result += walker(caller.arguments.callee.caller) || '';
return result;
}
function funcName(name) {
return name.toString().match(/function\s+(\S+\(\S*\))/)[1];
}
}
// --- usage example ---
function calltop() { intermidiate1() }
function intermidiate1() { intermidiate2() }
function intermidiate2() { intermidiate3() }
function intermidiate3() { callfunc() }
function callfunc() {
stackTrace();
}
</script></head>
<body>
<button onclick="calltop()">RUN</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment