< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java

Print this page

        

@@ -1759,11 +1759,11 @@
     public boolean enterForNode(final ForNode forNode) {
         if(!method.isReachable()) {
             return false;
         }
         enterStatement(forNode);
-        if (forNode.isForIn()) {
+        if (forNode.isForIn() || forNode.isForOf()) {
             enterForIn(forNode);
         } else {
             final Expression init = forNode.getInit();
             if (init != null) {
                 loadAndDiscard(init);

@@ -1774,11 +1774,19 @@
         return false;
     }
 
     private void enterForIn(final ForNode forNode) {
         loadExpression(forNode.getModify(), TypeBounds.OBJECT);
-        method.invoke(forNode.isForEach() ? ScriptRuntime.TO_VALUE_ITERATOR : ScriptRuntime.TO_PROPERTY_ITERATOR);
+        if (forNode.isForEach()) {
+            method.invoke(ScriptRuntime.TO_VALUE_ITERATOR);
+        } else if (forNode.isForIn()) {
+            method.invoke(ScriptRuntime.TO_PROPERTY_ITERATOR);
+        } else if (forNode.isForOf()) {
+            method.invoke(ScriptRuntime.TO_ES6_ITERATOR);
+        } else {
+            throw new IllegalArgumentException("Unexpected for node");
+        }
         final Symbol iterSymbol = forNode.getIterator();
         final int iterSlot = iterSymbol.getSlot(Type.OBJECT);
         method.store(iterSymbol, ITERATOR_TYPE);
 
         method.beforeJoinPoint(forNode);

@@ -3324,11 +3332,11 @@
             // 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);
+                final int flags = getScopeCallSiteFlags(identSymbol) | CALLSITE_DECLARE;
                 assert isFastScope(identSymbol);
                 storeFastScopeVar(identSymbol, flags);
             }
             return false;
         }
< prev index next >