Locate code line and file

Get the code line and file from error stack

by Unmi Qiu

HTML

<pre id="stack"></pre>
<pre id="loc"></pre>

JavaScript

var log = {
    info: function(arg){
        try {
            throw new Error();
        } catch (e) {
            document.querySelector("#stack").innerHTML = e.stack;
            var loc= e.stack.replace(/Error\n/).split(/\n/)[1].replace(/^\s+|\s+$/, "");
            document.querySelector("#loc").innerHTML = "Location: "+loc;
        }
    }
};

function foo(){
    log.info(123);
}

foo();