Chris Webster's Weblog
Using the Rhino Javascript debugging APIs
I was looking at Rhino , specifically to see how easy or hard accessing the debugging information would be. As it turns out, things are pretty easy. I have created a NetBeans project which has the basic infrastructure set up to run a script in the debugger. The project is accessible here
http://blogs.sun.com/cwebster/resource/RhinoDebugging.zip.
The essential part of getting this setup is the interaction with the context class, the following must be added:
context.setOptimizationLevel(-1);
RhinoDebugger debugger = new RhinoDebugger();
context.setDebugger(debugger, "sample debugger"
;
The optimization level ensures that the resulting generating code can be debugged. Failing to set the optimization level results in a non supported feature exception, so that one is important. The RhinoDebugger class referenced is an instance of the org.mozilla.javascript.debug.Debugger interface which is notified when a new script is compiled and when execution is started.
The debugger implementation in this code is not much more than print statement, but does show how to access properties in scope.
The sample project requires a reference to Rhino, which is not included so you will need to download this (I used 1.6_R2). This is the same version as in J2SE 6, but includes everything such as E4x. NetBeans projects are based on ant, so the built scripts can be executed outside of NetBeans, just add an entry to the project.properties of the form file.reference.js.jar=PATH_TO_RHINO.
If you are looking for a JavaScript debugger in NetBeans, take a look at project Phobos.
Posted at 09:13AM Feb 10, 2007 by Christopher Webster in Java | Comments[1]
Saturday Feb 10, 2007
Posted by ludo on February 10, 2007 at 11:40 AM PST #