Avoid generation of too deeply nested expressions to fit into v8 parser stack

This commit is contained in:
Alexey Andreev 2018-08-27 22:08:03 +03:00
parent 174ac9e725
commit 365e47882a

View File

@ -64,6 +64,7 @@ import org.teavm.ast.WhileStatement;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
class OptimizingVisitor implements StatementVisitor, ExprVisitor { class OptimizingVisitor implements StatementVisitor, ExprVisitor {
private static final int MAX_DEPTH = 20;
private Expr resultExpr; private Expr resultExpr;
Statement resultStmt; Statement resultStmt;
private final boolean[] preservedVars; private final boolean[] preservedVars;
@ -286,6 +287,9 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor {
return; return;
} }
if (locationStack.size() > MAX_DEPTH) {
return;
}
if (readFrequencies[index] != 1 || preservedVars[index]) { if (readFrequencies[index] != 1 || preservedVars[index]) {
return; return;
} }