Improving the coverage of the JavaScriptBody annotation compatibility tests.
1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/Bodies.java Thu Aug 28 14:16:08 2014 +0200
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java Sun Aug 31 10:05:01 2014 +0200
1.3 @@ -52,13 +52,18 @@
1.4 final class Bodies {
1.5 @JavaScriptBody(args = { "a", "b" }, body = "return a + b;")
1.6 public static native int sum(int a, int b);
1.7 +
1.8 + @JavaScriptBody(args = { "a", "b" }, javacall = true, body =
1.9 + "return @net.java.html.js.tests.Bodies::sum(II)(a, b);"
1.10 + )
1.11 + public static native int sumJS(int a, int b);
1.12
1.13 @JavaScriptBody(args = {"r"}, javacall = true, body = "r.@java.lang.Runnable::run()();")
1.14 static native void callback(Runnable r);
1.15
1.16 @JavaScriptBody(args = {"r"}, wait4js = false, javacall = true, body = "r.@java.lang.Runnable::run()();")
1.17 static native void asyncCallback(Runnable r);
1.18 -
1.19 +
1.20 @JavaScriptBody(args = {"c"}, javacall = true, body = "return c.@java.util.concurrent.Callable::call()();")
1.21 static native Object callback(Callable<? extends Object> c);
1.22
1.23 @@ -74,6 +79,9 @@
1.24 @JavaScriptBody(args = "o", body = "o.x++;")
1.25 public static native void incrementX(Object o);
1.26
1.27 + @JavaScriptBody(args = "o", wait4js = true, body = "o.x++;")
1.28 + static native void incrementXAsync(Object o);
1.29 +
1.30 @JavaScriptBody(args = "o", body = "return o.x;")
1.31 public static native int readX(Object o);
1.32
1.33 @@ -136,4 +144,22 @@
1.34 "return sum;\n"
1.35 )
1.36 public static native double sumMatrix(double[][] arr);
1.37 +
1.38 + static void incCounter(int howMuch, final Object js) {
1.39 + for (int i = 0; i < howMuch; i++) {
1.40 + asyncCallback(new Runnable() {
1.41 + @Override
1.42 + public void run() {
1.43 + incrementXAsync(js);
1.44 + }
1.45 + });
1.46 + }
1.47 + }
1.48 +
1.49 + @JavaScriptBody(args = {}, javacall = true, body =
1.50 + "var v = { x : 0 };\n" +
1.51 + "@net.java.html.js.tests.Bodies::incCounter(ILjava/lang/Object;)(42, v);\n" +
1.52 + "return v.x;\n"
1.53 + )
1.54 + static native int incAsync();
1.55 }
2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Thu Aug 28 14:16:08 2014 +0200
2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Sun Aug 31 10:05:01 2014 +0200
2.3 @@ -57,6 +57,11 @@
2.4 int res = Bodies.sum(5, 3);
2.5 assert res == 8 : "Expecting 8: " + res;
2.6 }
2.7 +
2.8 + @KOTest public void sumFromCallback() {
2.9 + int res = Bodies.sumJS(5, 3);
2.10 + assert res == 8 : "Expecting 8: " + res;
2.11 + }
2.12
2.13 @KOTest public void accessJsObject() {
2.14 Object o = Bodies.instance(10);
2.15 @@ -319,6 +324,11 @@
2.16 assert r == 42 : "Expecting 42: " + r;
2.17 }
2.18
2.19 + @KOTest public void asyncCallFromAJSCallbackNeedToFinishBeforeReturnToJS() {
2.20 + int r = Bodies.incAsync();
2.21 + assert r == 42 : "Expecting 42: " + r;
2.22 + }
2.23 +
2.24 Later l;
2.25 @KOTest public void callLater() throws Exception{
2.26 final Fn.Presenter p = Fn.activePresenter();