# HG changeset patch # User Jaroslav Tulach # Date 1461820380 -7200 # Node ID aa2e9630b6d5c9deaf5a38b541a830c0a602e124 # Parent 85f1fbb0f2f646b304a21b068f0047cdf2057327 Convert content of array properly before entering JavaScript diff -r 85f1fbb0f2f6 -r aa2e9630b6d5 rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java --- a/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java Thu Apr 28 06:21:04 2016 +0200 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotations.java Thu Apr 28 07:13:00 2016 +0200 @@ -99,4 +99,9 @@ + "return b ? 'yes' : 'no';\n" ) public static native String yesNo(Callable call); + + @JavaScriptBody(args = { "arr", "val" }, body = + "return arr[0] === val;" + ) + public static native boolean compareArr(Object[] arr, Object val); } diff -r 85f1fbb0f2f6 -r aa2e9630b6d5 rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java --- a/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Thu Apr 28 06:21:04 2016 +0200 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/HtmlAnnotationsTest.java Thu Apr 28 07:13:00 2016 +0200 @@ -106,6 +106,13 @@ }); assertEquals(no, "no", "FALSE is false"); } + + @BrwsrTest + public void compareArrayOfDoubles() throws Exception { + Double val = 2.2; + boolean res = HtmlAnnotations.compareArr(new Object[] { val }, val); + assertEquals(res, true, "Should be in the array"); + } private static void assertEquals(double real, double exp) { if (real - exp < 0.01) { diff -r 85f1fbb0f2f6 -r aa2e9630b6d5 rt/emul/mini/src/main/java/java/lang/Class.java --- a/rt/emul/mini/src/main/java/java/lang/Class.java Thu Apr 28 06:21:04 2016 +0200 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Thu Apr 28 07:13:00 2016 +0200 @@ -1870,10 +1870,10 @@ ) static native Object clone(Object self) throws CloneNotSupportedException; - @JavaScriptOnly(name = "toJS", value = "function(v) {\n" + @JavaScriptOnly(name = "toJS", value = "function convToJS(v) {\n" + " if (v === null) return null;\n" + " if (Object.prototype.toString.call(v) === '[object Array]') {\n" - + " return vm.org_apidesign_bck2brwsr_emul_lang_System(false).convArray__Ljava_lang_Object_2Ljava_lang_Object_2(v);\n" + + " return vm.org_apidesign_bck2brwsr_emul_lang_System(false).convArray__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2(v, convToJS);\n" + " }\n" + " if (v instanceof Date) return v;\n" + " return v.valueOf();\n" diff -r 85f1fbb0f2f6 -r aa2e9630b6d5 rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Thu Apr 28 06:21:04 2016 +0200 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java Thu Apr 28 07:13:00 2016 +0200 @@ -84,15 +84,17 @@ public void close() throws IOException { } }; + @JavaScriptBody(args = { "fn", "p" }, body = "return fn(p);") + private static native Object invoke(Object fn, Object p); @Exported - private static Object convArray(Object o) { + private static Object convArray(Object o, Object convToJS) { if (o instanceof Object[]) { Object[] arr = (Object[]) o; final int l = arr.length; Object[] ret = new Object[l]; for (int i = 0; i < l; i++) { - ret[i] = convArray(arr[i]); + ret[i] = invoke(convToJS, arr[i]); } return ret; }