Error Stack Column number

Art Fiedler artfiedler at gmail.com
Fri Dec 2 08:36:16 UTC 2016


Your right it's still not standard even in the EMCAScript 2016, it just
seems to
be the commonality. When thinking java yes line only makes sense as
typically
one who writes java does not minify the code. When thinking javascript
however
minified code is quite normal and myfile:1 might mean 5000 other lines as
well.

I looked into the source some to see if it actually is feasible to build my
own
stacktrace with file:line:column, however in the current state it seems
impossible! Nashorn actually uses java.lang.Throwable.getStackTrace() to
get the
stack and that ends up being native. The only place you can get the
columnNumber
is for the specific location the error was thrown. Keyword "thrown".

If you noticed my previous sample new Error().columnNumber === -1 since
columnNumber is not populated... however if you throw & catch then...
    try { throw new Error(); }
    catch(e) { /* e.columnNumber === 6 */ }

In my case with console.count(), the need for columnNumber is not the
location
of new Error() either, since the console.count() function would need the
callers file:line:col as that is where console.count() is called from.

In the end I still think if the stack element is from a script it should
include
the column number like node.js, ff, edge all seem to be doing. Since a line
only
is useless when the script is minified. However considering that nashorn is
not
providing the stackTrace directly, I could see why the team may not want to
include the columnNumber. If you do however know of another way to get the
callers file:line:col please let me know. My second thought was to check
arguments.callee.caller for that info but no dice.

-Arthur Fiedler

We do not aim to provide complete compatibility with other JS
> implementations on the non-standard properties such as "stack". stack
> tries to mimic whatever is done for Java code (no column number for
> eg.). But, as you've noted there are enough information on Error objects
> via other properties like lineNumber, columnNumber, fileName. It should
> be possible to write a simple utility function to format stack string as
> desired for specific applications.
>
> Thanks,
> -Sundar
>


More information about the nashorn-dev mailing list