src/jdk/nashorn/internal/ir/ForNode.java

Print this page

        

@@ -43,18 +43,18 @@
     private final JoinPredecessorExpression modify;
 
     /** Iterator symbol. */
     private Symbol iterator;
 
-    /** Is this a normal for loop? */
-    public static final int IS_FOR      = 1 << 0;
-
     /** Is this a normal for in loop? */
-    public static final int IS_FOR_IN   = 1 << 1;
+    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 << 2;
+    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;
 
     /**
      * Constructor

@@ -271,6 +271,20 @@
 
     @Override
     JoinPredecessor setLocalVariableConversionChanged(final LexicalContext lc, final LocalVariableConversion conversion) {
         return Node.replaceInLexicalContext(lc, this, new ForNode(this, init, test, body, modify, flags, controlFlowEscapes, conversion));
     }
+
+    @Override
+    public boolean hasPerIterationScope() {
+        return (flags & PER_ITERATION_SCOPE) != 0;
+    }
+
+    /**
+     * Set the per-iteration-scope flag on this node.
+     * @param lc lexical context
+     * @return the node with flag set
+     */
+    public ForNode setPerIterationScope(final LexicalContext lc) {
+        return setFlags(lc, flags | PER_ITERATION_SCOPE);
+    }
 }