Add support for rhino debugger (merge from helma_1_4)

This commit is contained in:
hns 2005-03-11 15:41:35 +00:00
parent 1f84ed41ac
commit 2373d63719
2 changed files with 36 additions and 6 deletions

View file

@ -27,6 +27,8 @@ import helma.util.CacheMap;
import helma.util.SystemMap;
import helma.util.WrappedMap;
import org.mozilla.javascript.*;
import org.mozilla.javascript.tools.debugger.Main;
import org.mozilla.javascript.tools.debugger.ScopeProvider;
import java.io.*;
import java.text.*;
@ -35,7 +37,7 @@ import java.util.*;
/**
* This is the implementation of ScriptingEnvironment for the Mozilla Rhino EcmaScript interpreter.
*/
public final class RhinoCore {
public final class RhinoCore implements ScopeProvider {
// the application we're running in
public final Application app;
@ -63,6 +65,8 @@ public final class RhinoCore {
// Any error that may have been found in global code
String globalError;
Main debugger = null;
/**
* Create a Rhino evaluator for the given application and request evaluator.
*/
@ -80,14 +84,24 @@ public final class RhinoCore {
wrapper.setJavaPrimitiveWrap(false);
context.setWrapFactory(wrapper);
int optLevel = 0;
// Set up visual debugger if rhino.debug = true
if ("true".equals(app.getProperty("rhino.debug"))) {
debugger = new Main(app.getName() + " Debugger");
debugger.setScopeProvider(this);
debugger.pack();
debugger.setVisible(true);
debugger.contextCreated(context);
debugger.contextEntered(context);
}
// Set default optimization level according to whether debugger is on
int optLevel = debugger == null ? 0 : -1;
try {
optLevel = Integer.parseInt(app.getProperty("rhino.optlevel"));
} catch (Exception ignore) {
}
// System.err.println("Setting Rhino optlevel to " + optLevel);
context.setOptimizationLevel(optLevel);
try {
@ -131,6 +145,11 @@ public final class RhinoCore {
throw new RuntimeException(e.getMessage());
} finally {
Context.exit();
if (debugger != null) {
debugger.contextExited(context);
debugger.contextReleased(context);
}
}
}

View file

@ -154,13 +154,18 @@ public class RhinoEngine implements ScriptingEngine {
context.setApplicationClassLoader(app.getClassLoader());
context.setWrapFactory(core.wrapper);
boolean trace = "true".equals(app.getProperty("rhino.trace"));
// if visual debugger is on let it know we're entering a context
if (core.debugger != null) {
core.debugger.contextCreated(context);
core.debugger.contextEntered(context);
}
if (trace) {
if ("true".equals(app.getProperty("rhino.trace"))) {
context.setDebugger(new Tracer(getResponse()), null);
}
int optLevel = 0;
// Set default optimization level according to whether debugger is on
int optLevel = core.debugger == null ? 0 : -1;
try {
optLevel = Integer.parseInt(app.getProperty("rhino.optlevel"));
@ -224,6 +229,12 @@ public class RhinoEngine implements ScriptingEngine {
core.global.unregisterScope();
thread = null;
// if visual debugger is on let it know we're exiting a context
if (core.debugger != null) {
core.debugger.contextExited(context);
core.debugger.contextReleased(context);
}
// loop through previous globals and unset them, if necessary.
if (lastGlobals != null) {
for (Iterator i=lastGlobals.keySet().iterator(); i.hasNext(); ) {