// function getStack(n) {
//     var stacks = [];
//
//     try {
//         throw new Error("Test getStack")
//
//     } catch (e) {
//         var stack = e.stack.split("\n");
//
//         for (var i = 0, j = stack.length; i < j; i++) {
//             var current = stack[i].match(/^(?:\s*at? ?)?(.+?)(?:@| )\(?(.*?):[^\/](\d*):?(\d*)?/);
//
//             if (current == null) {
//                 continue;
//             }
//
//             var entry = {
//                 fn: current[1] || "anonymous",
//                 file: current[2] || "unknown",
//                 line: ~~current[3],
//                 column: ~~current[4],
//                 time: new Date().getTime()
//             };
//
//             if ("getStack" !== entry.fn){
//                 stacks.push(entry);
//             }
//         }
//
//     } finally {
//         //return "number"=== typeof n?stacks[n]:stacks;
//         console.log("number" === typeof n ? stacks[n] : stacks);
//     }
// }

function getStack(n, e) {

//	console.log(e);

	if (typeof e.stack == "undefined") {
		console.log(e);
		return null;
	} 

    var stacks = [];
    var stack = e.stack.split("\n");

    for (var i = 0, j = stack.length; i < j; i++) {
        var current = stack[i].match(/^(?:\s*at? ?)?(.+?)(?:@| )\(?(.*?):[^\/](\d*):?(\d*)?/);

        if (current == null) {
            continue;
        }

        var entry = {
            msg : e.message,
            fn: current[1] || "anonymous",
            file: current[2] || "unknown",
            line: ~~current[3],
            column: ~~current[4],
            time: new Date().getTime()
        };

        if ("getStack" !== entry.fn){
            stacks.push(entry);
        }
    }

    console.log("number" === typeof n ? stacks[n] : stacks);
    //console.log( stacks);
}