It seems mandatory to use the load(filename) Nashorn extension when wanting to be able to debug both Java and Javascript in an IDE, see e.g. Debugging Nashorn JavaScript with Intellij
Unfortunately, this prohibits the use of CompiledScript, as the above returns a ScriptObjectMirror object, and at least no compile(filename) Nashorn extension is documented.
One of the CompiledScript functionalities being lost here is e.g. CompiledScript.eval(ScriptContext context). I couldn't find a way of achieving the same using ScriptObjectMirror. Also, load(filename) will immediately execute the script, which may not be wanted.
//@ sourceURL=annotations automatically to JS source files. This will result in file names being displayed in Nashorn JS stackframes in the Netbeans debugger, even whenload()is not used, e.g. withCompiledScript.