From 2f2985bb100d68cb6ba8ed1468c5a3f307f98486 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 27 Mar 2014 15:48:34 +0400 Subject: [PATCH] Removes inlining of variable's values into && and || expression, as it sometimes can violate evaluation order. Fixes creation of arrays of arrays of primitives. --- .../main/java/org/teavm/javascript/OptimizingVisitor.java | 8 ++++++++ .../src/main/java/org/teavm/javascript/Renderer.java | 3 --- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/javascript/OptimizingVisitor.java b/teavm-core/src/main/java/org/teavm/javascript/OptimizingVisitor.java index f1dfa0009..de5bf6203 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/OptimizingVisitor.java +++ b/teavm-core/src/main/java/org/teavm/javascript/OptimizingVisitor.java @@ -45,6 +45,14 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor { @Override public void visit(BinaryExpr expr) { + switch (expr.getOperation()) { + case AND: + case OR: + resultExpr = expr; + return; + default: + break; + } expr.getSecondOperand().acceptVisitor(this); Expr b = resultExpr; expr.getFirstOperand().acceptVisitor(this); diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index eb34438d9..8f1901fa0 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -1149,9 +1149,6 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext public void visit(NewArrayExpr expr) { try { ValueType type = expr.getType(); - while (type instanceof ValueType.Array) { - type = ((ValueType.Array)type).getItemType(); - } if (type instanceof ValueType.Primitive) { switch (((ValueType.Primitive)type).getKind()) { case BOOLEAN: