From 365e47882a65b9dc040bc466aa6463b87e4c87b2 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 27 Aug 2018 22:08:03 +0300 Subject: [PATCH] Avoid generation of too deeply nested expressions to fit into v8 parser stack --- .../java/org/teavm/ast/optimization/OptimizingVisitor.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java index 70fae9542..280617112 100644 --- a/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java +++ b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java @@ -64,6 +64,7 @@ import org.teavm.ast.WhileStatement; import org.teavm.model.TextLocation; class OptimizingVisitor implements StatementVisitor, ExprVisitor { + private static final int MAX_DEPTH = 20; private Expr resultExpr; Statement resultStmt; private final boolean[] preservedVars; @@ -286,6 +287,9 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor { return; } + if (locationStack.size() > MAX_DEPTH) { + return; + } if (readFrequencies[index] != 1 || preservedVars[index]) { return; }