< 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 !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;
     }
 

@@ -183,10 +190,27 @@
      * @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-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
      * @return true if this is a for each construct
      */

@@ -281,8 +305,8 @@
      *
      * @see Block#providesScopeCreator()
      * @return true if the containing block's scope object creator is required in codegen
      */
     public boolean needsScopeCreator() {
-        return isForIn() && hasPerIterationScope();
+        return isForInOrOf() && hasPerIterationScope();
     }
 }
< prev index next >