From b7d760188eec5047f00d096988a074e54c8c36e1 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 3 Dec 2016 14:30:43 +0300 Subject: [PATCH] When native method returns `undefined` and Java expects string, produce `null`. Add `$` prefix to local variables to avoid name clashing with global declarations --- .../java/org/teavm/backend/javascript/rendering/Renderer.java | 2 +- .../teavm/backend/javascript/rendering/StatementRenderer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java index 670c15c6e..390824005 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java @@ -182,7 +182,7 @@ public class Renderer implements RenderingManager { private void renderRuntimeString() throws IOException { MethodReference stringCons = new MethodReference(String.class, "", char[].class, void.class); writer.append("function $rt_str(str) {").indent().softNewLine(); - writer.append("if (str===null){").indent().softNewLine(); + writer.append("if (str == null) {").indent().softNewLine(); writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("var characters = $rt_createCharArray(str.length);").softNewLine(); diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java index 0925e8ae0..c3fc58b11 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java @@ -458,7 +458,7 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { ? currentMethod.getVariables().get(index) : null; if (variable != null && variable.getName() != null) { - String result = RenderingUtil.escapeName(variable.getName()); + String result = "$" + RenderingUtil.escapeName(variable.getName()); if (keywords.contains(result) || !usedVariableNames.add(result)) { String base = result; int suffix = 0;