From f085dbb6073c11c9e080ed3b94845cfc8c241ace Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Fri, 14 Feb 2014 16:42:45 +0400 Subject: [PATCH] Fixes array item propagation --- .../html4j/JavaScriptBodyDependency.java | 21 ++++++++++++++++--- .../html4j/test/JavaScriptBodyTests.java | 7 +++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java index 2006a3ff6..5d747f5e4 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java @@ -30,6 +30,18 @@ public class JavaScriptBodyDependency implements DependencyListener { public void started(DependencyChecker dependencyChecker) { allClassesNode = dependencyChecker.createNode(); allClassesNode.setTag("JavaScriptBody:global"); + allClassesNode.getArrayItem().addConsumer(new OneDirectionalConnection(allClassesNode)); + allClassesNode.getArrayItem().getArrayItem().addConsumer(new OneDirectionalConnection(allClassesNode)); + } + + private static class OneDirectionalConnection implements DependencyConsumer { + private DependencyNode target; + public OneDirectionalConnection( DependencyNode target) { + this.target = target; + } + @Override public void consume(String type) { + target.propagate(type); + } } @Override @@ -47,12 +59,15 @@ public class JavaScriptBodyDependency implements DependencyListener { MethodGraph graph = dependencyChecker.attachMethodGraph(methodRef); if (graph.getResult() != null) { allClassesNode.connect(graph.getResult()); + allClassesNode.addConsumer(new OneDirectionalConnection(graph.getResult().getArrayItem())); + allClassesNode.addConsumer(new OneDirectionalConnection(graph.getResult().getArrayItem() + .getArrayItem())); } for (int i = 0; i < graph.getParameterCount(); ++i) { graph.getVariable(i).connect(allClassesNode); - allClassesNode.getArrayItem().connect(graph.getVariable(i).getArrayItem()); - allClassesNode.getArrayItem().getArrayItem().connect(graph.getVariable(i) - .getArrayItem().getArrayItem()); + allClassesNode.addConsumer(new OneDirectionalConnection(graph.getVariable(i).getArrayItem())); + allClassesNode.addConsumer(new OneDirectionalConnection(graph.getVariable(i).getArrayItem() + .getArrayItem())); } if (javacall != null && javacall.getBoolean()) { String body = annot.getValue("body").getString(); diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java index 318546c63..f3b4ae335 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyTests.java @@ -44,6 +44,13 @@ public class JavaScriptBodyTests { @Test public void dependencyPropagatedThroughArray() { + storeObject(new Object[] { new AImpl() }); + A[] array = (A[])retrieveObject(); + assertEquals(23, array[0].foo()); + } + + @Test + public void dependencyPropagatedBackThroughArray() { A[] first = new A[1]; storeObject(first); Object[] second = (Object[])retrieveObject();