1.1 --- a/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 18:52:02 2013 +0100
1.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java Fri Jan 18 19:22:49 2013 +0100
1.3 @@ -159,8 +159,16 @@
1.4 * @exception IllegalArgumentException if the object argument is not
1.5 * an array
1.6 */
1.7 - public static native int getLength(Object array)
1.8 - throws IllegalArgumentException;
1.9 + public static int getLength(Object array)
1.10 + throws IllegalArgumentException {
1.11 + if (!array.getClass().isArray()) {
1.12 + throw new IllegalArgumentException();
1.13 + }
1.14 + return length(array);
1.15 + }
1.16 +
1.17 + @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
1.18 + private static native int length(Object arr);
1.19
1.20 /**
1.21 * Returns the value of the indexed component in the specified
2.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 18:52:02 2013 +0100
2.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionArrayTest.java Fri Jan 18 19:22:49 2013 +0100
2.3 @@ -31,6 +31,16 @@
2.4 String[] arr = (String[]) Array.newInstance(String.class, 10);
2.5 return arr.length;
2.6 }
2.7 +
2.8 + @Compare public int reflectiveLengthOfStringArray() {
2.9 + Object arr = Array.newInstance(String.class, 10);
2.10 + return Array.getLength(arr);
2.11 + }
2.12 +
2.13 + @Compare public int reflectiveLengthOneNonArray() {
2.14 + Object arr = "non-array";
2.15 + return Array.getLength(arr);
2.16 + }
2.17
2.18 @Compare public String compTypeOfStringArray() {
2.19 String[] arr = (String[]) Array.newInstance(String.class, 10);
2.20 @@ -46,6 +56,11 @@
2.21 return arr.length;
2.22 }
2.23
2.24 + @Compare public int reflectiveLengthOfIntArray() {
2.25 + Object arr = Array.newInstance(Integer.TYPE, 10);
2.26 + return Array.getLength(arr);
2.27 + }
2.28 +
2.29 @Compare public String compTypeOfIntArray() {
2.30 int[] arr = (int[]) Array.newInstance(int.class, 10);
2.31 return arr.getClass().getComponentType().getName();
2.32 @@ -54,6 +69,40 @@
2.33 @Compare public Object intNegativeArrayExcp() {
2.34 return Array.newInstance(int.class, -5);
2.35 }
2.36 +
2.37 + @Compare public Integer verifyAutobox() {
2.38 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.39 + return (Integer) Array.get(arr, 0);
2.40 + }
2.41 + @Compare public int verifyInt() {
2.42 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.43 + return Array.getInt(arr, 0);
2.44 + }
2.45 + @Compare public long verifyConvertToLong() {
2.46 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.47 + return Array.getLong(arr, 0);
2.48 + }
2.49 +
2.50 + @Compare public Object verifySetIntToObject() {
2.51 + Object[] arr = (Object[]) Array.newInstance(Object.class, 5);
2.52 + Array.setInt(arr, 0, 10);
2.53 + return Array.get(arr, 0);
2.54 + }
2.55 + @Compare public long verifySetShort() {
2.56 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.57 + Array.setShort(arr, 0, (short)10);
2.58 + return Array.getLong(arr, 0);
2.59 + }
2.60 + @Compare public long verifyCantSetLong() {
2.61 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.62 + Array.setLong(arr, 0, 10);
2.63 + return Array.getLong(arr, 0);
2.64 + }
2.65 +
2.66 + @Compare public double verifyConvertToDouble() {
2.67 + int[] arr = (int[]) Array.newInstance(int.class, 5);
2.68 + return Array.getDouble(arr, 0);
2.69 + }
2.70
2.71 @Compare public int multiIntArray() {
2.72 int[][][] arr = (int[][][]) Array.newInstance(int.class, 3, 3, 3);