From 11f270e3ef6ec2ee1c28f83361e14f11ba98e937 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 9 Dec 2014 16:42:26 +0400 Subject: [PATCH] Fix https://github.com/konsoletyper/teavm/issues/39 --- teavm-jso/pom.xml | 41 +++++++++++++++++++ .../java/org/teavm/jso/JSNativeGenerator.java | 4 +- .../test/java/org/teavm/jso/test/JSOTest.java | 21 ++++++++++ .../test/java/org/teavm/jso/test/RegExp.java | 13 ++++++ .../test/java/org/teavm/jso/test/Window.java | 13 ++++++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java create mode 100644 teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java create mode 100644 teavm-jso/src/test/java/org/teavm/jso/test/Window.java diff --git a/teavm-jso/pom.xml b/teavm-jso/pom.xml index 5e7e7a986..a42c91397 100644 --- a/teavm-jso/pom.xml +++ b/teavm-jso/pom.xml @@ -34,10 +34,51 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs ${project.version} true + + junit + junit + test + + + org.teavm + teavm-maven-plugin + ${project.version} + + + org.teavm + teavm-classlib + ${project.version} + + + + + generate-javascript-tests + + build-test-javascript + + process-test-classes + + false + + en, en_US, en_GB, ru, ru_RU + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ** + + + org.apache.maven.plugins maven-checkstyle-plugin 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 2e049a44c..9720fb7a6 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java +++ b/teavm-jso/src/main/java/org/teavm/jso/JSNativeGenerator.java @@ -74,10 +74,10 @@ public class JSNativeGenerator implements Injector, DependencyPlugin { writer.append(')'); break; case "instantiate": - writer.append("(new "); + writer.append("(new ("); context.writeExpr(context.getArgument(0)); renderProperty(context.getArgument(1), context); - writer.append('('); + writer.append(")("); for (int i = 2; i < context.argumentCount(); ++i) { if (i > 2) { writer.append(',').ws(); diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java b/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java new file mode 100644 index 000000000..7627d393a --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/JSOTest.java @@ -0,0 +1,21 @@ +package org.teavm.jso.test; + +import static org.junit.Assert.*; +import org.junit.Test; +import org.teavm.jso.JS; + +/** + * + * @author Alexey Andreev + */ +public class JSOTest { + @Test + public void complexConstructorParenthesized() { + RegExp regexp = getWindow().createRegExp("."); + assertEquals(".", regexp.getSource()); + } + + private static Window getWindow() { + return (Window)JS.getGlobal(); + } +} diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java b/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java new file mode 100644 index 000000000..4ce204f9e --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/RegExp.java @@ -0,0 +1,13 @@ +package org.teavm.jso.test; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface RegExp extends JSObject { + @JSProperty + String getSource(); +} diff --git a/teavm-jso/src/test/java/org/teavm/jso/test/Window.java b/teavm-jso/src/test/java/org/teavm/jso/test/Window.java new file mode 100644 index 000000000..04d3bb6a1 --- /dev/null +++ b/teavm-jso/src/test/java/org/teavm/jso/test/Window.java @@ -0,0 +1,13 @@ +package org.teavm.jso.test; + +import org.teavm.jso.JSConstructor; +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface Window extends JSObject { + @JSConstructor("RegExp") + RegExp createRegExp(String regex); +}