From 50686c882db6e202ad2dd16df5fb417eeb85af45 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 30 Sep 2014 18:13:45 +0400 Subject: [PATCH] Add fix for dependency issue when invoking callback from native JS --- teavm-jso/src/main/java/org/teavm/jso/JS.java | 1 + .../java/org/teavm/jso/JSNativeGenerator.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/teavm-jso/src/main/java/org/teavm/jso/JS.java b/teavm-jso/src/main/java/org/teavm/jso/JS.java index 3a500c537..84f97f8f1 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JS.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JS.java @@ -117,6 +117,7 @@ public final class JS { public static native double unwrapDouble(JSObject obj); @GeneratedBy(JSNativeGenerator.class) + @PluggableDependency(JSNativeGenerator.class) public static native String unwrapString(JSObject obj); @InjectedBy(JSNativeGenerator.class) 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 dc2a77392..9aec63dbe 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java @@ -116,12 +116,20 @@ public class JSNativeGenerator implements Generator, Injector, DependencyPlugin @Override public void methodAchieved(final DependencyAgent agent, final MethodDependency method) { - for (int i = 0; i < method.getReference().parameterCount(); ++i) { - method.getVariable(i).addConsumer(new DependencyConsumer() { - @Override public void consume(DependencyAgentType type) { - achieveFunctorMethods(agent, type.getName(), method); + switch (method.getReference().getName()) { + case "invoke": + case "instantiate": + for (int i = 0; i < method.getReference().parameterCount(); ++i) { + method.getVariable(i).addConsumer(new DependencyConsumer() { + @Override public void consume(DependencyAgentType type) { + achieveFunctorMethods(agent, type.getName(), method); + } + }); } - }); + break; + case "unwrapString": + method.getResult().propagate(agent.getType("java.lang.String")); + break; } }