JDK-8011964.js revision 877:cf4d2252d444
1178825Sdfr/* 2233294Sstas * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3233294Sstas * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4233294Sstas * 5178825Sdfr * This code is free software; you can redistribute it and/or modify it 6233294Sstas * under the terms of the GNU General Public License version 2 only, as 7233294Sstas * published by the Free Software Foundation. 8233294Sstas * 9178825Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 10233294Sstas * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11233294Sstas * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12178825Sdfr * version 2 for more details (a copy is included in the LICENSE file that 13233294Sstas * accompanied this code). 14233294Sstas * 15233294Sstas * You should have received a copy of the GNU General Public License version 16178825Sdfr * 2 along with this work; if not, write to the Free Software Foundation, 17178825Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18178825Sdfr * 19178825Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20178825Sdfr * or visit www.oracle.com if you need additional information or have any 21178825Sdfr * questions. 22178825Sdfr */ 23178825Sdfr 24178825Sdfr/** 25178825Sdfr * JDK-8011964: need indexed access to externally-managed ByteBuffer 26178825Sdfr * 27178825Sdfr * @test 28178825Sdfr * @run 29178825Sdfr */ 30178825Sdfr 31178825Sdfr 32178825Sdfrvar ByteBuffer = Java.type("java.nio.ByteBuffer"); 33178825Sdfrvar buf = ByteBuffer.allocate(5); 34178825Sdfr 35178825Sdfrvar obj = {} 36178825SdfrObject.setIndexedPropertiesToExternalArrayData(obj, buf); 37178825Sdfr 38178825Sdfrobj[0] = 'A'.charCodeAt(0); 39178825Sdfrobj[1] = 'B'.charCodeAt(0); 40178825Sdfrobj[2] = 'C'.charCodeAt(0); 41178825Sdfrobj[3] = 'D'.charCodeAt(0); 42178825Sdfrobj[4] = 'E'.charCodeAt(0); 43178825Sdfr 44178825Sdfrfor (var i = 0; i < buf.capacity(); i++) { 45178825Sdfr print("obj[" + i + "] = " + obj[i]); 46178825Sdfr print("buf.get(" + i + ") = " + buf.get(i)); 47178825Sdfr} 48178825Sdfr 49178825Sdfrvar arr = []; 50178825SdfrObject.setIndexedPropertiesToExternalArrayData(arr, buf); 51178825Sdfrobj[0] = 'a'.charCodeAt(0); 52178825Sdfrobj[1] = 'b'.charCodeAt(0); 53178825Sdfrobj[2] = 'c'.charCodeAt(0); 54178825Sdfrobj[3] = 'd'.charCodeAt(0); 55178825Sdfrobj[4] = 'e'.charCodeAt(0); 56178825Sdfr 57178825Sdfrfor (var i in arr) { 58178825Sdfr print("arr[" + i + "] = " + arr[i]); 59178825Sdfr print("buf.get(" + i + ") = " + buf.get(i)); 60178825Sdfr} 61178825Sdfr