Skip to content

Instantly share code, notes, and snippets.

@koistya
Created February 16, 2012 17:20
Show Gist options
  • Save koistya/1846562 to your computer and use it in GitHub Desktop.
Save koistya/1846562 to your computer and use it in GitHub Desktop.
Show v8 stack trace
var stack_holder = new Error;
function stackPrepare(e,stacks) {
var stack = stacks
for (var p in stack[0]) {
stack[p] = stack[0][p]
}
stack.find = function(fn) {
for (var i=stack.length;i--;) {
if (stack[i].getFunction() === fn) break;
}
return i;
}
return stack
}
function getStack(){
var old = Error.prepareStackTrace;
Error.prepareStackTrace = stackPrepare;
Error.captureStackTrace(stack_holder, getStack);
var stack = stack_holder.stack;
Error.prepareStackTrace = old;
return stack;
}
console.log(getStack())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment