Providing "script name" to eval

Tim Fox timvolpe at gmail.com
Wed Jul 9 15:02:59 UTC 2014


Hi folks,

I am using Nashorn to execute a piece of JavaScript using eval:

String str = loadFileFromClasspath(scriptName);

engine.eval(str);

If there's an error in the script, I get an error message something like 
this:

ReferenceError: "blah" is not defined in <eval> at line number 1245242

Is there any way informing the engine of the "script name" when running 
the eval so it provides nicer error messages like this:

ReferenceError: "blah" is not defined in myscript.js at line number 1245242

Which is much nicer for the user.

(As a last resort I can catch any exceptions and replace <eval> with 
scriptName then rethrow them, but it would be nice if the engine could 
do this for me)




More information about the nashorn-dev mailing list