From e5c85dd3bd3eaa254db87225db0901b779ee02e1 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 16 Nov 2018 19:04:15 +0300 Subject: [PATCH] Prevent inlining of JSBody code in some complex cases --- .../main/java/org/teavm/jso/impl/JSBodyInlineUtil.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java index ee07a8641..206d1fef8 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSBodyInlineUtil.java @@ -44,7 +44,7 @@ final class JSBodyInlineUtil { ComplexityCounter complexityCounter = new ComplexityCounter(); expression.visit(complexityCounter); - if (complexityCounter.getComplexity() > COMPLEXITY_THRESHOLD) { + if (complexityCounter.hasUnsupportedConstructs || complexityCounter.getComplexity() > COMPLEXITY_THRESHOLD) { return null; } @@ -86,6 +86,7 @@ final class JSBodyInlineUtil { static class ComplexityCounter implements NodeVisitor { private int complexity; + boolean hasUnsupportedConstructs; public int getComplexity() { return complexity; @@ -94,6 +95,13 @@ final class JSBodyInlineUtil { @Override public boolean visit(AstNode node) { ++complexity; + switch (node.getType()) { + case Token.FUNCTION: + case Token.OBJECTLIT: + case Token.ARRAYLIT: + hasUnsupportedConstructs = true; + break; + } return true; } }