crafterm 2002/12/07 13:53:57
Modified: src/java/org/apache/cocoon/components/flow flow.xconf
src/java/org/apache/cocoon/components/flow/javascript
JavaScriptInterpreter.java
Log:
Added support for using the Rhino JavaScript debugger with Cocoon
flowscript.
To use the debugger, add the following commented line to your
flow.xconf/cocoon.xconf:
<component-instance name="JavaScript"
class="org.apache.cocoon.components.flow.javascript.JavaScriptInterpreter">
<load-on-startup>resource://org/apache/cocoon/components/flow/javascript/system.js</load-on-startup>
<reload-scripts>true</reload-scripts>
<check-time>4000</check-time>
<debugger>enabled</debugger> <!-- this line enables the flow debugger -->
</component-instance>
When the <debugger/> element is present, all threads that create a javascript
interpreter will operate via a Rhino visual debugger instance.
Revision Changes Path
1.4 +1 -0
xml-cocoon2/src/java/org/apache/cocoon/components/flow/flow.xconf
Index: flow.xconf
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/flow.xconf,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- flow.xconf 6 Dec 2002 18:20:15 -0000 1.3
+++ flow.xconf 7 Dec 2002 21:53:57 -0000 1.4
@@ -48,6 +48,7 @@
<load-on-startup>resource://org/apache/cocoon/components/flow/javascript/system.js</load-on-startup>
<reload-scripts>true</reload-scripts>
<check-time>4000</check-time>
+ <!-- <debugger>enabled</debugger> --> <!-- JavaScript Debugger support -->
</component-instance>
<!--
1.11 +68 -11
xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java
Index: JavaScriptInterpreter.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JavaScriptInterpreter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JavaScriptInterpreter.java 1 Oct 2002 07:30:43 -0000 1.10
+++ JavaScriptInterpreter.java 7 Dec 2002 21:53:57 -0000 1.11
@@ -73,11 +73,13 @@
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.tools.debugger.ScopeProvider;
/**
* Interface with the JavaScript interpreter.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @since March 25, 2002
*/
public class JavaScriptInterpreter extends AbstractInterpreter
@@ -103,6 +105,8 @@
JSGlobal scope;
Script compiledScript;
JSErrorReporter errorReporter;
+ boolean enableDebugger = false;
+ org.mozilla.javascript.tools.debugger.Main debugger;
public void configure(Configuration config)
throws ConfigurationException
@@ -111,13 +115,39 @@
String loadOnStartup
= config.getChild("load-on-startup", true).getValue(null);
- if (loadOnStartup != null)
+ if (loadOnStartup != null) {
register(loadOnStartup);
+ }
+
+ String debugger
+ = config.getChild("debugger").getValue(null);
+ if ("enabled".equalsIgnoreCase(debugger)) {
+ enableDebugger = true;
+ }
}
public void initialize()
throws Exception
{
+ if (enableDebugger) {
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Flow debugger enabled, creating");
+ }
+
+ final org.mozilla.javascript.tools.debugger.Main db
+ = new org.mozilla.javascript.tools.debugger.Main("Cocoon Flow Debugger");
+ db.pack();
+ db.setSize(600,460);
+ db.setExitAction(
+ new Runnable() { public void run() { db.setVisible(false); } }
+ );
+ db.setVisible(true);
+
+ debugger = db;
+ Context.addContextListener(debugger);
+ }
+
Context context = Context.enter();
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
@@ -152,7 +182,6 @@
Scriptable log = context.newObject(scope, "Log", args);
((JSLog)log).enableLogging(getLogger());
scope.put("log", scope, log);
-
}
catch (Exception e) {
context.exit();
@@ -177,14 +206,16 @@
Request request = ObjectModelHelper.getRequest(objectModel);
Session session = request.getSession(false);
- if (session == null)
+ if (session == null) {
return null;
+ }
Scriptable scope;
HashMap userScopes = (HashMap)session.getAttribute(USER_GLOBAL_SCOPE);
- if (userScopes == null)
+ if (userScopes == null) {
return null;
+ }
scope = (Scriptable)userScopes.get(environment.getURIPrefix());
@@ -248,6 +279,7 @@
throws Exception
{
Context context = Context.enter();
+ context.setGeneratingDebug(true);
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
context.setCompileFunctionsWithDynamicScope(true);
context.setErrorReporter(errorReporter);
@@ -285,11 +317,12 @@
((JSCocoon)cocoon).setScope(thrScope);
thrScope.put("cocoon", thrScope, cocoon);
- if (compiledScript != null)
+ if (compiledScript != null) {
compiledScript.exec(context, thrScope);
- }
- else
+ }
+ } else {
cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
+ }
// We need to setup the JSCocoon object according to the current
// request. Everything else remains the same.
@@ -315,7 +348,9 @@
{
Scriptable thrScope = null;
- System.out.println("Reading scripts");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Reading scripts");
+ }
try {
thrScope = enterContext(environment);
@@ -424,9 +459,19 @@
try {
thrScope = enterContext(environment);
Context context = Context.getCurrentContext();
-
JSCocoon cocoon = (JSCocoon)thrScope.get("cocoon", thrScope);
+ if (enableDebugger) {
+ final Scriptable s = thrScope;
+ debugger.setScopeProvider(
+ new ScopeProvider()
+ { public Scriptable getScope() {return s;} }
+ );
+ debugger.doBreak();
+ if (!debugger.isVisible())
+ debugger.setVisible(true);
+ }
+
Object callFunction = thrScope.get("callFunction", thrScope);
if (callFunction == Scriptable.NOT_FOUND)
throw new RuntimeException("Cannot find 'callFunction' "
@@ -457,6 +502,7 @@
}
catch (Exception ex) {
ex.printStackTrace();
+ throw ex;
}
finally {
exitContext(thrScope);
@@ -473,6 +519,7 @@
throw new RuntimeException("No continuation with id " + id);
Context context = Context.enter();
+ context.setGeneratingDebug(true);
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
context.setCompileFunctionsWithDynamicScope(true);
@@ -482,7 +529,17 @@
JSWebContinuation jswk = (JSWebContinuation)wk.getUserObject();
JSCocoon cocoon = jswk.getJSCocoon();
cocoon.setContext(manager, environment);
- Scriptable kScope = cocoon.getScope();
+ final Scriptable kScope = cocoon.getScope();
+
+ if (enableDebugger) {
+ debugger.setScopeProvider(
+ new ScopeProvider()
+ { public Scriptable getScope() {return kScope;} }
+ );
+ debugger.doBreak();
+ if (!debugger.isVisible())
+ debugger.setVisible(true);
+ }
// We can now resume the processing from the state saved by the
// continuation object. Setup the JavaScript Context object.
@@ -508,7 +565,7 @@
try {
((Function)handleContFunction).call(context, kScope, kScope, args);
}
- catch (Exception ex) {
+ catch (final Exception ex) {
ex.printStackTrace();
throw ex;
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]