Java Reference
In-Depth Information
// Get the Nashorn script engine
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
try {
// Get a Reader for the script file
Reader scriptReader = Files.
newBufferedReader(scriptPath);
// Execute the script in the file
engine.eval(scriptReader);
}
catch (IOException | ScriptException e) {
e.printStackTrace();
}
}
}
8 is a prime number: false
37 is a prime number: true
Summary
NetBeans 8 with JDK 8 or later supports debugging Nashorn scripts in the NetBeans IDE.
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. The debugger jumps
from Java code to Nashorn scripts seamlessly.
Nashorn supports callsite tracing and profiling. You can enable these options in
the jjs command-line tool as well as in the embedded Nashorn engine. You can enable
tracing and profiling for all scripts run by the engine or per script/function. The -tcs
option enables callsite tracing for all scripts run by the engine. The -pcs option enables
callsite profiling for all scripts run by the engine and prints the callsite profiling data in
a file called NashornProfile.txt in the current directory. JDK8u40 adds four Nashorn
directives: "nashorn callsite trace enterexit" , "nashorn callsite trace miss" ,
"nashorn callsite trace objects" , and "nashorn callsite profile" . These
directives can be added in the beginning of scripts and functions to trace and profile
scripts and functions selectively. They work only in debug mode, which can be enabled
setting the system property nashorn.debug to true.
 
Search WWH ::




Custom Search