Fix ecma_3/ExecutionContexts/10.1.3.js

r=rogerl
This commit is contained in:
norris%netscape.com 2000-01-20 20:59:56 +00:00
Родитель 563b315d04
Коммит ef65d489ce
4 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -503,14 +503,25 @@ public class NodeTransformer {
// OPT: a whole pass to collect variables seems expensive.
// Could special case to go into statements only.
PreorderNodeIterator iterator = tree.getPreorderIterator();
Hashtable ht = null;
Node node;
while ((node = iterator.nextNode()) != null) {
if (node.getType() != TokenStream.VAR)
int nodeType = node.getType();
if (nodeType == TokenStream.FUNCTION) {
// In a function with both "var x" and "function x",
// disregard the var statement, independent of order.
vars.removeLocal(node.getString());
if (ht == null)
ht = new Hashtable();
ht.put(node.getString(), Boolean.TRUE);
}
if (nodeType != TokenStream.VAR)
continue;
ShallowNodeIterator i = node.getChildIterator();
while (i.hasMoreElements()) {
Node n = i.nextNode();
vars.addLocal(n.getString());
if (ht == null || ht.get(n.getString()) == null)
vars.addLocal(n.getString());
}
}
}

Просмотреть файл

@ -130,6 +130,17 @@ public class VariableTable {
itsVariableNames.put(vName, new Integer(index));
}
// This should only be called very early in compilation
public void removeLocal(String name) {
for (int i=0; i < itsVariables.size(); i++) {
LocalVariable v = (LocalVariable) itsVariables.elementAt(i);
if (v.getName().equals(name)) {
itsVariables.removeElementAt(i);
return;
}
}
}
// a list of the formal parameters and local variables
protected Vector itsVariables = new Vector();

Просмотреть файл

@ -503,14 +503,25 @@ public class NodeTransformer {
// OPT: a whole pass to collect variables seems expensive.
// Could special case to go into statements only.
PreorderNodeIterator iterator = tree.getPreorderIterator();
Hashtable ht = null;
Node node;
while ((node = iterator.nextNode()) != null) {
if (node.getType() != TokenStream.VAR)
int nodeType = node.getType();
if (nodeType == TokenStream.FUNCTION) {
// In a function with both "var x" and "function x",
// disregard the var statement, independent of order.
vars.removeLocal(node.getString());
if (ht == null)
ht = new Hashtable();
ht.put(node.getString(), Boolean.TRUE);
}
if (nodeType != TokenStream.VAR)
continue;
ShallowNodeIterator i = node.getChildIterator();
while (i.hasMoreElements()) {
Node n = i.nextNode();
vars.addLocal(n.getString());
if (ht == null || ht.get(n.getString()) == null)
vars.addLocal(n.getString());
}
}
}

Просмотреть файл

@ -130,6 +130,17 @@ public class VariableTable {
itsVariableNames.put(vName, new Integer(index));
}
// This should only be called very early in compilation
public void removeLocal(String name) {
for (int i=0; i < itsVariables.size(); i++) {
LocalVariable v = (LocalVariable) itsVariables.elementAt(i);
if (v.getName().equals(name)) {
itsVariables.removeElementAt(i);
return;
}
}
}
// a list of the formal parameters and local variables
protected Vector itsVariables = new Vector();