diff --git a/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java b/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java index 2ec035ff5..b4b49d7fc 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java +++ b/teavm-core/src/main/java/org/teavm/javascript/JavascriptNativeProcessor.java @@ -282,7 +282,7 @@ class JavascriptNativeProcessor { } String name = type.getMethods().iterator().next().getName(); Variable functor = program.createVariable(); - Variable nameVar = addString(name); + Variable nameVar = addStringWrap(addString(name)); InvokeInstruction insn = new InvokeInstruction(); insn.setMethod(new MethodReference(JS.class.getName(), new MethodDescriptor("function", ValueType.object(JSObject.class.getName()), ValueType.object(JSObject.class.getName()), @@ -290,6 +290,7 @@ class JavascriptNativeProcessor { insn.setReceiver(functor); insn.getArguments().add(var); insn.getArguments().add(nameVar); + replacement.add(insn); return functor; } diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JS.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JS.java index d2612de18..916794a3b 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ni/JS.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JS.java @@ -190,5 +190,6 @@ public final class JS { public static native void set(JSObject instance, JSObject index, JSObject obj); @InjectedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) public static native JSObject function(JSObject instance, JSObject property); } diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/JSNativeGenerator.java b/teavm-core/src/main/java/org/teavm/javascript/ni/JSNativeGenerator.java index ca7fba5d4..69a76dc4c 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ni/JSNativeGenerator.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/JSNativeGenerator.java @@ -132,10 +132,10 @@ public class JSNativeGenerator implements Generator, Injector, DependencyPlugin SourceWriter writer = context.getWriter(); writer.append("(function()").ws().append("{").indent().softNewLine(); writer.append("return "); - context.writeExpr(context.getArgument(1)); - renderProperty(context.getArgument(2), context); + context.writeExpr(context.getArgument(0)); + renderProperty(context.getArgument(1), context); writer.append(".apply("); - context.writeExpr(context.getArgument(1)); + context.writeExpr(context.getArgument(0)); writer.append(",").ws().append("arguments);").softNewLine(); writer.outdent().append("})"); }