Skip to content

Instantly share code, notes, and snippets.

@houkanshan
Created October 11, 2013 15:22
Show Gist options
  • Save houkanshan/6936599 to your computer and use it in GitHub Desktop.
Save houkanshan/6936599 to your computer and use it in GitHub Desktop.
get stack
// https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
function customPrepare(error, trace) {
return trace
}
function getStack() {
var stack
var oldPrepare = Error.prepareStackTrace
Error.prepareStackTrace = customPrepare
stack = (new Error()).stack
Error.prepareStackTrace = oldPrepare
return stack
}
function test(){
var stack = getStack()
stack.forEach(function(call){
console.log('[Func]', call.getFunction())
console.log('[FuncName]', call.getFunctionName())
console.log('[MethodName]', call.getMethodName())
})
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment