With IntelliJ IDEA 13.1 RC2, now you can add breakpoints to your Nashorn scripts and go through them when debugging your Java application. Let’s see how it works on a simple example. Here we have an application which loads a Java interface implementation from in a Nashorn script. The interface has a “sayHello” method with a single String parameter and returning a String.
When we run the application in the Debug mode, it stops at our breakpoint so we can see the state of local variables and step through the script statements.
Then we stop at another breakpoint we added, but already on the Java side. Here we can see the state of the “demo.HelloWorld” instance, returned by the script.
Now if we call the Step Into action, we’ll be able to step inside the script.
Note that here we use an instance of “demo.HelloHelper” Java class to get a “prefix.” This means that if we use the Step Into action again, we’ll get back to the Java side.
Also notice, that the Frames tab shows the exact stack of the invoked methods from both Java and Narshorn code.
As you can see, with IntelliJ IDEA it’s really easy to debug your Nashorn scripts. We’ll hope this feature will come useful for you as Nashorn is a very powerful tool for scripting your Java application.
Develop with Pleasure!