aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsundar <none@none>2014-04-07 21:57:33 +0530
committersundar <none@none>2014-04-07 21:57:33 +0530
commit2fff65c3044c67a68cee475e852531ec73bc288d (patch)
tree0a5e402e357ff61dbadb882a740295ff71487ea8 /test
parent937145d4660750c9acd2de3dd58ec54c27273109 (diff)
downloadnashorn-2fff65c3044c67a68cee475e852531ec73bc288d.tar.gz
8039387: Nashorn supports indexed access of List elements, but length property is not supported
Reviewed-by: lagergren, jlaskey
Diffstat (limited to 'test')
-rw-r--r--test/script/basic/JDK-8039387.js39
-rw-r--r--test/script/basic/JDK-8039387.js.EXPECTED4
-rw-r--r--test/script/basic/list.js2
-rw-r--r--test/script/basic/list.js.EXPECTED2
4 files changed, 45 insertions, 2 deletions
diff --git a/test/script/basic/JDK-8039387.js b/test/script/basic/JDK-8039387.js
new file mode 100644
index 00000000..8f903c1a
--- /dev/null
+++ b/test/script/basic/JDK-8039387.js
@@ -0,0 +1,39 @@
+/*
+ * 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-8039387: Nashorn supports indexed access of List elements, but length property is not supported
+ *
+ * @test
+ * @run
+ */
+
+var ArrayList = Java.type("java.util.ArrayList")
+var list = new ArrayList(3)
+list.add("nashorn")
+list.add("js")
+list.add("ecmascript")
+var len = list.length
+print("length = " + len)
+for (var i = 0; i < len; i++)
+ print(list[i])
diff --git a/test/script/basic/JDK-8039387.js.EXPECTED b/test/script/basic/JDK-8039387.js.EXPECTED
new file mode 100644
index 00000000..5b9ce56d
--- /dev/null
+++ b/test/script/basic/JDK-8039387.js.EXPECTED
@@ -0,0 +1,4 @@
+length = 3
+nashorn
+js
+ecmascript
diff --git a/test/script/basic/list.js b/test/script/basic/list.js
index 72ae0be7..59136c0b 100644
--- a/test/script/basic/list.js
+++ b/test/script/basic/list.js
@@ -33,7 +33,7 @@ print("l.class.name=" + Java.typeName(l.class)) // Has "class" property like any
l.add("foo")
l.add("bar")
-print("l.length=" + l.length) // doesn't work, returns undefined
+print("l.length=" + l.length) // works, maps to l.size()
print("l.size()=" + l.size()) // this will work
print("l[0]=" + l[0])
diff --git a/test/script/basic/list.js.EXPECTED b/test/script/basic/list.js.EXPECTED
index 18feade2..47f3bd4f 100644
--- a/test/script/basic/list.js.EXPECTED
+++ b/test/script/basic/list.js.EXPECTED
@@ -1,5 +1,5 @@
l.class.name=java.util.ArrayList
-l.length=undefined
+l.length=2
l.size()=2
l[0]=foo
l[1]=bar