diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index f0e702957..48b91b2ae 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -77,7 +77,6 @@ class JSClassProcessor { private final List replacement = new ArrayList<>(); private final JSTypeHelper typeHelper; private final Diagnostics diagnostics; - private int methodIndexGenerator; private final Map overriddenMethodCache = new HashMap<>(); private JSValueMarshaller marshaller; private IncrementalDependencyRegistration incrementalCache; @@ -576,9 +575,12 @@ class JSClassProcessor { ? ValueType.VOID : ValueType.parse(JSObject.class); + ClassReader ownerClass = classSource.get(methodToProcess.getOwnerName()); + int methodIndex = indexOfMethod(ownerClass, methodToProcess); + // create proxy method MethodReference proxyMethod = new MethodReference(methodToProcess.getOwnerName(), - methodToProcess.getName() + "$js_body$_" + methodIndexGenerator++, proxyParamTypes); + methodToProcess.getName() + "$js_body$_" + methodIndex, proxyParamTypes); String script = bodyAnnot.getValue("script").getString(); String[] parameterNames = paramsValue != null ? paramsValue.getList().stream() .map(AnnotationValue::getString) @@ -617,6 +619,17 @@ class JSClassProcessor { } } + private int indexOfMethod(ClassReader cls, MethodReader method) { + int index = 0; + for (MethodReader m : cls.getMethods()) { + if (m.getDescriptor().equals(method.getDescriptor())) { + return index; + } + ++index; + } + return -1; + } + void createJSMethods(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { MethodReference methodRef = method.getReference();