Java Reference
In-Depth Information
Chapter 13
Debugging, Tracing,
and Profiling Scripts
In this chapter, you will learn:
How to debug standalone Nashorn scripts in the NetBeans IDE
How to debug Nashorn scripts that are called from Java code in
the NetBeans IDE
How to trace and profile Nashorn scripts
NetBeans 8 with JDK 8 or later supports debugging, tracing, and profiling Nashorn
scripts. You can run and debug standalone Nashorn scripts from within the NetBeans
IDE. You can also debug Nashorn scripts when they are called from Java code. You can
use all the debugging features for debugging scripts that you can use for debugging Java
code; you can set breakpoints, display variables' values, add watches, monitor call stacks,
and so on. When debugging Nashorn scripts, the debugger shows the Nashorn stack.
In NetBeans, all debugger-related panes can be opened using the menu item
Windows Debugging . For a list of the complete debugging features in NetBeans, please
refer to the help page in NetBeans. You can open the help page by pressing the F1 key
while the NetBeans application is active. I will use the script in Listing 13-1 as an example
of debugging scripts in this chapter.
Listing 13-1. A Test Script Containing an isPrime( ) Function and Calls to That Function
// primetest.js
function isPrime(n) {
// Integers <= 2, floating-point numbers, and even numbers are not
// primes
if (n <= 2 || Math.floor(n) !== n || n % 2 === 0) {
return false;
}
 
Search WWH ::




Custom Search