mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-01 08:12:37 +00:00
Merge
This commit is contained in:
commit
20710c0c6e
@ -125,7 +125,7 @@ public final class NativeArguments extends ScriptObject {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -856,8 +856,12 @@ public final class NativeArray extends ScriptObject {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@ -27,8 +27,6 @@ package jdk.nashorn.internal.runtime;
|
||||
|
||||
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 @@ public final class URIUtils {
|
||||
|
||||
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 @@ public final class URIUtils {
|
||||
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 @@ public final class URIUtils {
|
||||
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;
|
||||
|
||||
@ -294,6 +294,29 @@ public abstract class ArrayData {
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
||||
@ -128,6 +128,18 @@ abstract class ArrayFilter extends ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@ -142,6 +142,7 @@ final class DeletedArrayFilter extends ArrayFilter {
|
||||
final long longIndex = ArrayIndex.toLongIndex(index);
|
||||
assert longIndex >= 0 && longIndex < length();
|
||||
deleted.set(longIndex);
|
||||
underlying.setEmpty(index);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -149,6 +150,7 @@ final class DeletedArrayFilter extends ArrayFilter {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -202,6 +202,8 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
|
||||
@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 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
|
||||
}
|
||||
lo = Math.min(fromIndex, lo);
|
||||
hi = Math.max(toIndex, hi);
|
||||
underlying.setEmpty(lo, hi);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -138,6 +138,18 @@ final class ObjectArrayData extends ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
@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 @@ final class ObjectArrayData extends ArrayData {
|
||||
|
||||
@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 class ObjectArrayData extends ArrayData {
|
||||
|
||||
final int newLength = (int) (length() - 1);
|
||||
final Object elem = array[newLength];
|
||||
array[newLength] = 0;
|
||||
setEmpty(newLength);
|
||||
setLength(newLength);
|
||||
return elem;
|
||||
}
|
||||
|
||||
@ -203,6 +203,18 @@ class SparseArrayData extends ArrayData {
|
||||
return this;
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
59
nashorn/test/script/basic/JDK-8010697.js
Normal file
59
nashorn/test/script/basic/JDK-8010697.js
Normal file
@ -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");
|
||||
1
nashorn/test/script/basic/JDK-8010697.js.EXPECTED
Normal file
1
nashorn/test/script/basic/JDK-8010697.js.EXPECTED
Normal file
@ -0,0 +1 @@
|
||||
All references gone
|
||||
39
nashorn/test/script/basic/JDK-8015347.js
Normal file
39
nashorn/test/script/basic/JDK-8015347.js
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
46
nashorn/test/script/basic/JDK-8017046.js
Normal file
46
nashorn/test/script/basic/JDK-8017046.js
Normal file
@ -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");
|
||||
@ -39,7 +39,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ import org.testng.annotations.Test;
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user