aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsundar <none@none>2014-02-14 19:02:02 +0530
committersundar <none@none>2014-02-14 19:02:02 +0530
commit583306df186bb54ee1201185d20a4a7075c6e065 (patch)
treeaf1a0387c4db5ba28a3fa19905356189e880fe22 /test
parent8e0f393275ddaad74c323d58caed97c93b7f91b1 (diff)
downloadnashorn-583306df186bb54ee1201185d20a4a7075c6e065.tar.gz
8011964: need indexed access to externally-managed ByteBuffer
Reviewed-by: lagergren, hannesw
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8011964.js60
-rw-r--r--test/script/basic/JDK-8011964.js.EXPECTED20
-rw-r--r--test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java24
3 files changed, 104 insertions, 0 deletions
diff --git a/test/script/basic/JDK-8011964.js b/test/script/basic/JDK-8011964.js
new file mode 100644
index 00000000..a46023eb
--- /dev/null
+++ b/test/script/basic/JDK-8011964.js
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8011964: need indexed access to externally-managed ByteBuffer
+ *
+ * @test
+ * @run
+ */
+
+
+var ByteBuffer = Java.type("java.nio.ByteBuffer");
+var buf = ByteBuffer.allocate(5);
+
+var obj = {}
+Object.setIndexedPropertiesToExternalArrayData(obj, buf);
+
+obj[0] = 'A'.charCodeAt(0);
+obj[1] = 'B'.charCodeAt(0);
+obj[2] = 'C'.charCodeAt(0);
+obj[3] = 'D'.charCodeAt(0);
+obj[4] = 'E'.charCodeAt(0);
+
+for (var i = 0; i < buf.capacity(); i++) {
+ print("obj[" + i + "] = " + obj[i]);
+ print("buf.get(" + i + ") = " + buf.get(i));
+}
+
+var arr = [];
+Object.setIndexedPropertiesToExternalArrayData(arr, buf);
+obj[0] = 'a'.charCodeAt(0);
+obj[1] = 'b'.charCodeAt(0);
+obj[2] = 'c'.charCodeAt(0);
+obj[3] = 'd'.charCodeAt(0);
+obj[4] = 'e'.charCodeAt(0);
+
+for (var i in arr) {
+ print("arr[" + i + "] = " + arr[i]);
+ print("buf.get(" + i + ") = " + buf.get(i));
+}
diff --git a/test/script/basic/JDK-8011964.js.EXPECTED b/test/script/basic/JDK-8011964.js.EXPECTED
new file mode 100644
index 00000000..5bec2bdf
--- /dev/null
+++ b/test/script/basic/JDK-8011964.js.EXPECTED
@@ -0,0 +1,20 @@
+obj[0] = 65
+buf.get(0) = 65
+obj[1] = 66
+buf.get(1) = 66
+obj[2] = 67
+buf.get(2) = 67
+obj[3] = 68
+buf.get(3) = 68
+obj[4] = 69
+buf.get(4) = 69
+arr[0] = 97
+buf.get(0) = 97
+arr[1] = 98
+buf.get(1) = 98
+arr[2] = 99
+buf.get(2) = 99
+arr[3] = 100
+buf.get(3) = 100
+arr[4] = 101
+buf.get(4) = 101
diff --git a/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java b/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java
index 544f4ea7..241f22c3 100644
--- a/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java
+++ b/test/src/jdk/nashorn/api/scripting/ScriptObjectMirrorTest.java
@@ -25,6 +25,7 @@
package jdk.nashorn.api.scripting;
+import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -230,6 +231,29 @@ public class ScriptObjectMirrorTest {
}
@Test
+ public void indexPropertiesExternalBufferTest() throws ScriptException {
+ final ScriptEngineManager m = new ScriptEngineManager();
+ final ScriptEngine e = m.getEngineByName("nashorn");
+ final ScriptObjectMirror obj = (ScriptObjectMirror)e.eval("var obj = {}; obj");
+ final ByteBuffer buf = ByteBuffer.allocate(5);
+ int i;
+ for (i = 0; i < 5; i++) {
+ buf.put(i, (byte)(i+10));
+ }
+ obj.setIndexedPropertiesToExternalArrayData(buf);
+
+ for (i = 0; i < 5; i++) {
+ assertEquals((byte)(i+10), ((Number)e.eval("obj[" + i + "]")).byteValue());
+ }
+
+ e.eval("for (i = 0; i < 5; i++) obj[i] = 0");
+ for (i = 0; i < 5; i++) {
+ assertEquals((byte)0, ((Number)e.eval("obj[" + i + "]")).byteValue());
+ assertEquals((byte)0, buf.get(i));
+ }
+ }
+
+ @Test
public void conversionTest() throws ScriptException {
final ScriptEngineManager m = new ScriptEngineManager();
final ScriptEngine e = m.getEngineByName("nashorn");