diff --git a/js/rhino/src/org/mozilla/javascript/Context.java b/js/rhino/src/org/mozilla/javascript/Context.java index 4ceee11ce3ac..727daa2f029c 100644 --- a/js/rhino/src/org/mozilla/javascript/Context.java +++ b/js/rhino/src/org/mozilla/javascript/Context.java @@ -1899,7 +1899,7 @@ public class Context { tree = compiler.transform(this, irf, tree); - if (printTrees) { System.out.println(tree.toStringTree()); } + if (printTrees) { System.out.println(tree.toStringTree(tree)); } if (returnFunction) { int functionCount = tree.getFunctionCount(); diff --git a/js/rhino/src/org/mozilla/javascript/Node.java b/js/rhino/src/org/mozilla/javascript/Node.java index a0ca4a69e59b..b8ef6dcc6807 100644 --- a/js/rhino/src/org/mozilla/javascript/Node.java +++ b/js/rhino/src/org/mozilla/javascript/Node.java @@ -507,33 +507,36 @@ public class Node implements Cloneable { return null; } - public String toStringTree() { - return toStringTreeHelper(0); + public String toStringTree(ScriptOrFnNode treeTop) { + if (Context.printTrees) { + StringBuffer sb = new StringBuffer(); + toStringTreeHelper(treeTop, this, 0, sb); + return sb.toString(); + } + return null; } - - private String toStringTreeHelper(int level) { + private static void toStringTreeHelper(ScriptOrFnNode treeTop, Node n, + int level, StringBuffer sb) + { if (Context.printTrees) { - StringBuffer s = new StringBuffer(); - for (int i=0; i < level; i++) { - s.append(" "); + for (int i = 0; i != level; ++i) { + sb.append(" "); } - s.append(toString()); - s.append('\n'); - for (Node cursor = getFirstChild(); cursor != null; + sb.append(n.toString()); + sb.append('\n'); + for (Node cursor = n.getFirstChild(); cursor != null; cursor = cursor.getNext()) { - Node n = cursor; if (cursor.getType() == TokenStream.FUNCTION) { - Node p = (Node) cursor.getProp(Node.FUNCTION_PROP); - if (p != null) - n = p; + int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP); + FunctionNode fn = treeTop.getFunctionNode(fnIndex); + toStringTreeHelper(fn, fn, level + 1, sb); + } else { + toStringTreeHelper(treeTop, cursor, level + 1, sb); } - s.append(n.toStringTreeHelper(level+1)); } - return s.toString(); } - return ""; } int type; // type of the node; TokenStream.NAME for example