atom feed6 messages in eval() + debug in JavaScript inte...
FromSent OnAttachments
Andrew MickishAug 28, 2007 1:01 pm 
Roberto ChinniciAug 29, 2007 12:41 pm 
Andrew MickishSep 13, 2007 2:14 pm 
Ludovic ChampenoisSep 13, 2007 2:32 pm 
Roberto ChinniciSep 13, 2007 2:40 pm 
Andrew MickishSep 20, 2007 7:17 am 
Subject:Re: eval() + debug in JavaScript interpreter
From:Roberto Chinnici (Robe@Sun.COM)
Date:Aug 29, 2007 12:41:56 pm

I think the answer is yes, but there are a few things than may need to be disentangled first.

Let me explain how the Phobos debugger works.

We don't use Rhino out of the JDK. Instead, we take a Mozilla Rhino release and add our own JSR-223 scripting engine to it.

The constructor of the factory class for the engine (com.sun.phobos.script.javascript.RhinoScriptEngineFactory) takes as argument a Rhino org.mozilla.javascript.ContextFactory.Listener. When the Phobos container starts up, if debugging is enabled it passes a context listener object which calls back into the Phobos debugger embedded in the container (com.sun.phobos.container.debug.DebuggerImpl).

The debugger translates Rhino events (which have a number of drawbacks I won't get into here) into its own kind of events and exposes them through a listener interface (com.sun.phobos.debug.DebuggerListener). This interface is implemented by the NetBeans portion of the Phobos debugger so taht debug events can drive the debugger UI in NetBeans.

In theory, it is possible to perform all these steps from NetBeans without instantiating a Phobos container. The only catch is that currently the DebuggerImpl class requires a Phobos container to be present. I imagine it'd be possible to come up with a minimal DebuggerImpl that does not depend on the rest of the container, then use it to run single scripts in debug mode.

As for the eval() function, it's part of the standard JSR-223 ScriptEngine interface so the Phobos JSR-223 engine for Rhino supports it.


Andrew Mickish wrote:

Please help me understand if I can leverage the Phobos JavaScript interpreter and debugger as a platform for some tools I am building.

My goal is a main Java application with an embedded JavaScript interpreter that supports JavaScript debugging. Users of my application should be able to type in moderately complicated algorithms expressed in JavaScript, which I evaluate for side-effects and return values. You could consider these user-defined algorithms as 'customizations' of the main Java application.

One strategy is to invoke the standard Rhino Debugger's eval() method. But a better approach would be to add my own 'customizable' high-level tools as NetBeans plug-ins, cooperating with an embedded debuggable JavaScript interpreter.

Is it possible to explicitly call 'eval' in Phobos (like JDK 1.6 ScriptEngine.eval())?

For example, in the context of NetBeans, suppose I select (highlight) some JavaScript code that I composed in a NetBeans editor window, then right-click and select 'eval'. I would like to see the debugger suspend execution at the first line of the code, and let me step through it.

Maybe this hypothetical right-click-eval feature could be written as a plug-in, or something unique to my NetBeans installation. But what is the API it calls?

I do not necessarily need to eval my JavaScript expressions in a web browser, just a JavaScript interpreter that supports a debugging interface.

Stand-alone Rhino comes with a debugger that is meant to execute whole JavaScript files. I made some preliminary modifications, and got it to step through evaluations of my expressions without loading files.

But the NetBeans debugging environment is more powerful and polished than the Rhino debugger, and it would be great if I could piggy-back on JavaScript-in-NetBeans instead of develop my own debugger.

Thanks for your advice,