From 8286ad9289e0e07cee1d3591373af6d68759baaa Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sat, 22 Mar 2014 23:25:51 +0400 Subject: [PATCH] Adds problem with closure variables when generating JSO bridge functions --- .../main/java/org/teavm/jso/JSNativeGenerator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java index 6b0ca2aee..00f5cc1a2 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java @@ -137,14 +137,14 @@ public class JSNativeGenerator implements Generator, Injector, DependencyPlugin private void generateFunction(InjectorContext context) throws IOException { SourceWriter writer = context.getWriter(); - writer.append("(function()").ws().append("{").indent().softNewLine(); - writer.append("return "); + writer.append("(function($instance, $property) { return function()").ws().append("{").indent().softNewLine(); + writer.append("return $property.apply($instance, arguments);").softNewLine(); + writer.outdent().append("};})("); + context.writeExpr(context.getArgument(0)); + writer.append(", "); context.writeExpr(context.getArgument(0)); renderProperty(context.getArgument(1), context); - writer.append(".apply("); - context.writeExpr(context.getArgument(0)); - writer.append(",").ws().append("arguments);").softNewLine(); - writer.outdent().append("})"); + writer.append(")"); } private void renderProperty(Expr property, InjectorContext context) throws IOException {