Skip to content

Commit

Permalink
Merge pull request #69 from pixilation/fix-clobbered-e-variable
Browse files Browse the repository at this point in the history
Fix 'e' variable being clobbered by watch exception
  • Loading branch information
softwareCobbler authored Jan 8, 2025
2 parents 099a38a + 9588c4d commit 6c015f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
+ "<cfscript>"
+ "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 } }"
+ "</cfscript>";
}

Expand Down
17 changes: 16 additions & 1 deletion luceedebug/src/test/java/luceedebug/EvaluatesAnExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/docker/app1/a.cfm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<cfscript>
function foo(n) {
var e = "bar";
return n;
}
Expand Down

0 comments on commit 6c015f5

Please sign in to comment.