--- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java 2016-03-18 11:22:27.410479397 +0100 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java 2016-03-18 11:22:27.310479401 +0100 @@ -97,6 +97,7 @@ final class Lower extends NodeOperatorVisitor implements Loggable { private final DebugLogger log; + private final boolean es6; // Conservative pattern to test if element names consist of characters valid for identifiers. // This matches any non-zero length alphanumeric string including _ and $ and not starting with a digit. @@ -144,6 +145,7 @@ }); this.log = initLogger(compiler.getContext()); + this.es6 = compiler.getScriptEnvironment()._es6; } @Override @@ -257,8 +259,9 @@ } newForNode = checkEscape(newForNode); - if(newForNode.isForIn()) { - // Wrap it in a block so its internally created iterator is restricted in scope + if(!es6 && newForNode.isForIn()) { + // Wrap it in a block so its internally created iterator is restricted in scope, unless we are running + // in ES6 mode, in which case the parser already created a block to capture let/const declarations. addStatementEnclosedInBlock(newForNode); } else { addStatement(newForNode);