diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index d71d3455b..f034f4cc7 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -446,11 +446,12 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext debugEmitter.emitMethod(method.getReference().getDescriptor()); MethodReference ref = method.getReference(); writer.append(",").newLine(); + String methodName = method.isAsync() ? naming.getNameForAsync(ref) : naming.getNameFor(ref); if (method.isOriginalNamePreserved()) { - writer.append("[\"").appendMethod(ref).append("\",").ws().append("\"").append(ref.getName()) + writer.append("[\"").append(methodName).append("\",").ws().append("\"").append(ref.getName()) .append("\"]"); } else { - writer.append("\"").appendMethod(ref).append("\""); + writer.append("\"").append(methodName).append("\""); } writer.append(",").ws().append("function("); for (int i = 1; i <= ref.parameterCount(); ++i) { diff --git a/teavm-core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java b/teavm-core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java index 719a1a842..7a3a10504 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java +++ b/teavm-core/src/main/java/org/teavm/javascript/UnusedVariableEliminator.java @@ -227,5 +227,8 @@ class UnusedVariableEliminator implements ExprVisitor, StatementVisitor { @Override public void visit(RestoreAsyncStatement statement) { + if (statement.getReceiver() != null) { + statement.setReceiver(renumber(statement.getReceiver())); + } } } diff --git a/teavm-core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java b/teavm-core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java index 4c07b28bd..abfd73398 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java +++ b/teavm-core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java @@ -85,5 +85,38 @@ public class AsyncMethodFinder { for (CallSite callSite : node.getCallerCallSites()) { add(callSite.getCaller().getMethod()); } + Set visited = new HashSet<>(); + Set overriden = new HashSet<>(); + if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) { + findOverridenMethods(new MethodReference(cls.getParent(), methodRef.getDescriptor()), overriden, visited); + } + for (String iface : cls.getInterfaces()) { + findOverridenMethods(new MethodReference(iface, methodRef.getDescriptor()), overriden, visited); + } + for (MethodReference overridenMethod : overriden) { + add(overridenMethod); + } + } + + private void findOverridenMethods(MethodReference methodRef, Set result, + Set visited) { + if (!visited.add(methodRef)) { + return; + } + ClassReader cls = classSource.get(methodRef.getClassName()); + if (cls == null) { + return; + } + MethodReader method = cls.getMethod(methodRef.getDescriptor()); + if (method != null) { + result.add(methodRef); + } else { + if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) { + findOverridenMethods(new MethodReference(cls.getParent(), methodRef.getDescriptor()), result, visited); + } + for (String iface : cls.getInterfaces()) { + findOverridenMethods(new MethodReference(iface, methodRef.getDescriptor()), result, visited); + } + } } }