From 75a7b213e05c4a74e187b2b5bdab423a90494c10 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 18 Feb 2014 09:36:40 +0400 Subject: [PATCH] Adds test of array conversion while passing to the JavaScriptBody --- .../test/JavaScriptBodyConversionTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java index 96167b4c8..a31e4b237 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/JavaScriptBodyConversionTests.java @@ -34,9 +34,28 @@ public class JavaScriptBodyConversionTests { assertEquals(23, returnAsObject(23)); } + @Test + public void convertsArray() { + assertEquals(42, getArrayItem(new Integer[] { 23, 42 }, 1)); + } + + @Test + public void copiesArray() { + Integer[] array = { 23, 42 }; + Integer[] arrayCopy = (Integer[])modifyIntegerArray(array); + assertEquals(Integer.valueOf(23), array[0]); + assertEquals(Integer.valueOf(1), arrayCopy[0]); + } + @JavaScriptBody(args = { "value" }, body = "return value;") private native int returnAsInt(Object value); @JavaScriptBody(args = { "value" }, body = "return value;") private native Object returnAsObject(int value); + + @JavaScriptBody(args = { "value" }, body = "value[0] = 1; return value;") + private native Object modifyIntegerArray(Object value); + + @JavaScriptBody(args = { "array", "index" }, body = "return array[index];") + private native Object getArrayItem(Object array, int index); }