When native method returns undefined and Java expects string, produce null. Add $ prefix to local variables to avoid name clashing with global declarations

This commit is contained in:
Alexey Andreev 2016-12-03 14:30:43 +03:00
parent f96aa54461
commit b7d760188e
2 changed files with 2 additions and 2 deletions

View File

@ -182,7 +182,7 @@ public class Renderer implements RenderingManager {
private void renderRuntimeString() throws IOException {
MethodReference stringCons = new MethodReference(String.class, "<init>", 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();

View File

@ -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;