< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/ForNode.java

Print this page

        

*** 49,60 **** public static final int IS_FOR_IN = 1 << 0; /** Is this a normal for each in loop? */ public static final int IS_FOR_EACH = 1 << 1; /** Does this loop need a per-iteration scope because its init contain a LET declaration? */ ! public static final int PER_ITERATION_SCOPE = 1 << 2; private final int flags; /** * Constructs a ForNode --- 49,63 ---- public static final int IS_FOR_IN = 1 << 0; /** 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 << 3; private final int flags; /** * Constructs a ForNode
*** 125,134 **** --- 128,141 ---- if (isForIn()) { 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); } sb.append("; ");
*** 144,159 **** sb.append(')'); } @Override public boolean hasGoto() { ! return !isForIn() && test == null; } @Override public boolean mustEnter() { ! if (isForIn()) { return false; //may be an empty set to iterate over, then we skip the loop } return test == null; } --- 151,166 ---- sb.append(')'); } @Override public boolean hasGoto() { ! return !isForIn() && !isForOf() && test == null; } @Override public boolean mustEnter() { ! if (isForIn() || isForOf()) { return false; //may be an empty set to iterate over, then we skip the loop } return test == null; }
*** 183,192 **** --- 190,208 ---- * @return true if this is a for in constructor */ 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 each construct, known from e.g. Rhino. This will be a for of construct * in ECMAScript 6 * @return true if this is a for each construct */
*** 280,287 **** * per-iteration scope. This is only true for for-in loops with lexical declarations. * * @return true if the containing block's scope object creator is required in codegen */ public boolean needsScopeCreator() { ! return isForIn() && hasPerIterationScope(); } } --- 296,303 ---- * per-iteration scope. This is only true for for-in loops with lexical declarations. * * @return true if the containing block's scope object creator is required in codegen */ public boolean needsScopeCreator() { ! return (isForIn() || isForOf()) && hasPerIterationScope(); } }
< prev index next >