Skip to content

Instantly share code, notes, and snippets.

@atdt
Created February 19, 2012 07:47
Show Gist options
  • Save atdt/1862503 to your computer and use it in GitHub Desktop.
Save atdt/1862503 to your computer and use it in GitHub Desktop.
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