< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java
Print this page
@@ -3318,12 +3318,14 @@
final Symbol identSymbol = identNode.getSymbol();
assert identSymbol != null : "variable node " + varNode + " requires a name with a symbol";
final boolean needsScope = identSymbol.isScope();
if (init == null) {
- if (needsScope && varNode.isBlockScoped()) {
- // block scoped variables need a DECLARE flag to signal end of temporal dead zone (TDZ)
+ // Block-scoped variables need a DECLARE flag to signal end of temporal dead zone (TDZ).
+ // However, don't do this for CONST which always has an initializer except in the special case of
+ // for-in/of loops, in which it is initialized in the loop header and should be left untouched here.
+ if (needsScope && varNode.isLet()) {
method.loadCompilerConstant(SCOPE);
method.loadUndefined(Type.OBJECT);
final int flags = getScopeCallSiteFlags(identSymbol) | (varNode.isBlockScoped() ? CALLSITE_DECLARE : 0);
assert isFastScope(identSymbol);
storeFastScopeVar(identSymbol, flags);
< prev index next >