src/jdk/nashorn/internal/codegen/CodeGenerator.java

Print this page

        

@@ -3262,10 +3262,17 @@
         body.accept(this);
         if(repeatLabel != continueLabel) {
             emitContinueLabel(continueLabel, liveLocalsOnContinue);
         }
 
+        if (loopNode.hasPerIterationScope() && lc.getParentBlock().needsScope()) {
+            // ES6 for loops with LET init need a new scope for each iteration. We just create a shallow copy here.
+            method.loadCompilerConstant(SCOPE);
+            method.invoke(virtualCallNoLookup(ScriptObject.class, "copy", ScriptObject.class));
+            method.storeCompilerConstant(SCOPE);
+        }
+
         if(method.isReachable()) {
             if(modify != null) {
                 lineNumber(loopNode);
                 loadAndDiscard(modify);
                 method.beforeJoinPoint(modify);