changeset 1275:2054d01ae326 jdk9-b65

Merge
author lana
date Thu, 14 May 2015 20:14:44 -0700
parents a975636b1433 (current diff) d46a2d937061 (diff)
children d2999fc30824 92958064570c
files
diffstat 20 files changed, 141 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/make/build.xml	Thu May 14 12:38:15 2015 -0700
+++ b/make/build.xml	Thu May 14 20:14:44 2015 -0700
@@ -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">
--- a/make/project.properties	Thu May 14 12:38:15 2015 -0700
+++ b/make/project.properties	Thu May 14 20:14:44 2015 -0700
@@ -105,8 +105,8 @@
 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-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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArray.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArray.java	Thu May 14 20:14:44 2015 -0700
@@ -1228,31 +1228,41 @@
         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;
-                }
+        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;
+                    }
 
-                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);
+                    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));
-            }
-        });
+                    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]);
     }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu May 14 20:14:44 2015 -0700
@@ -28,6 +28,7 @@
 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 @@
     }
 
     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);
     }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat32Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat32Array.java	Thu May 14 20:14:44 2015 -0700
@@ -81,7 +81,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat64Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat64Array.java	Thu May 14 20:14:44 2015 -0700
@@ -81,7 +81,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt16Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt16Array.java	Thu May 14 20:14:44 2015 -0700
@@ -82,7 +82,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt32Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt32Array.java	Thu May 14 20:14:44 2015 -0700
@@ -81,7 +81,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt8Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt8Array.java	Thu May 14 20:14:44 2015 -0700
@@ -80,7 +80,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint16Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint16Array.java	Thu May 14 20:14:44 2015 -0700
@@ -81,7 +81,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint32Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint32Array.java	Thu May 14 20:14:44 2015 -0700
@@ -82,7 +82,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8Array.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8Array.java	Thu May 14 20:14:44 2015 -0700
@@ -81,7 +81,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Thu May 14 20:14:44 2015 -0700
@@ -85,7 +85,7 @@
         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
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Thu May 14 20:14:44 2015 -0700
@@ -1239,6 +1239,10 @@
         }
 
         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()) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptEnvironment.java	Thu May 14 20:14:44 2015 -0700
@@ -73,7 +73,7 @@
     /** 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 */
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java	Thu May 14 20:14:44 2015 -0700
@@ -28,9 +28,11 @@
 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.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 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()));
+        }
+    }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Messages.properties	Thu May 14 20:14:44 2015 -0700
@@ -121,7 +121,7 @@
 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}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Options.properties	Thu May 14 12:38:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Options.properties	Thu May 14 20:14:44 2015 -0700
@@ -114,7 +114,7 @@
     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                                                  \
 }
 
--- a/test/script/basic/8024180/with_java_object.js.EXPECTED	Thu May 14 12:38:15 2015 -0700
+++ b/test/script/basic/8024180/with_java_object.js.EXPECTED	Thu May 14 20:14:44 2015 -0700
@@ -1,1 +1,1 @@
-TypeError: Cannot apply "with" to non script object
+TypeError: Cannot apply "with" to non script object. Consider using "with(Object.bindProperties({}, nonScriptObject))".
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8080182.js	Thu May 14 20:14:44 2015 -0700
@@ -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();
+}