--- a/nashorn/src/jdk/nashorn/internal/objects/NativeArguments.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeArguments.java Thu Jun 20 17:34:42 2013 +0530
@@ -125,7 +125,7 @@
@Override
public void setArgument(final int key, final Object value) {
if (namedArgs.has(key)) {
- namedArgs.set(key, value, false);
+ namedArgs = namedArgs.set(key, value, false);
}
}
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeArray.java Thu Jun 20 17:34:42 2013 +0530
@@ -856,8 +856,12 @@
}
// delete missing elements - which are at the end of sorted array
- sobj.setArray(array.delete(sorted.length, len - 1));
- }
+ if (sorted.length != len) {
+ array = array.delete(sorted.length, len - 1);
+ }
+
+ sobj.setArray(array);
+ }
return sobj;
} catch (final ClassCastException | NullPointerException e) {
--- a/nashorn/src/jdk/nashorn/internal/runtime/URIUtils.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/URIUtils.java Thu Jun 20 17:34:42 2013 +0530
@@ -27,8 +27,6 @@
import static jdk.nashorn.internal.runtime.ECMAErrors.uriError;
-import java.io.UnsupportedEncodingException;
-
/**
* URI handling global functions. ECMA 15.1.3 URI Handling Function Properties
*
@@ -127,6 +125,7 @@
k += 2;
char C;
+ // Most significant bit is zero
if ((B & 0x80) == 0) {
C = (char) B;
if (!component && URI_RESERVED.indexOf(C) >= 0) {
@@ -137,49 +136,68 @@
sb.append(C);
}
} else {
- int n;
- for (n = 1; n < 6; n++) {
- if (((B << n) & 0x80) == 0) {
- break;
- }
- }
+ // n is utf8 length, V is codepoint and minV is lower bound
+ int n, V, minV;
- if (n == 1 || n > 4) {
+ if ((B & 0xC0) == 0x80) {
+ // 10xxxxxx - illegal first byte
+ return error(string, k);
+ } else if ((B & 0x20) == 0) {
+ // 110xxxxx 10xxxxxx
+ n = 2;
+ V = B & 0x1F;
+ minV = 0x80;
+ } else if ((B & 0x10) == 0) {
+ // 1110xxxx 10xxxxxx 10xxxxxx
+ n = 3;
+ V = B & 0x0F;
+ minV = 0x800;
+ } else if ((B & 0x08) == 0) {
+ // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ n = 4;
+ V = B & 0x07;
+ minV = 0x10000;
+ } else if ((B & 0x04) == 0) {
+ // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ n = 5;
+ V = B & 0x03;
+ minV = 0x200000;
+ } else if ((B & 0x02) == 0) {
+ // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ n = 6;
+ V = B & 0x01;
+ minV = 0x4000000;
+ } else {
return error(string, k);
}
- if ((k + (3 * (n - 1))) >= len) {
+ // check bound for sufficient chars
+ if (k + (3*(n-1)) >= len) {
return error(string, k);
}
- final byte[] bbuf = new byte[n];
- bbuf[0] = (byte) B;
-
for (int j = 1; j < n; j++) {
k++;
if (string.charAt(k) != '%') {
return error(string, k);
}
- if (k + 2 == len) {
- return error(string, k);
- }
-
B = toHexByte(string.charAt(k + 1), string.charAt(k + 2));
if (B < 0 || (B & 0xC0) != 0x80) {
return error(string, k + 1);
}
+ V = (V << 6) | (B & 0x3F);
k += 2;
- bbuf[j] = (byte) B;
}
- int V;
- try {
- V = ucs4Char(bbuf);
- } catch (final Exception e) {
- throw uriError(e, "bad.uri", string, Integer.toString(k));
+ // Check for overlongs and invalid codepoints.
+ // The high and low surrogate halves used by UTF-16
+ // (U+D800 through U+DFFF) are not legal Unicode values.
+ if ((V < minV) || (V >= 0xD800 && V <= 0xDFFF)) {
+ V = Integer.MAX_VALUE;
}
+
if (V < 0x10000) {
C = (char) V;
if (!component && URI_RESERVED.indexOf(C) >= 0) {
@@ -224,10 +242,6 @@
return -1;
}
- private static int ucs4Char(final byte[] utf8) throws UnsupportedEncodingException {
- return new String(utf8, "UTF-8").codePointAt(0);
- }
-
private static String toHexEscape(final int u0) {
int u = u0;
int len;
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Thu Jun 20 17:34:42 2013 +0530
@@ -295,6 +295,29 @@
public abstract ArrayData set(int index, double value, boolean strict);
/**
+ * Set an empty value at a given index. Should only affect Object array.
+ *
+ * @param index the index
+ * @return new array data (or same)
+ */
+ public ArrayData setEmpty(final int index) {
+ // Do nothing.
+ return this;
+ }
+
+ /**
+ * Set an empty value for a given range. Should only affect Object array.
+ *
+ * @param lo range low end
+ * @param hi range high end
+ * @return new array data (or same)
+ */
+ public ArrayData setEmpty(final long lo, final long hi) {
+ // Do nothing.
+ return this;
+ }
+
+ /**
* Get an int value from a given index
*
* @param index the index
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/ArrayFilter.java Thu Jun 20 17:34:42 2013 +0530
@@ -129,6 +129,18 @@
}
@Override
+ public ArrayData setEmpty(final int index) {
+ underlying.setEmpty(index);
+ return this;
+ }
+
+ @Override
+ public ArrayData setEmpty(final long lo, final long hi) {
+ underlying.setEmpty(lo, hi);
+ return this;
+ }
+
+ @Override
public int getInt(final int index) {
return underlying.getInt(index);
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/DeletedArrayFilter.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/DeletedArrayFilter.java Thu Jun 20 17:34:42 2013 +0530
@@ -142,6 +142,7 @@
final long longIndex = ArrayIndex.toLongIndex(index);
assert longIndex >= 0 && longIndex < length();
deleted.set(longIndex);
+ underlying.setEmpty(index);
return this;
}
@@ -149,6 +150,7 @@
public ArrayData delete(final long fromIndex, final long toIndex) {
assert fromIndex >= 0 && fromIndex <= toIndex && toIndex < length();
deleted.setRange(fromIndex, toIndex + 1);
+ underlying.setEmpty(fromIndex, toIndex);
return this;
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/DeletedRangeArrayFilter.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/DeletedRangeArrayFilter.java Thu Jun 20 17:34:42 2013 +0530
@@ -202,6 +202,8 @@
@Override
public ArrayData delete(final int index) {
final long longIndex = ArrayIndex.toLongIndex(index);
+ underlying.setEmpty(index);
+
if (longIndex + 1 == lo) {
lo = longIndex;
} else if (longIndex - 1 == hi) {
@@ -220,6 +222,7 @@
}
lo = Math.min(fromIndex, lo);
hi = Math.max(toIndex, hi);
+ underlying.setEmpty(lo, hi);
return this;
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/ObjectArrayData.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/ObjectArrayData.java Thu Jun 20 17:34:42 2013 +0530
@@ -139,6 +139,18 @@
}
@Override
+ public ArrayData setEmpty(final int index) {
+ array[index] = ScriptRuntime.EMPTY;
+ return this;
+ }
+
+ @Override
+ public ArrayData setEmpty(final long lo, final long hi) {
+ Arrays.fill(array, (int)Math.max(lo, 0L), (int)Math.min(hi, (long)Integer.MAX_VALUE), ScriptRuntime.EMPTY);
+ return this;
+ }
+
+ @Override
public int getInt(final int index) {
return JSType.toInt32(array[index]);
}
@@ -165,11 +177,13 @@
@Override
public ArrayData delete(final int index) {
+ setEmpty(index);
return new DeletedRangeArrayFilter(this, index, index);
}
@Override
public ArrayData delete(final long fromIndex, final long toIndex) {
+ setEmpty(fromIndex, toIndex);
return new DeletedRangeArrayFilter(this, fromIndex, toIndex);
}
@@ -181,7 +195,7 @@
final int newLength = (int) (length() - 1);
final Object elem = array[newLength];
- array[newLength] = 0;
+ setEmpty(newLength);
setLength(newLength);
return elem;
}
--- a/nashorn/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Thu Jun 20 17:34:42 2013 +0530
@@ -204,6 +204,18 @@
}
@Override
+ public ArrayData setEmpty(final int index) {
+ underlying.setEmpty(index);
+ return this;
+ }
+
+ @Override
+ public ArrayData setEmpty(final long lo, final long hi) {
+ underlying.setEmpty(lo, hi);
+ return this;
+ }
+
+ @Override
public int getInt(final int index) {
if (index >= 0 && index < maxDenseLength) {
return underlying.getInt(index);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8010697.js Thu Jun 20 17:34:42 2013 +0530
@@ -0,0 +1,59 @@
+/*
+ * 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-8010697: DeletedArrayFilter seems to leak memory
+ *
+ * @test
+ * @run
+ */
+
+var N = 1000;
+
+var array = new Array(N);
+var WeakReferenceArray = Java.type("java.lang.ref.WeakReference[]");
+var refArray = new WeakReferenceArray(N);
+
+for (var i = 0; i < N; i ++) {
+ var object = new java.lang.Object();
+ array[i] = object;
+ refArray[i] = new java.lang.ref.WeakReference(object);
+}
+
+object = null;
+
+for (var i = 0; i < N; i ++) {
+ delete array[i];
+}
+
+java.lang.System.gc();
+java.lang.System.gc();
+
+for (var i = 0; i < N; i ++) {
+ if (refArray[i].get() != null) {
+ print("Reference found at " + i);
+ exit(0);
+ }
+}
+
+print("All references gone");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8010697.js.EXPECTED Thu Jun 20 17:34:42 2013 +0530
@@ -0,0 +1,1 @@
+All references gone
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8015347.js Thu Jun 20 17:34:42 2013 +0530
@@ -0,0 +1,39 @@
+/*
+ * 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-8015347: Parsing issue with decodeURIComponent
+ *
+ * @test
+ * @run
+ */
+
+try {
+ decodeURIComponent("%C0%80");
+ fail("Should have thrown URIError");
+} catch (e) {
+ if (! (e instanceof URIError)) {
+ fail("Expected URIError, but got " + e);
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8017046.js Thu Jun 20 17:34:42 2013 +0530
@@ -0,0 +1,46 @@
+/*
+ * 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-8017046: Cannot assign undefined to a function argument if the function uses arguments object
+ *
+ * @test
+ * @run
+ */
+
+function assert(value, msg) {
+ if (! value) {
+ fail(msg);
+ }
+}
+
+function func(a) {
+ assert(a === arguments[0], "a !== arguments[0]");
+ assert(a === "hello", "a !== 'hello'");
+ a = undefined;
+ assert(a === arguments[0], "a !== arguments[0]");
+ assert(a === undefined, "a !== undefined");
+ assert(typeof(a) === 'undefined', "typeof(a) is not 'undefined'");
+}
+
+func("hello");
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -39,7 +39,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.BooleanAccessTest
- * @run testng jdk.nashorn.api.javaaccess.BooleanAccessTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.BooleanAccessTest
*/
public class BooleanAccessTest {
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -42,7 +42,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.MethodAccessTest
- * @run testng jdk.nashorn.api.javaaccess.MethodAccessTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.MethodAccessTest
*/
public class MethodAccessTest {
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -39,7 +39,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.NumberAccessTest
- * @run testng jdk.nashorn.api.javaaccess.NumberAccessTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.NumberAccessTest
*/
public class NumberAccessTest {
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -38,7 +38,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.NumberBoxingTest
- * @run testng jdk.nashorn.api.javaaccess.NumberBoxingTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.NumberBoxingTest
*/
public class NumberBoxingTest {
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -38,7 +38,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.ObjectAccessTest
- * @run testng jdk.nashorn.api.javaaccess.ObjectAccessTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.ObjectAccessTest
*/
public class ObjectAccessTest {
--- a/nashorn/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Tue Jun 18 16:06:45 2013 +0100
+++ b/nashorn/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Thu Jun 20 17:34:42 2013 +0530
@@ -38,7 +38,7 @@
/**
* @test
* @build jdk.nashorn.api.javaaccess.SharedObject jdk.nashorn.api.javaaccess.Person jdk.nashorn.api.javaaccess.StringAccessTest
- * @run testng jdk.nashorn.api.javaaccess.StringAccessTest
+ * @run testng/othervm jdk.nashorn.api.javaaccess.StringAccessTest
*/
public class StringAccessTest {