fix the scoping problem: variables in an outer scope were not included in the stack

This commit is contained in:
Shu Lei
2007-11-07 20:11:55 +00:00
parent 3bf2fc2958
commit 2281d056ec

View File

@@ -477,8 +477,12 @@ public class DebugStackState extends StackState implements DebugRequestListener
Vector variables = new Vector(); Vector variables = new Vector();
Hashtable variablesSeen = new Hashtable(); Hashtable variablesSeen = new Hashtable();
addVariables(variables, variablesSeen, index); Proto p = calls[index].closure.p;
for (int i = index; i >= 0; i--) {
if (i == index || isInScope(p, calls[i])) {
addVariables(variables, variablesSeen, i);
}
}
Variable[] result = new Variable[variables.size()]; Variable[] result = new Variable[variables.size()];
for (int i = 0; i < variables.size(); i++) { for (int i = 0; i < variables.size(); i++) {
result[i] = (Variable) variables.elementAt(i); result[i] = (Variable) variables.elementAt(i);
@@ -487,6 +491,19 @@ public class DebugStackState extends StackState implements DebugRequestListener
return result; return result;
} }
protected boolean isInScope(Proto p, CallInfo ci) {
Proto[] enclosingProtos = ci.closure.p.p;
boolean bFound = false;
for (int i = 0; enclosingProtos!= null && i < enclosingProtos.length; i++) {
if (enclosingProtos[i] == p) {
bFound = true;
break;
}
}
return bFound;
}
/** /**
* Returns the visible globals to the current VM. * Returns the visible globals to the current VM.
* @return the visible globals. * @return the visible globals.