java - Debug dynamically loaded JavaScript code with IntelliJ and the Nashorn engine -


i dynamically loading , running javascript code stored on disk in yaml file. know if possible (using intellij) debug js code though not loading standalone js file. simplify problem description, consider following java code:

nashornscriptenginefactory nashornfactory = new nashornscriptenginefactory(); scriptengine engine = nashornfactory.getscriptengine(); engine.eval("var = 1 + 1;\nprint(a);"); 

how set breakpoint on line 2 (the "print" function call) , how examine value of variable "a"? if not possible, best workaround?

based on blog post https://blogs.oracle.com/sundararajan/remote-debugging-of-nashorn-scripts-with-netbeans-ide-using-debugger-statements, can attach remote java debugger process.

you can in intellij idea creating new remote run configuration.

after attaching, use javascript command:

debugger; 

this force debugger break if attached. can inspect values of variables within variable window.

if can't manage attach intellij, open browsers inspector/debugger , same line of javascript cause browser's debugger break on line.


Comments