< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/ForNode.java
Print this page
@@ -49,12 +49,15 @@
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 << 2;
+ public static final int PER_ITERATION_SCOPE = 1 << 3;
private final int flags;
/**
* Constructs a ForNode
@@ -125,10 +128,14 @@
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,16 +151,16 @@
sb.append(')');
}
@Override
public boolean hasGoto() {
- return !isForIn() && test == null;
+ return !isForIn() && !isForOf() && test == null;
}
@Override
public boolean mustEnter() {
- if (isForIn()) {
+ if (isForIn() || isForOf()) {
return false; //may be an empty set to iterate over, then we skip the loop
}
return test == null;
}
@@ -183,10 +190,19 @@
* @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,8 +296,8 @@
* 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();
+ return (isForIn() || isForOf()) && hasPerIterationScope();
}
}
< prev index next >