emul/src/main/java/java/lang/reflect/Array.java
changeset 571 62c327a1e23f
parent 486 947269b26dc0
     1.1 --- a/emul/src/main/java/java/lang/reflect/Array.java	Fri Jan 18 22:16:04 2013 +0100
     1.2 +++ b/emul/src/main/java/java/lang/reflect/Array.java	Thu Jan 24 17:08:02 2013 +0100
     1.3 @@ -190,7 +190,7 @@
     1.4      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
     1.5          final Class<?> t = array.getClass().getComponentType();
     1.6          if (t.isPrimitive()) {
     1.7 -            return Array.fromPrimitive(t, array, index);
     1.8 +            return fromPrimitive(t, array, index);
     1.9          } else {
    1.10              return ((Object[])array)[index];
    1.11          }
    1.12 @@ -512,7 +512,7 @@
    1.13          }
    1.14          
    1.15      }
    1.16 -
    1.17 +    
    1.18      /**
    1.19       * Sets the value of the indexed component of the specified array
    1.20       * object to the specified {@code int} value.
    1.21 @@ -534,7 +534,7 @@
    1.22      throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
    1.23          Class<?> t = array.getClass().getComponentType();
    1.24          if (t == Integer.TYPE) {
    1.25 -            long[] arr = (long[]) array;
    1.26 +            int[] arr = (int[]) array;
    1.27              arr[index] = i;
    1.28          } else {
    1.29              setLong(array, index, i);
    1.30 @@ -643,10 +643,11 @@
    1.31          if (dims.length == index + 1) {
    1.32              return newArray(sig.length() == 2, sig, dims[index]);
    1.33          }
    1.34 -        Object[] arr = (Object[]) newArray(false, sig, dims[index]);
    1.35 +        Object arr = newArray(false, sig, dims[index]);
    1.36          String compsig = sig.substring(1);
    1.37 -        for (int i = 0; i < arr.length; i++) {
    1.38 -            arr[i] = multiNewArray(compsig, dims, index + 1);
    1.39 +        int len = getLength(arr);
    1.40 +        for (int i = 0; i < len; i++) {
    1.41 +            setArray(arr, i, multiNewArray(compsig, dims, index + 1));
    1.42          }
    1.43          return arr;
    1.44      }
    1.45 @@ -654,6 +655,9 @@
    1.46          return Method.fromPrimitive(t, atArray(array, index));
    1.47      }
    1.48      
    1.49 -    @JavaScriptBody(args = { "array", "index" }, body = "return array[index]")
    1.50 +    @JavaScriptBody(args = { "array", "index" }, body = "return array[index];")
    1.51      private static native Object atArray(Object array, int index);
    1.52 +
    1.53 +    @JavaScriptBody(args = { "array", "index", "v" }, body = "array[index] = v;")
    1.54 +    private static native Object setArray(Object array, int index, Object v);
    1.55  }