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.  


 


Comments:

Cool... A complete NetBeans 5.5.x JavaScript debugger for server side javascript is available on the Phobos project: https://phobos.dev.java.net This includes local variables, stack trace, threads, breakpoints, sessions, tooltip on the javascript editor and watches (with some expression evaluation). If you know how to use the JavaDebugger in NetBeans, then you know how to use it for JavaScript in a Phobos environment... Ludo

Posted by ludo on February 10, 2007 at 03:40 AM PST #

Post a Comment:
Comments are closed for this entry.
About

cwebster

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today