jlaskey@3: /* jlaskey@7: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. jlaskey@3: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jlaskey@3: * jlaskey@3: * This code is free software; you can redistribute it and/or modify it jlaskey@3: * under the terms of the GNU General Public License version 2 only, as jlaskey@3: * published by the Free Software Foundation. jlaskey@3: * jlaskey@3: * This code is distributed in the hope that it will be useful, but WITHOUT jlaskey@3: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jlaskey@3: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jlaskey@3: * version 2 for more details (a copy is included in the LICENSE file that jlaskey@3: * accompanied this code). jlaskey@3: * jlaskey@3: * You should have received a copy of the GNU General Public License version jlaskey@3: * 2 along with this work; if not, write to the Free Software Foundation, jlaskey@3: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jlaskey@3: * jlaskey@3: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jlaskey@3: * or visit www.oracle.com if you need additional information or have any jlaskey@3: * questions. jlaskey@3: */ jlaskey@3: jlaskey@3: /* jlaskey@3: * Basic check for Java array element access and array element set. jlaskey@3: * jlaskey@3: * @test jlaskey@3: * @run jlaskey@3: */ jlaskey@3: jlaskey@3: (function() { jlaskey@3: var nargs = arguments.length; attila@458: var args = new (Java.type("java.lang.Object[]"))(nargs); jlaskey@3: print(args.length); jlaskey@3: for (var i = 0; i < nargs; i++) { jlaskey@3: var arg = arguments[i]; jlaskey@3: args[i] = arg; jlaskey@3: print(i + ' ' + arg + '/' + args[i]); jlaskey@3: } jlaskey@3: })(13, 3.14, 'foo'); jlaskey@3: jlaskey@3: var z; // undefined jlaskey@3: attila@458: var intArray = new (Java.type("int[]"))(1); jlaskey@3: intArray[0] = 10; jlaskey@3: print(intArray[0]); jlaskey@3: print(intArray.length); jlaskey@3: intArray[0] = z; jlaskey@3: print(intArray[0]); jlaskey@3: intArray[0] = 10.1; jlaskey@3: print(intArray[0]); jlaskey@3: attila@458: var boolArray = new (Java.type("boolean[]"))(2); jlaskey@3: boolArray[0] = true; jlaskey@3: print(boolArray[0]); jlaskey@3: print(boolArray[1]); jlaskey@3: print(boolArray.length); jlaskey@3: attila@458: var charArray = new (Java.type("char[]"))(1); jlaskey@3: charArray[0] = 'j'; jlaskey@3: print(charArray[0]); jlaskey@3: print(charArray.length); jlaskey@3: jlaskey@3: attila@458: var doubleArray = new (Java.type("double[]"))(1) jlaskey@3: doubleArray[0]=z jlaskey@3: print(doubleArray[0]) jlaskey@3: doubleArray[0]=1 jlaskey@3: print(doubleArray[0]) jlaskey@3: doubleArray[0]=1.1 jlaskey@3: print(doubleArray[0])