Fixes issue with JSFunctor-annotated classes

This commit is contained in:
konsoletyper 2014-02-10 12:43:23 +04:00
parent 67bc76f89a
commit 8055edd547
3 changed files with 6 additions and 4 deletions

View File

@ -282,7 +282,7 @@ class JavascriptNativeProcessor {
} }
String name = type.getMethods().iterator().next().getName(); String name = type.getMethods().iterator().next().getName();
Variable functor = program.createVariable(); Variable functor = program.createVariable();
Variable nameVar = addString(name); Variable nameVar = addStringWrap(addString(name));
InvokeInstruction insn = new InvokeInstruction(); InvokeInstruction insn = new InvokeInstruction();
insn.setMethod(new MethodReference(JS.class.getName(), new MethodDescriptor("function", insn.setMethod(new MethodReference(JS.class.getName(), new MethodDescriptor("function",
ValueType.object(JSObject.class.getName()), ValueType.object(JSObject.class.getName()), ValueType.object(JSObject.class.getName()), ValueType.object(JSObject.class.getName()),
@ -290,6 +290,7 @@ class JavascriptNativeProcessor {
insn.setReceiver(functor); insn.setReceiver(functor);
insn.getArguments().add(var); insn.getArguments().add(var);
insn.getArguments().add(nameVar); insn.getArguments().add(nameVar);
replacement.add(insn);
return functor; return functor;
} }

View File

@ -190,5 +190,6 @@ public final class JS {
public static native void set(JSObject instance, JSObject index, JSObject obj); public static native void set(JSObject instance, JSObject index, JSObject obj);
@InjectedBy(JSNativeGenerator.class) @InjectedBy(JSNativeGenerator.class)
@PluggableDependency(JSNativeGenerator.class)
public static native JSObject function(JSObject instance, JSObject property); public static native JSObject function(JSObject instance, JSObject property);
} }

View File

@ -132,10 +132,10 @@ public class JSNativeGenerator implements Generator, Injector, DependencyPlugin
SourceWriter writer = context.getWriter(); SourceWriter writer = context.getWriter();
writer.append("(function()").ws().append("{").indent().softNewLine(); writer.append("(function()").ws().append("{").indent().softNewLine();
writer.append("return "); writer.append("return ");
context.writeExpr(context.getArgument(1)); context.writeExpr(context.getArgument(0));
renderProperty(context.getArgument(2), context); renderProperty(context.getArgument(1), context);
writer.append(".apply("); writer.append(".apply(");
context.writeExpr(context.getArgument(1)); context.writeExpr(context.getArgument(0));
writer.append(",").ws().append("arguments);").softNewLine(); writer.append(",").ws().append("arguments);").softNewLine();
writer.outdent().append("})"); writer.outdent().append("})");
} }