Error Stack Column number

Art Fiedler artfiedler at
Wed Nov 30 22:02:54 UTC 2016

When making an implementation of console.count([label])  part of the
Mozilla's developer docs
mentions when label is omitted, the function will count the number of times
count() was called
on that line... however, if the javascript code has been minified all lines
of code may be on the
same line... messing up all console.count() calls...

I was providing that implementation by using new Error().stack and parsing
the current file:line...
however I could fix the minify issue if new Error().stack output the column
also for instance...
other browser seem to be doing file:line:column in the stack trace.
Including nodejs see:

Microsoft Edge's dev console outputs...
    new Error().stack:
       at eval code (eval code:1:1)"
Firefox since FF30:

Currently nashorn error stacks only include the line number...
    public static void main(String[] args) throws Exception {
        NashornScriptEngineFactory factory = new
        ScriptEngine scriptEngine = factory.getScriptEngine();
        scriptEngine.put(ScriptEngine.FILENAME, "myfile.js");
        scriptEngine.eval("print('fileName: ' + new Error().fileName);");
        scriptEngine.eval("print('lineNumber: ' + new
        scriptEngine.eval("print('columnNumber: ' + new
        scriptEngine.eval("print('stack: ' + new Error().stack);");
    fileName: myfile.js
    lineNumber: 1
    columnNumber: -1
    stack: Error
        at <program> (myfile.js:1)

Would be nice to add the column number to the stacks and error object in

Arthur Fiedler

More information about the nashorn-dev mailing list