Merge
This commit is contained in:
commit
372c3a8c86
@ -188,7 +188,7 @@
|
||||
<mkdir dir="${fxshell.classes.dir}"/>
|
||||
<javac srcdir="${fxshell.dir}"
|
||||
destdir="${fxshell.classes.dir}"
|
||||
classpath="${dist.jar}:${javac.classpath}"
|
||||
classpath="${dist.jar}${path.separator}${javac.classpath}"
|
||||
debug="${javac.debug}"
|
||||
encoding="${javac.encoding}"
|
||||
includeantruntime="false">
|
||||
|
@ -105,8 +105,8 @@ javac.encoding=ascii
|
||||
javac.classpath=\
|
||||
${build.classes.dir}
|
||||
javac.test.classpath=\
|
||||
${build.classes.dir}:\
|
||||
${build.test.classes.dir}:\
|
||||
${build.classes.dir}${path.separator}\
|
||||
${build.test.classes.dir}${path.separator}\
|
||||
${file.reference.testng.jar}
|
||||
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
@ -259,8 +259,8 @@ testjfx.run.test.classpath=\
|
||||
testjfx-test-sys-prop.test.fork.jvm.options=${run.test.jvmargs.main} -Xmx${run.test.xmx} -cp ${testjfx.run.test.classpath}
|
||||
|
||||
run.test.classpath=\
|
||||
${file.reference.testng.jar}:\
|
||||
${nashorn.internal.tests.jar}:\
|
||||
${file.reference.testng.jar}${path.separator}\
|
||||
${nashorn.internal.tests.jar}${path.separator}\
|
||||
${nashorn.api.tests.jar}
|
||||
|
||||
src.dir=src/jdk.scripting.nashorn/share/classes
|
||||
|
@ -1228,31 +1228,41 @@ public final class NativeArray extends ScriptObject implements OptimisticBuiltin
|
||||
final List<Object> list = Arrays.asList(array);
|
||||
final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance();
|
||||
|
||||
Collections.sort(list, new Comparator<Object>() {
|
||||
private final MethodHandle call_cmp = getCALL_CMP();
|
||||
@Override
|
||||
public int compare(final Object x, final Object y) {
|
||||
if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
|
||||
return 0;
|
||||
} else if (x == ScriptRuntime.UNDEFINED) {
|
||||
return 1;
|
||||
} else if (y == ScriptRuntime.UNDEFINED) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cmp != null) {
|
||||
try {
|
||||
return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
|
||||
} catch (final RuntimeException | Error e) {
|
||||
throw e;
|
||||
} catch (final Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
try {
|
||||
Collections.sort(list, new Comparator<Object>() {
|
||||
private final MethodHandle call_cmp = getCALL_CMP();
|
||||
@Override
|
||||
public int compare(final Object x, final Object y) {
|
||||
if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
|
||||
return 0;
|
||||
} else if (x == ScriptRuntime.UNDEFINED) {
|
||||
return 1;
|
||||
} else if (y == ScriptRuntime.UNDEFINED) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return JSType.toString(x).compareTo(JSType.toString(y));
|
||||
}
|
||||
});
|
||||
if (cmp != null) {
|
||||
try {
|
||||
return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
|
||||
} catch (final RuntimeException | Error e) {
|
||||
throw e;
|
||||
} catch (final Throwable t) {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
return JSType.toString(x).compareTo(JSType.toString(y));
|
||||
}
|
||||
});
|
||||
} catch (final IllegalArgumentException iae) {
|
||||
// Collections.sort throws IllegalArgumentException when
|
||||
// Comparison method violates its general contract
|
||||
|
||||
// See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
|
||||
// If "comparefn" is not undefined and is not a consistent
|
||||
// comparison function for the elements of this array, the
|
||||
// behaviour of sort is implementation-defined.
|
||||
}
|
||||
|
||||
return list.toArray(new Object[array.length]);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package jdk.nashorn.internal.objects;
|
||||
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import jdk.nashorn.internal.objects.annotations.Attribute;
|
||||
import jdk.nashorn.internal.objects.annotations.Constructor;
|
||||
import jdk.nashorn.internal.objects.annotations.Function;
|
||||
@ -226,10 +227,10 @@ public final class NativeArrayBuffer extends ScriptObject {
|
||||
}
|
||||
|
||||
ByteBuffer getBuffer(final int offset) {
|
||||
return nb.duplicate().position(offset);
|
||||
return (ByteBuffer)nb.duplicate().position(offset);
|
||||
}
|
||||
|
||||
ByteBuffer getBuffer(final int offset, final int length) {
|
||||
return getBuffer(offset).limit(length);
|
||||
return (ByteBuffer)getBuffer(offset).limit(length);
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public final class NativeFloat32Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Float32ArrayData.class, "setElem", void.class, int.class, double.class).methodHandle();
|
||||
|
||||
private Float32ArrayData(final FloatBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((FloatBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public final class NativeFloat64Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Float64ArrayData.class, "setElem", void.class, int.class, double.class).methodHandle();
|
||||
|
||||
private Float64ArrayData(final DoubleBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((DoubleBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +82,7 @@ public final class NativeInt16Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int16ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Int16ArrayData(final ShortBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((ShortBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public final class NativeInt32Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int32ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Int32ArrayData(final IntBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((IntBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +80,7 @@ public final class NativeInt8Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int8ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Int8ArrayData(final ByteBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public final class NativeUint16Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint16ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Uint16ArrayData(final CharBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((CharBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +82,7 @@ public final class NativeUint32Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint32ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Uint32ArrayData(final IntBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((IntBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public final class NativeUint8Array extends ArrayBufferView {
|
||||
private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint8ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
|
||||
|
||||
private Uint8ArrayData(final ByteBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +85,7 @@ public final class NativeUint8ClampedArray extends ArrayBufferView {
|
||||
private static final MethodHandle CLAMP_LONG = staticCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "clampLong", long.class, long.class).methodHandle();
|
||||
|
||||
private Uint8ClampedArrayData(final ByteBuffer nb, final int start, final int end) {
|
||||
super(nb.position(start).limit(end).slice(), end - start);
|
||||
super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1239,6 +1239,10 @@ public final class Context {
|
||||
}
|
||||
|
||||
if (storedScript == null) {
|
||||
if (env._dest_dir != null) {
|
||||
source.dump(env._dest_dir);
|
||||
}
|
||||
|
||||
functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();
|
||||
|
||||
if (errMan.hasErrors()) {
|
||||
|
@ -73,7 +73,7 @@ public final class ScriptEnvironment {
|
||||
/** Generate line number table in class files */
|
||||
public final boolean _debug_lines;
|
||||
|
||||
/** Package to which generated class files are added */
|
||||
/** Directory in which source files and generated class files are dumped */
|
||||
public final String _dest_dir;
|
||||
|
||||
/** Display stack trace upon error, default is false */
|
||||
|
@ -28,9 +28,11 @@ package jdk.nashorn.internal.runtime;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.MalformedURLException;
|
||||
@ -44,6 +46,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
@ -989,4 +992,39 @@ public final class Source implements Loggable {
|
||||
public DebugLogger getLogger() {
|
||||
return initLogger(Context.getContextTrusted());
|
||||
}
|
||||
|
||||
private File dumpFile(final String dir) {
|
||||
final URL u = getURL();
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
// make it unique by prefixing current date & time
|
||||
buf.append(LocalDateTime.now().toString());
|
||||
buf.append('_');
|
||||
if (u != null) {
|
||||
// make it a safe file name
|
||||
buf.append(u.toString()
|
||||
.replace('/', '_')
|
||||
.replace('\\', '_'));
|
||||
} else {
|
||||
buf.append(getName());
|
||||
}
|
||||
|
||||
return new File(dir, buf.toString());
|
||||
}
|
||||
|
||||
void dump(final String dir) {
|
||||
final File file = dumpFile(dir);
|
||||
try (final FileOutputStream fos = new FileOutputStream(file)) {
|
||||
final PrintWriter pw = new PrintWriter(fos);
|
||||
pw.print(data.toString());
|
||||
pw.flush();
|
||||
} catch (final IOException ioExp) {
|
||||
debug("Skipping source dump for " +
|
||||
name +
|
||||
": " +
|
||||
ECMAErrors.getMessage(
|
||||
"io.error.cant.write",
|
||||
dir.toString() +
|
||||
" : " + ioExp.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ type.error.cannot.get.default.string=Cannot get default string value
|
||||
type.error.cannot.get.default.number=Cannot get default number value
|
||||
type.error.cant.apply.with.to.null=Cannot apply "with" to null
|
||||
type.error.cant.apply.with.to.undefined=Cannot apply "with" to undefined
|
||||
type.error.cant.apply.with.to.non.scriptobject=Cannot apply "with" to non script object
|
||||
type.error.cant.apply.with.to.non.scriptobject=Cannot apply "with" to non script object. Consider using "with(Object.bindProperties('{'}, nonScriptObject))".
|
||||
type.error.in.with.non.object=Right hand side of "in" cannot be non-Object, found {0}
|
||||
type.error.prototype.not.an.object="prototype" of {0} is not an Object, it is {1}
|
||||
type.error.cant.load.script=Cannot load script from {0}
|
||||
|
@ -114,7 +114,7 @@ nashorn.option.d = { \
|
||||
short_name="-d", \
|
||||
is_undocumented=true, \
|
||||
params="<path>", \
|
||||
desc="specify a destination directory to dump class files.", \
|
||||
desc="specify a destination directory to dump source and class files.", \
|
||||
type=String \
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
TypeError: Cannot apply "with" to non script object
|
||||
TypeError: Cannot apply "with" to non script object. Consider using "with(Object.bindProperties({}, nonScriptObject))".
|
||||
|
46
nashorn/test/script/basic/JDK-8080182.js
Normal file
46
nashorn/test/script/basic/JDK-8080182.js
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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-8080182: Array.prototype.sort throws IAE on inconsistent comparison
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
function Random() {
|
||||
this.toString = function() {
|
||||
return (Math.random() * 100).toString();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
var arr = [];
|
||||
|
||||
for (var j = 0; j < 64; ++j) {
|
||||
arr[j] = new Random();
|
||||
}
|
||||
|
||||
// no IllegalArgumentException expected!
|
||||
arr.sort();
|
||||
}
|
Loading…
Reference in New Issue
Block a user