Fixes bugs related to stepping

This commit is contained in:
Alexey Andreev 2014-08-24 16:02:21 +04:00
parent 6272c3a79a
commit 97e107635b
2 changed files with 34 additions and 12 deletions

View File

@ -108,18 +108,8 @@ public class Debugger {
if (callSiteLoc != null) { if (callSiteLoc != null) {
callMethod = debugInfo.getCallSite(callSiteLoc); callMethod = debugInfo.getCallSite(callSiteLoc);
} }
SourceLocation[] following = debugInfo.getFollowingLines(frame.getLocation()); exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet<SourceLocation>(),
if (following != null) { successors);
for (SourceLocation successor : following) {
if (successor == null) {
exits = true;
} else {
for (GeneratedLocation loc : debugInfo.getGeneratedLocations(successor)) {
successors.add(new JavaScriptLocation(script, loc.getLine(), loc.getColumn()));
}
}
}
}
if (enterMethod && callMethod != null) { if (enterMethod && callMethod != null) {
for (MethodReference potentialMethod : debugInfo.getOverridingMethods(callMethod)) { for (MethodReference potentialMethod : debugInfo.getOverridingMethods(callMethod)) {
for (GeneratedLocation loc : debugInfo.getMethodEntrances(potentialMethod)) { for (GeneratedLocation loc : debugInfo.getMethodEntrances(potentialMethod)) {
@ -140,6 +130,32 @@ public class Debugger {
javaScriptDebugger.resume(); javaScriptDebugger.resume();
} }
private boolean addFollowing(DebugInformation debugInfo, SourceLocation location, String script,
Set<SourceLocation> visited, Set<JavaScriptLocation> successors) {
if (!visited.add(location)) {
return false;
}
SourceLocation[] following = debugInfo.getFollowingLines(location);
boolean exits = false;
if (following != null) {
for (SourceLocation successor : following) {
if (successor == null) {
exits = true;
} else {
Collection<GeneratedLocation> genLocations = debugInfo.getGeneratedLocations(successor);
if (!genLocations.isEmpty()) {
for (GeneratedLocation loc : genLocations) {
successors.add(new JavaScriptLocation(script, loc.getLine(), loc.getColumn()));
}
} else {
exits |= addFollowing(debugInfo, successor, script, visited, successors);
}
}
}
}
return exits;
}
private List<DebugInformation> debugInformationBySource(String sourceFile) { private List<DebugInformation> debugInformationBySource(String sourceFile) {
Map<DebugInformation, Object> list = debugInformationFileMap.get(sourceFile); Map<DebugInformation, Object> list = debugInformationFileMap.get(sourceFile);
return list != null ? new ArrayList<>(list.keySet()) : Collections.<DebugInformation>emptyList(); return list != null ? new ArrayList<>(list.keySet()) : Collections.<DebugInformation>emptyList();

View File

@ -631,9 +631,15 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
public void visit(ConditionalStatement statement) { public void visit(ConditionalStatement statement) {
try { try {
while (true) { while (true) {
if (statement.getCondition().getLocation() != null) {
pushLocation(statement.getCondition().getLocation());
}
writer.append("if").ws().append("("); writer.append("if").ws().append("(");
statement.getCondition().acceptVisitor(this); statement.getCondition().acceptVisitor(this);
writer.append(")").ws().append("{").softNewLine().indent(); writer.append(")").ws().append("{").softNewLine().indent();
if (statement.getCondition().getLocation() != null) {
popLocation();
}
for (Statement part : statement.getConsequent()) { for (Statement part : statement.getConsequent()) {
part.acceptVisitor(this); part.acceptVisitor(this);
} }