diff --git a/common/src/main/java/dev/latvian/mods/rhino/Kit.java b/common/src/main/java/dev/latvian/mods/rhino/Kit.java index 7baf90c3..3d33ae5f 100644 --- a/common/src/main/java/dev/latvian/mods/rhino/Kit.java +++ b/common/src/main/java/dev/latvian/mods/rhino/Kit.java @@ -389,4 +389,11 @@ public static RuntimeException codeBug(String msg) throws RuntimeException { ex.printStackTrace(System.err); throw ex; } + + /** + * useful for lambda -> iterable + */ + public static Iterable iterable(Iterable itrProvider) { + return itrProvider; + } } diff --git a/common/src/main/java/dev/latvian/mods/rhino/NodeTransformer.java b/common/src/main/java/dev/latvian/mods/rhino/NodeTransformer.java index 83f1a5bb..b509500c 100644 --- a/common/src/main/java/dev/latvian/mods/rhino/NodeTransformer.java +++ b/common/src/main/java/dev/latvian/mods/rhino/NodeTransformer.java @@ -158,14 +158,13 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent break; // skip the whole mess. } Node unwindBlock = null; - for (val n : loops.reversed()) { + for (val n : Kit.iterable(loops::descendingIterator)) { val elemtype = n.getType(); if (elemtype == Token.TRY || elemtype == Token.WITH) { Node unwind; if (elemtype == Token.TRY) { val jsrNode = new Jump(Token.JSR); - val jsrTarget = ((Jump) n).getFinally(); - jsrNode.target = jsrTarget; + jsrNode.target = ((Jump) n).getFinally(); unwind = jsrNode; } else { unwind = new Node(Token.LEAVEWITH); @@ -178,12 +177,12 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent } if (unwindBlock != null) { Node returnNode = node; - Node returnExpr = returnNode.getFirstChild(); + val returnExpr = returnNode.getFirstChild(); node = replaceCurrent(parent, previous, node, unwindBlock); if (returnExpr == null || isGenerator) { unwindBlock.addChildToBack(returnNode); } else { - Node store = new Node(Token.EXPR_RESULT, returnExpr); + val store = new Node(Token.EXPR_RESULT, returnExpr); unwindBlock.addChildToFront(store); returnNode = new Node(Token.RETURN_RESULT); unwindBlock.addChildToBack(returnNode); @@ -198,8 +197,8 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent case Token.BREAK: case Token.CONTINUE: { - Jump jump = (Jump) node; - Jump jumpStatement = jump.getJumpStatement(); + val jump = (Jump) node; + val jumpStatement = jump.getJumpStatement(); if (jumpStatement == null) { Kit.codeBug(); } @@ -210,12 +209,12 @@ private void transformCompilationUnit_r(final ScriptNode tree, final Node parent // which should be found throw Kit.codeBug(); } - for (Node n : loops.reversed()) { + for (val n : Kit.iterable(loops::descendingIterator)) { if (n == jumpStatement) { break; } - int elemtype = n.getType(); + val elemtype = n.getType(); if (elemtype == Token.WITH) { Node leave = new Node(Token.LEAVEWITH); previous = addBeforeCurrent(parent, previous, node, leave);