--- a/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java Fri May 03 16:01:33 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java Fri May 03 22:47:23 2013 +0200
@@ -297,7 +297,7 @@
@Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object length(final Object self) {
if (isArray(self)) {
- return ((NativeArray) self).getArray().length() & JSType.MAX_UINT;
+ return ((ScriptObject) self).getArray().length() & JSType.MAX_UINT;
}
return 0;
@@ -311,7 +311,7 @@
@Setter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static void length(final Object self, final Object length) {
if (isArray(self)) {
- ((NativeArray) self).setLength(validLength(length, true));
+ ((ScriptObject) self).setLength(validLength(length, true));
}
}
@@ -642,10 +642,9 @@
final boolean strict = sobj.isStrictContext();
if (bulkable(sobj)) {
- final NativeArray nativeArray = (NativeArray)sobj;
- if (nativeArray.getArray().length() + args.length <= JSType.MAX_UINT) {
- final ArrayData newData = nativeArray.getArray().push(nativeArray.isStrictContext(), args);
- nativeArray.setArray(newData);
+ if (sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
+ final ArrayData newData = sobj.getArray().push(sobj.isStrictContext(), args);
+ sobj.setArray(newData);
return newData.length();
}
//fallthru
@@ -780,8 +779,7 @@
}
if (bulkable(sobj)) {
- final NativeArray narray = (NativeArray) sobj;
- return new NativeArray(narray.getArray().slice(k, finale));
+ return new NativeArray(sobj.getArray().slice(k, finale));
}
final NativeArray copy = new NativeArray(0);
@@ -1001,11 +999,10 @@
}
if (bulkable(sobj)) {
- final NativeArray nativeArray = (NativeArray) sobj;
- nativeArray.getArray().shiftRight(items.length);
+ sobj.getArray().shiftRight(items.length);
for (int j = 0; j < items.length; j++) {
- nativeArray.setArray(nativeArray.getArray().set(j, items[j], sobj.isStrictContext()));
+ sobj.setArray(sobj.getArray().set(j, items[j], sobj.isStrictContext()));
}
} else {
for (long k = len; k > 0; k--) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8013878.js Fri May 03 22:47:23 2013 +0200
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010, 2013, 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-8013878: ClassCastException in Regex
+ *
+ * @test
+ * @run
+ */
+
+var re = /(a)(b)(c)/;
+var str = 'abc';
+
+print(re.exec(str).length);
+print(re.exec(str).concat(['d', 'e', 'f']));
+print(re.exec(str).join('-'));
+print(re.exec(str).push('d'));
+print(re.exec(str).pop());
+print(re.exec(str).reverse());
+print(re.exec(str).shift());
+print(re.exec(str).sort());
+print(re.exec(str).slice(1));
+print(re.exec(str).splice(1, 2, 'foo'));
+print(re.exec(str).unshift('x'));
+print(re.exec(str).indexOf('a'));
+print(re.exec(str).lastIndexOf('a'));
+print(re.exec(str).every(function(a) {return a.length;}));
+print(re.exec(str).some(function(a) {return a.length;}));
+print(re.exec(str).filter(function(a) {return a.length;}));
+print(re.exec(str).forEach(function(a) {print(a)}));
+print(re.exec(str).map(function(a) {return a.length;}));
+print(re.exec(str).reduce(function(a, b) {return a + b}));
+print(re.exec(str).reduceRight(function(a, b) {return a + b}));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8013878.js.EXPECTED Fri May 03 22:47:23 2013 +0200
@@ -0,0 +1,24 @@
+4
+abc,a,b,c,d,e,f
+abc-a-b-c
+5
+c
+c,b,a,abc
+abc
+a,abc,b,c
+a,b,c
+a,b
+5
+1
+1
+true
+true
+abc,a,b,c
+abc
+a
+b
+c
+undefined
+3,1,1,1
+abcabc
+cbaabc