Debug dynamically loaded JavaScript code using IntelliJ and the Nashorn engine

I dynamically load and run JavaScript code that is stored on disk in the YAML file. I would like to know if it is possible (using intelliJ) to debug JS code even if I do not load it from a standalone JS file. To simplify the description of the problem, consider the following Java code:

NashornScriptEngineFactory nashornFactory = new NashornScriptEngineFactory();
ScriptEngine engine = nashornFactory.getScriptEngine();
engine.eval("var a = 1 + 1;\nprint(a);");

How to set a breakpoint on line 2 (calling the "print" function) and how do I know the value of the variable "a"? If this is not possible, what would be the best way?

+4
source share
1 answer

https://blogs.oracle.com/sundararajan/remote-debugging-of-nashorn-scripts-with-netbeans-ide-using-debugger-statements, java .

IntelliJ IDEA, .

JavaScript:

debugger;

, . .

IntelliJ, / , javascript , .

+2

Source: https://habr.com/ru/post/1648699/


All Articles