--- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/ForNode.java 2016-03-24 10:55:24.176784126 +0100 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/ForNode.java 2016-03-24 10:55:24.016784132 +0100 @@ -51,8 +51,11 @@ /** Is this a normal for each in loop? */ public static final int IS_FOR_EACH = 1 << 1; + /** Is this a ES6 for-of loop? */ + public static final int IS_FOR_OF = 1 << 2; + /** Does this loop need a per-iteration scope because its init contain a LET declaration? */ - public static final int PER_ITERATION_SCOPE = 1 << 2; + public static final int PER_ITERATION_SCOPE = 1 << 3; private final int flags; @@ -127,6 +130,10 @@ init.toString(sb, printTypes); sb.append(" in "); modify.toString(sb, printTypes); + } else if (isForOf()) { + init.toString(sb, printTypes); + sb.append(" of "); + modify.toString(sb, printTypes); } else { if (init != null) { init.toString(sb, printTypes); @@ -146,12 +153,12 @@ @Override public boolean hasGoto() { - return !isForIn() && test == null; + return !isForInOrOf() && test == null; } @Override public boolean mustEnter() { - if (isForIn()) { + if (isForInOrOf()) { return false; //may be an empty set to iterate over, then we skip the loop } return test == null; @@ -185,6 +192,23 @@ public boolean isForIn() { return (flags & IS_FOR_IN) != 0; } + + /** + * Is this a for-of loop? + * @return true if this is a for-of loop + */ + public boolean isForOf() { + return (flags & IS_FOR_OF) != 0; + } + + /** + * Is this a for-in or for-of statement? + * @return true if this is a for-in or for-of loop + */ + public boolean isForInOrOf() { + return isForIn() || isForOf(); + } + /** * Is this a for each construct, known from e.g. Rhino. This will be a for of construct * in ECMAScript 6 @@ -283,6 +307,6 @@ * @return true if the containing block's scope object creator is required in codegen */ public boolean needsScopeCreator() { - return isForIn() && hasPerIterationScope(); + return isForInOrOf() && hasPerIterationScope(); } }