From fb3412b4c047982382d80b63461238e0319b1b16 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 21 Oct 2015 21:56:08 +0300 Subject: [PATCH] Fix generation of JS aliases for Java objects --- .../org/teavm/jso/impl/JSAliasRenderer.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java index 8a5e7f097..9e5931e54 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java @@ -57,8 +57,12 @@ class JSAliasRenderer implements RendererListener { } writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;").softNewLine(); for (Map.Entry aliasEntry : cls.methods.entrySet()) { - writer.append("c.").append(aliasEntry.getValue()).ws().append("=").ws().append("c.") - .appendMethod(aliasEntry.getKey()).append(";").softNewLine(); + if (isKeyword(aliasEntry.getValue())) { + writer.append("c[\"").append(aliasEntry.getValue()).append("\"]"); + } else { + writer.append("c.").append(aliasEntry.getValue()); + } + writer.ws().append("=").ws().append("c.").appendMethod(aliasEntry.getKey()).append(";").softNewLine(); } if (cls.functorField != null) { @@ -68,6 +72,25 @@ class JSAliasRenderer implements RendererListener { writer.outdent().append("})();").newLine(); } + private boolean isKeyword(String id) { + switch (id) { + case "with": + case "delete": + case "in": + case "undefined": + case "debugger": + case "export": + case "function": + case "let": + case "var": + case "typeof": + case "yield": + return true; + default: + return false; + } + } + private void writeFunctor(ExposedClass cls) throws IOException { String alias = cls.methods.get(cls.functorMethod); if (alias == null) {