Fix bugs in JSBody

This commit is contained in:
Alexey Andreev 2015-04-01 18:28:31 +04:00
parent 4adf789142
commit b8fa0a541a
2 changed files with 6 additions and 9 deletions

View File

@ -15,10 +15,7 @@
*/
package org.teavm.jso;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**
*
@ -26,5 +23,6 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface JSFunctor {
}

View File

@ -36,16 +36,15 @@ public class JSBodyGenerator implements Generator {
List<AnnotationValue> paramNames = annot.getValue("params").getList();
int bodyParamCount = isStatic ? method.parameterCount() : method.parameterCount() - 1;
int offset = isStatic ? 1 : 0;
writer.append("if (!").appendMethodBody(methodRef).append(".$native)").ws().append('{').indent().newLine();
writer.appendMethodBody(methodRef).append(".$native").ws().append('=').ws().append("function(");
int count = method.parameterCount() + (isStatic ? 0 : 1);
int count = method.parameterCount();
for (int i = 0; i < count; ++i) {
if (i > 0) {
writer.append(',').ws();
}
writer.append('_').append(context.getParameterName(i + offset));
writer.append('_').append(context.getParameterName(i + 1));
}
writer.append(')').ws().append('{').softNewLine().indent();
@ -68,7 +67,7 @@ public class JSBodyGenerator implements Generator {
if (i > 0) {
writer.append(',').ws();
}
writer.append('_').append(context.getParameterName(i + offset));
writer.append('_').append(context.getParameterName(i + 1));
}
writer.append(");").softNewLine();
writer.outdent().append("};").softNewLine();
@ -81,7 +80,7 @@ public class JSBodyGenerator implements Generator {
if (i > 0) {
writer.append(',').ws();
}
writer.append(context.getParameterName(i + offset));
writer.append(context.getParameterName(i + 1));
}
writer.append(");").softNewLine();
}