Merge
authorchegar
Tue, 22 Mar 2016 10:52:12 +0000
changeset 36693 79618075dd44
parent 36692 dd2e61a63a44 (current diff)
parent 36689 3370f6f942ff (diff)
child 36694 182a5e7a519e
Merge
nashorn/make/build.xml
--- a/nashorn/make/build.xml	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/make/build.xml	Tue Mar 22 10:52:12 2016 +0000
@@ -93,7 +93,21 @@
         <os family="windows"/>
       </not>
     </condition>
-  </target>
+
+    <!--set windows cygwin/cmd specific properties-->
+    <property environment="env"/>
+    <condition property="test-sys-prop-no-security.os.not.windows.cmd">
+     <not>
+      <and>
+        <os family="windows"/>
+        <not>
+          <isset property="env.SHELL"/>
+        </not>
+      </and>
+     </not>
+    </condition>
+   </target>
+  
 
   <!-- check minimum ant version required to be 1.8.4 -->
   <target name="check-ant-version">
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/LinkedMap.java	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/LinkedMap.java	Tue Mar 22 10:52:12 2016 +0000
@@ -62,7 +62,7 @@
      */
     static class Node {
         private final Object key;
-        private final Object value;
+        private volatile Object value;
 
         private volatile boolean alive = true;
         private volatile Node prev;
@@ -103,6 +103,14 @@
         public Object getValue() {
             return value;
         }
+
+        /**
+         * Set the node's value
+         * @param value the new value
+         */
+        void setValue(final Object value) {
+            this.value = value;
+        }
     }
 
     /**
@@ -150,12 +158,14 @@
      * @param value the value
      */
     public void set(final Object key, final Object value) {
-        final Node newNode = new Node(key, value);
-        final Node oldNode = data.put(key, newNode);
-        if (oldNode != null) {
-            unlink(oldNode);
+        Node node = data.get(key);
+        if (node != null) {
+            node.setValue(value);
+        } else {
+            node = new Node(key, value);
+            data.put(key, node);
+            link(node);
         }
-        link(newNode);
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/es6/JDK-8151809.js	Tue Mar 22 10:52:12 2016 +0000
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2016, 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-8151809: ES6 Map/Set insertion with existing keys changes iteration order
+ *
+ * @test
+ * @run
+ * @option --language=es6
+ */
+
+function assertSetIteratorResult(result, expectedDone, expectedValue) {
+    Assert.assertEquals(result.done, expectedDone);
+    Assert.assertEquals(result.value, expectedValue);
+}
+
+function assertMapIteratorResult(result, expectedDone, expectedKey, expectedValue) {
+    Assert.assertEquals(result.done, expectedDone);
+    if (expectedDone) {
+        Assert.assertEquals(result.value, undefined);
+    } else {
+        Assert.assertEquals(result.value[0], expectedKey);
+        Assert.assertEquals(result.value[1], expectedValue);
+    }
+}
+
+let set = new Set(["foo", "bar", "foo"]);
+let iter = set[Symbol.iterator]();
+assertSetIteratorResult(iter.next(), false, "foo");
+assertSetIteratorResult(iter.next(), false, "bar");
+assertSetIteratorResult(iter.next(), true);
+
+set.add ("foo");
+iter = set[Symbol.iterator]();
+assertSetIteratorResult(iter.next(), false, "foo", false);
+assertSetIteratorResult(iter.next(), false, "bar", false);
+assertSetIteratorResult(iter.next(), true);
+
+set.delete("foo");
+set.add ("foo");
+assertSetIteratorResult(iter.next(), true);
+iter = set[Symbol.iterator]();
+assertSetIteratorResult(iter.next(), false, "bar", false);
+assertSetIteratorResult(iter.next(), false, "foo", false);
+assertSetIteratorResult(iter.next(), true);
+
+
+let map = new Map([["foo", 1], ["bar", 2], ["foo", 3]]);
+iter = map[Symbol.iterator]();
+assertMapIteratorResult(iter.next(), false, "foo", 3);
+assertMapIteratorResult(iter.next(), false, "bar", 2);
+assertMapIteratorResult(iter.next(), true);
+
+
+map.set("foo", 4);
+iter = map[Symbol.iterator]();
+assertMapIteratorResult(iter.next(), false, "foo", 4);
+assertMapIteratorResult(iter.next(), false, "bar", 2);
+assertMapIteratorResult(iter.next(), true);
+
+map.delete("foo");
+map.set("foo", 5);
+assertMapIteratorResult(iter.next(), true);
+iter = map[Symbol.iterator]();
+assertMapIteratorResult(iter.next(), false, "bar", 2);
+assertMapIteratorResult(iter.next(), false, "foo", 5);
+assertMapIteratorResult(iter.next(), true);
--- a/nashorn/test/script/nosecurity/JDK-8144221.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/JDK-8144221.js	Tue Mar 22 10:52:12 2016 +0000
@@ -26,7 +26,7 @@
  *
  * @test
  * @option -scripting
- * @run
+ * @runif os.not.windows.cmd
  */
 
 // The test generates three different JavaScript source files. The first two
--- a/nashorn/test/script/nosecurity/JDK-8151291.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/JDK-8151291.js	Tue Mar 22 10:52:12 2016 +0000
@@ -27,7 +27,7 @@
  *
  * @test
  * @option -scripting
- * @run
+ * @runif os.not.windows.cmd
  */
 
 $EXEC(["java", "-version"])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/nosecurity/JDK-util.js	Tue Mar 22 10:52:12 2016 +0000
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2016, 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.
+ */
+
+/**
+ * This file contains utility functions used by other tests.
+ * @subtest
+ */
+
+var Files = Java.type('java.nio.file.Files'),
+    Paths = Java.type('java.nio.file.Paths'),
+    System = Java.type('java.lang.System')
+
+var File = java.io.File
+var windows = System.getProperty("os.name").startsWith("Windows")
+var winCyg = false
+
+var outPath = {
+    windows:0, //C:\dir
+    mixed:1    //C:/dir
+}
+
+if (windows) {
+    //Is there any better way to diffrentiate between cygwin/command prompt on windows
+    var term = System.getenv("TERM")
+    winCyg = term ? true:false
+}
+
+/**
+ * Returns which command is selected from PATH
+ * @param cmd name of the command searched from PATH
+ */
+function which(cmd) {
+    var path = System.getenv("PATH")
+    var st = new java.util.StringTokenizer(path, File.pathSeparator)
+    while (st.hasMoreTokens()) {
+        var file = new File(st.nextToken(), cmd)
+        if (file.exists()) {
+            return (file.getAbsolutePath())
+        }
+    }
+}
+
+/**
+ * Removes a given file
+ * @param pathname name of the file
+ */
+function rm(pathname) {
+    var Path = Paths.get(pathname)
+    if (!Files.deleteIfExists(Path))
+        print("File \"${pathname}\" doesn't exist")
+}
+    
+
+
+/**
+ * Unix cygpath implementation
+ * Supports only two outputs,windows(C:\dir\) and mixed(C:/dir/)
+ */
+function cygpath(path,mode) {
+   
+    var newpath = path
+    if(path.startsWith("/cygdrive/")){
+        var str = path.substring(10)
+        var index = str.indexOf('/',0)
+        var drv = str.substring(0,index)
+        var rstr = drv.toUpperCase() + ":"
+        newpath = str.replaceFirst(drv,rstr)
+    }
+    if (mode == outPath.windows)
+        return Paths.get(newpath).toString()
+    else {
+        newpath = newpath.replaceAll('\\\\','/')
+        return newpath
+    }                   
+
+}
+
+/**
+ * convert given path based on underlying shell programme runs on
+ */
+function toShellPath(path) {
+    if (windows) {
+        if (winCyg) {
+            return cygpath(path,outPath.mixed)
+        }else {
+         var path = cygpath(path,outPath.windows)
+         //convert '\' ->'\\',cmd shell expects this.
+         return path.replaceAll('\\\\','\\\\\\\\')
+       }
+    }else {
+        return path
+    }
+} 
+
--- a/nashorn/test/script/nosecurity/jjs-common.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-common.js	Tue Mar 22 10:52:12 2016 +0000
@@ -26,15 +26,29 @@
  * @subtest
  * @summary test used by all other jjs-option* test cases
  */
-var javaHome = $ENV.JAVA_HOME,
-    homeJjs = "${javaHome}/bin/jjs",
-    altJjs = $EXEC('which jjs').trim(),
-    homejavac = "${javaHome}/bin/javac",
-    altjavac = $EXEC('which javac').trim()
+
+load(__DIR__ + "JDK-util.js")
+
+var javaHome = System.getenv("JAVA_HOME"),
+    homeJjs = "${javaHome}" + "/bin/jjs",
+    altJjs = which('jjs'),
+    homejavac = "${javaHome}" + "/bin/javac",
+    altjavac = which('javac')
 
-var Files = Java.type('java.nio.file.Files'),
-    Paths = Java.type('java.nio.file.Paths'),
-    System = Java.type('java.lang.System')
+if (windows) {
+    if (winCyg) {
+        //Files.exists() expects proper extension as it talks to windows filesystem even on cygwin
+        //make paths work on on underlying shells cygwin/cmd/linux.
+        homeJjs = toShellPath("${javaHome}" + "/bin/jjs.exe")
+        homejavac = toShellPath("${javaHome}" + "/bin/javac.exe")
+    }
+    else {
+        homeJjs = toShellPath("${javaHome}" + "\\bin\\jjs.exe")
+        homejavac = toShellPath("${javaHome}" + "\\bin\\javac.exe")
+    }
+    altJjs = which('jjs.exe')
+    altjavac = which('javac.exe')
+}
 
 // Initialize default values for variables used in different functions
 var func_cond_p = <<EOD
@@ -62,12 +76,11 @@
 
 // create file to check -flag passing
 var path_f = Paths.get("temp-flag.js")
-var testflag_file = path_f.toAbsolutePath()
+var testflag_file = toShellPath(path_f.toAbsolutePath().toString())
 
 // create file to check -flag functionality
 var path_func = Paths.get("temp-func.js")
-var testfunc_file = path_func.toAbsolutePath()
-
+var testfunc_file = toShellPath(path_func.toAbsolutePath().toString())
 
 function exists(f) {
     return Files.exists(Paths.get(f))
@@ -82,12 +95,12 @@
 
 // write code to testflag_file
 function write_testflag_file() {
-    Files.write(testflag_file, msg_flag.getBytes())
+    Files.write(Paths.get(testflag_file), msg_flag.getBytes())
 }
 
 // write code to testfunc_file
 function write_testfunc_file() {
-    Files.write(testfunc_file, msg_func.getBytes())
+    Files.write(Paths.get(testfunc_file), msg_func.getBytes())
 }
 
 function flag_test_pass() {
@@ -106,7 +119,7 @@
     if (positive) {
         if (eval(func_cond_p))
             print("functionality test PASSED")
-        else
+        else 
             print("functionality test FAILED. stdout: ${out} -- stderr: ${err}")
     }
     else {
@@ -156,8 +169,8 @@
         print("${flag} flag negative test:")
         testjjs_opt("${args_n} ${testflag_file}", false, true)        // negative test
     } finally {
-        $EXEC("rm ${testflag_file}")
-        $EXEC("rm ${testfunc_file}")
+        rm("${testflag_file}")
+        rm("${testfunc_file}")
     }
 }
 
@@ -171,7 +184,7 @@
         print("${flag} flag negative test:")
         testjjs_opt_func("${args_n} ${testfunc_file}", false)        // negative test
     } finally {
-        $EXEC("rm ${testfunc_file}")
+        rm("${testfunc_file}")
     }
 }
 
@@ -185,6 +198,6 @@
         print("${flag} flag negative test:")
         testjjs_opt("${args_n} ${testflag_file}", false, false)        // negative test
     } finally {
-        $EXEC("rm ${testflag_file}")
+        rm("${testflag_file}")
     }
 }
--- a/nashorn/test/script/nosecurity/jjs-option-cp.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-cp.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,37 +25,44 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test to check if -cp flag and its basic functionality
  */
 
 load(__DIR__ + "jjs-common.js")
 
-var hello = __DIR__ + "Hello.class";
-var helloj = __DIR__ + "Hello.java";
+var hello = __DIR__ + "Hello.class"
+var helloj = __DIR__ + "Hello.java"
+
+hello = toShellPath(hello)
+helloj = toShellPath(helloj)
 
 // code to check -flag
 var msg_flag = "print($OPTIONS._classpath)"
 
 // code to check basic functionality
 var msg_func = <<EOD
-$EXEC("rm -f ${hello}")
+var Files = Java.type('java.nio.file.Files')
+var Paths = Java.type('java.nio.file.Paths')
+Files.deleteIfExists(Paths.get("${hello}"))
 $EXEC("${javac} ${helloj}")
-var v = new Packages.Hello();
+var v = new Packages.Hello()
 if (v.string != 'hello') {
-    throw new Error("Unexpected property value");
+    throw new Error("Unexpected property value")
 }
 EOD
 
+var dir = toShellPath(__DIR__)
+
 // flag test expected output variables
-var e_outp = "__DIR__"
+var e_outp = "${dir}"
 var e_outn = "null"
 
 // functionality test arguments
-var arg_p = "-scripting -cp ${__DIR__}  ${testfunc_file}"
+var arg_p = "-scripting -cp ${dir}  ${testfunc_file}"
 var arg_n = "-scripting ${testfunc_file}"
 
 // Testing starts here
-testjjs_flag_and_func("-cp", " __DIR__")
-$EXEC("rm -f ${hello}")
+testjjs_flag_and_func("-cp", " ${dir}")
+rm("${hello}")
+
--- a/nashorn/test/script/nosecurity/jjs-option-define.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-define.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test to check -D flag basic functionality
  */
@@ -38,7 +37,7 @@
 // code to check basic functionality
 var msg_func = <<EOD
 try {
-    var System = Java.type('java.lang.System');
+    var System = Java.type('java.lang.System')
     print(System.getProperty('user.name'))
     if (System.getProperty('user.name') != "nashorn9")
         throw new Error("un expected system property user.name value")
--- a/nashorn/test/script/nosecurity/jjs-option-doe.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-doe.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -doe flag and its basic functionality
  */
--- a/nashorn/test/script/nosecurity/jjs-option-fv.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-fv.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test if -fv flag its basic funnctionality
  */
--- a/nashorn/test/script/nosecurity/jjs-option-fx.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-fx.js	Tue Mar 22 10:52:12 2016 +0000
@@ -26,7 +26,6 @@
  * check -fx option.
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -fx flag and its basic functionality
  * the JavaFX primary stage is available to Nashorn as a global property $STAGE with -fx
@@ -35,7 +34,7 @@
 
 load(__DIR__ + "jjs-common.js")
 
-var msg_flag = "print(typeof($STAGE)); exit();";
+var msg_flag = "print(typeof($STAGE)); exit();"
 
 // flag test expected output variables
 var e_outn = "undefined"
--- a/nashorn/test/script/nosecurity/jjs-option-lang.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-lang.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -lang flag and its basic functionality
  */
--- a/nashorn/test/script/nosecurity/jjs-option-ot.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-ot.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -ot flag
  */
@@ -33,7 +32,7 @@
 load(__DIR__ + "jjs-common.js")
 
 var args_n = "-scripting -ot=false"
-var msg_flag = "print($OPTIONS._optimistic_types);";
+var msg_flag = "print($OPTIONS._optimistic_types)"
 
 // flag test expected output variables
 var e_outp = "true"
--- a/nashorn/test/script/nosecurity/jjs-option-scripting.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-scripting.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -scripting flag and its basic functionality
  */
@@ -40,7 +39,7 @@
 var x = "Nashorn"
 var hello = "Hello ${x}"
 if (hello != "Hello Nashorn") {
-    throw new Error("string interploation not working");
+    throw new Error("string interploation not working")
 }
 EOD
 
--- a/nashorn/test/script/nosecurity/jjs-option-strict.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-strict.js	Tue Mar 22 10:52:12 2016 +0000
@@ -25,7 +25,6 @@
  * JDK-8144113: Nashorn: enable jjs testing. 
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test  -strict flag and its basic functionality
  */
--- a/nashorn/test/script/nosecurity/jjs-option-version.js	Tue Mar 22 10:43:23 2016 +0000
+++ b/nashorn/test/script/nosecurity/jjs-option-version.js	Tue Mar 22 10:52:12 2016 +0000
@@ -26,7 +26,6 @@
  * check if jjs version is same as of java.
  * @test
  * @option -scripting
- * @runif os.not.windows
  * @run
  * @summary Test -version flag and its functionality 
  */