- * This is useful during debugging a test so that you can step execute and inspect state of JavaScript. - * This will launch a Swing GUI, and the method returns immediately. - * - *
- * Note that installing a debugger appears to make an execution of JavaScript substantially slower. - */ - public Dim interactiveJavaScriptDebugger() { - // this can be too late, depending on when this method is invoked. - Functions.DEBUG_YUI = true; - - // TODO: port this back later -// return net.sourceforge.htmlunit.corejs.javascript.tools.debugger.Main.mainEmbedded("Rhino debugger: "+getName()); - return null; - } - /** * Returns the last item in the list. */ @@ -1222,6 +1184,18 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { return e.getURI().contains("/yui/"); } }); + + // if no other debugger is installed, install jsDebugger, + // so as not to interfere with the 'Dim' class. + getJavaScriptEngine().getContextFactory().addListener(new Listener() { + public void contextCreated(Context cx) { + if (cx.getDebugger() == null) + cx.setDebugger(jsDebugger, null); + } + + public void contextReleased(Context cx) { + } + }); } /** @@ -1389,6 +1363,38 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { cea.add(id,requestHandler); return goTo("closures/?uuid="+id); } + + /** + * Starts an interactive JavaScript debugger, and break at the next JavaScript execution. + * + *
+ * This is useful during debugging a test so that you can step execute and inspect state of JavaScript. + * This will launch a Swing GUI, and the method returns immediately. + * + *
+ * Note that installing a debugger appears to make an execution of JavaScript substantially slower. + * + *
+ * TODO: because each script block evaluation in HtmlUnit is done in a separate Rhino context, + * if you step over from one script block, the debugger fails to kick in on the beginning of the next script block. + * This makes it difficult to set a break point on arbitrary script block in the HTML page. We need to fix this + * by tweaking {@link Dim.StackFrame#onLineChange(Context, int)}. + */ + public Dim interactiveJavaScriptDebugger() { + // this can be too late, depending on when this method is invoked. + Functions.DEBUG_YUI = true; + + Global global = new Global(); + HtmlUnitContextFactory cf = getJavaScriptEngine().getContextFactory(); + global.init(cf); + + Dim dim = org.mozilla.javascript.tools.debugger.Main.mainEmbedded(cf, global, "Rhino debugger: " + getName()); + + // break on exceptions. this catch most of the errors + dim.setBreakOnExceptions(true); + + return dim; + } } // needs to keep reference, or it gets GC-ed.