diff --git a/luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java b/luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java index 962c7cc..43f7261 100644 --- a/luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java +++ b/luceedebug/src/main/java/luceedebug/coreinject/ExprEvaluator.java @@ -43,12 +43,13 @@ static abstract class Evaluator { // At this time, `lucee.runtime.compiler.Renderer.loadPage` will // cache compilations based on the hash of the source text; so, using the same result name // every time ensures we don't need to recompile a particular expression every time. + static protected final String errName = "__luceedebug__error"; static protected final String resultName = "__luceedebug__evalResult"; static protected String getEvaluatableSourceText(String expr) { return "" + "" + "try { variables['" + resultName + "'] = {'ok': true, 'result': " + expr + " } }" - + "catch (any e) { variables['" + resultName + "'] = {'ok': false, 'result': e.message } }" + + "catch (any " + errName + ") { variables['" + resultName + "'] = {'ok': false, 'result': " + errName + ".message } }" + ""; } diff --git a/luceedebug/src/test/java/luceedebug/EvaluatesAnExpression.java b/luceedebug/src/test/java/luceedebug/EvaluatesAnExpression.java index 611ea9f..a89d58f 100644 --- a/luceedebug/src/test/java/luceedebug/EvaluatesAnExpression.java +++ b/luceedebug/src/test/java/luceedebug/EvaluatesAnExpression.java @@ -66,7 +66,7 @@ void a(LuceeAndDockerInfo dockerInfo) throws Throwable { DapUtils.attach(dapServer).join(); DapUtils - .setBreakpoints(dapServer, "/var/www/a.cfm", 3) + .setBreakpoints(dapServer, "/var/www/a.cfm", 4) .join(); final var requestThreadToBeBlockedByBreakpoint = new java.lang.Thread(() -> { @@ -104,6 +104,21 @@ void a(LuceeAndDockerInfo dockerInfo) throws Throwable { "evaluation result as expected" ); + assertEquals( + "\"bar\"", + DapUtils.evaluate(dapServer, frameID, "e").join().getResult(), + "e is initialized to \"bar\"" + ); + + // An expression that will throw an exception, should not clobber "e" in the local scope + DapUtils.evaluate(dapServer, frameID, "zzz"); + + assertEquals( + "\"bar\"", + DapUtils.evaluate(dapServer, frameID, "e").join().getResult(), + "e is still \"bar\"" + ); + DapUtils.continue_(dapServer, threadID); requestThreadToBeBlockedByBreakpoint.join(); diff --git a/test/docker/app1/a.cfm b/test/docker/app1/a.cfm index 783c303..aa86045 100644 --- a/test/docker/app1/a.cfm +++ b/test/docker/app1/a.cfm @@ -1,5 +1,6 @@ function foo(n) { + var e = "bar"; return n; }