Last active
June 1, 2016 09:45
-
-
Save friedemannsommer/22bdfacba8173f80276a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stacktrace() { | |
var stack; | |
function trace(fn) { | |
return (typeof fn !== 'function') | |
? [] | |
: trace(fn.caller).concat([fn.toString().split('(')[0].substring(9)]); | |
} | |
try { | |
throw new Error('stacktrace'); | |
} | |
catch (e) { | |
if (typeof e.stack === 'string') { | |
stack = e.stack; | |
} | |
else { | |
var arrayStack = trace(arguments.callee.caller); | |
arrayStack.shift(); | |
arrayStack.reverse(); | |
stack = arrayStack.join('\n\t'); | |
} | |
} | |
return stack; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stacktrace():string { | |
let stack:string; | |
function trace(fn:Function):Array<string> { | |
return (typeof fn !== 'function') | |
? [] | |
: trace(fn.caller).concat([fn.toString().split('(')[0].substring(9)]); | |
} | |
try { | |
throw new Error('stacktrace'); | |
} | |
catch(e) { | |
if(typeof e.stack === 'string'){ | |
stack = e.stack; | |
} | |
else { | |
let arrayStack:Array<string> = trace(arguments.callee.caller); | |
arrayStack.shift(); | |
arrayStack.reverse(); | |
stack = arrayStack.join('\n\t'); | |
} | |
} | |
return stack; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment