Wed, 17 Jun 2015 23:30:09 -0700
Merge
.hgtags | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Mon Jun 15 11:41:52 2015 -0700 1.2 +++ b/.hgtags Wed Jun 17 23:30:09 2015 -0700 1.3 @@ -430,6 +430,7 @@ 1.4 ff7052ce0f6b655d726cd0f77e9a5f8313361889 jdk8u60-b17 1.5 0b5c0f02a0b79ae0aa97520d65e5b520af8f1b2a jdk8u60-b18 1.6 3780124b6dbb100c2c4af2759b8f0e12a8bf1c4c jdk8u60-b19 1.7 +46a3d8588ad227dc390d84dfc0f89b9291395a36 jdk8u60-b20 1.8 afc8b472a5f3d54734be29aa9c4f617191fc9246 jdk8u52-b06 1.9 8cd2d9bea168694db5f090b30ba5973e1656385b jdk8u52-b07 1.10 afc8b472a5f3d54734be29aa9c4f617191fc9246 jdk8u65-b00
2.1 --- a/README Mon Jun 15 11:41:52 2015 -0700 2.2 +++ b/README Wed Jun 17 23:30:09 2015 -0700 2.3 @@ -72,14 +72,11 @@ 2.4 - Running tests 2.5 2.6 Nashorn tests are TestNG based. Running tests requires downloading the 2.7 -TestNG library and placing its jar file into the lib subdirectory: 2.8 +TestNG library and placing its jar file into the test/lib subdirectory. This is 2.9 +done automatically when executing the "ant externals" command to get external 2.10 +test suites (see below). 2.11 2.12 - # download and install TestNG 2.13 - wget http://testng.org/testng-x.y.z.zip 2.14 - unzip testng-x.y.z.zip 2.15 - cp testng-x.y.z/testng-x.y.z.jar test/lib/testng.jar 2.16 - 2.17 -After that, you can run the tests using: 2.18 +Once TestNG is properly installed, you can run the tests using: 2.19 cd make 2.20 ant clean test 2.21
3.1 --- a/make/build.xml Mon Jun 15 11:41:52 2015 -0700 3.2 +++ b/make/build.xml Wed Jun 17 23:30:09 2015 -0700 3.3 @@ -1,7 +1,7 @@ 3.4 <?xml version="1.0" encoding="UTF-8"?> 3.5 3.6 <!-- 3.7 - Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3.8 + Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 3.9 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.10 3.11 This code is free software; you can redistribute it and/or modify it 3.12 @@ -388,7 +388,7 @@ 3.13 </target> 3.14 3.15 <target name="check-testng" unless="testng.available"> 3.16 - <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under test/lib directory."/> 3.17 + <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under ${test.lib} directory."/> 3.18 </target> 3.19 3.20 <!-- only to be invoked as dependency of "test" target --> 3.21 @@ -460,7 +460,7 @@ 3.22 </testng> 3.23 </target> 3.24 3.25 - <target name="test" depends="javadoc, test-pessimistic, test-optimistic"/> 3.26 + <target name="test" depends="get-testng, javadoc, test-pessimistic, test-optimistic"/> 3.27 3.28 <target name="test-optimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.29 <echo message="Running test suite in OPTIMISTIC mode..."/> 3.30 @@ -490,7 +490,7 @@ 3.31 <echo message="WARNING: Jemmy or JavaFX or TestNG not available, will not run tests. Please copy testng.jar, JemmyCore.jar, JemmyFX.jar, JemmyAWTInput.jar under test${file.separator}lib directory. And make sure you have jfxrt.jar in ${java.home}${file.separator}lib${file.separator}ext dir."/> 3.32 </target> 3.33 3.34 - <target name="testjfx" depends="jar, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available"> 3.35 + <target name="testjfx" depends="jar, get-testng, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available"> 3.36 <fileset id="test.classes" dir="${build.test.classes.dir}"> 3.37 <include name="**/framework/*Test.class"/> 3.38 </fileset> 3.39 @@ -518,7 +518,7 @@ 3.40 </testng> 3.41 </target> 3.42 3.43 - <target name="testmarkdown" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.44 + <target name="testmarkdown" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.45 <fileset id="test.classes" dir="${build.test.classes.dir}"> 3.46 <include name="**/framework/*Test.class"/> 3.47 </fileset> 3.48 @@ -537,7 +537,7 @@ 3.49 </testng> 3.50 </target> 3.51 3.52 - <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.53 + <target name="test262" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.54 <fileset id="test.classes" dir="${build.test.classes.dir}"> 3.55 <include name="**/framework/*Test.class"/> 3.56 </fileset> 3.57 @@ -561,7 +561,7 @@ 3.58 3.59 <target name="test262parallel" depends="test262-parallel"/> 3.60 3.61 - <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.62 + <target name="test262-parallel" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.63 <!-- use just build.test.classes.dir to avoid referring to TestNG --> 3.64 <java classname="${parallel.test.runner}" dir="${basedir}" fork="true"> 3.65 <jvmarg line="${ext.class.path}"/> 3.66 @@ -580,7 +580,7 @@ 3.67 3.68 <target name="testparallel" depends="test-parallel"/> 3.69 3.70 - <target name="test-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.71 + <target name="test-parallel" depends="jar, get-testng, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 3.72 <!-- use just build.test.classes.dir to avoid referring to TestNG --> 3.73 <java classname="${parallel.test.runner}" dir="${basedir}" 3.74 failonerror="true" 3.75 @@ -685,7 +685,7 @@ 3.76 </target> 3.77 3.78 <!-- get all external test scripts --> 3.79 - <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider"> 3.80 + <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider, get-testng"> 3.81 <!-- make external test dir --> 3.82 <mkdir dir="${test.external.dir}"/> 3.83 3.84 @@ -710,8 +710,8 @@ 3.85 3.86 <!-- showdown --> 3.87 <mkdir dir="${test.external.dir}/showdown"/> 3.88 - <get src="https://raw.github.com/coreyti/showdown/master/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/> 3.89 - <get src="https://raw.github.com/coreyti/showdown/master/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/> 3.90 + <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/> 3.91 + <get src="https://raw.githubusercontent.com/showdownjs/showdown/0.5.4/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/> 3.92 3.93 </target> 3.94 3.95 @@ -721,12 +721,20 @@ 3.96 <!-- run all perf tests --> 3.97 <target name="perf" depends="externals, update-externals, sunspider, octane"/> 3.98 3.99 - <!-- run all tests --> 3.100 - <target name="exit-if-no-testng" depends="init, check-testng" unless="${testng.available}"> 3.101 - <fail message="Exiting.."/> 3.102 + <!-- download and install testng.jar --> 3.103 + <target name="get-testng" depends="prepare" unless="testng.available"> 3.104 + <get src="http://testng.org/testng-6.8.zip" dest="${test.lib}" skipexisting="true" ignoreerrors="true"/> 3.105 + <unzip src="${test.lib}${file.separator}testng-6.8.zip" dest="${test.lib}"> 3.106 + <patternset> 3.107 + <include name="testng-6.8/testng-6.8.jar"/> 3.108 + </patternset> 3.109 + </unzip> 3.110 + <move file="${test.lib}${file.separator}testng-6.8${file.separator}testng-6.8.jar" tofile="${test.lib}${file.separator}testng.jar"/> 3.111 + <delete dir="${test.lib}${file.separator}testng-6.8"/> 3.112 </target> 3.113 3.114 - <target name="alltests" depends="exit-if-no-testng, externals, update-externals, test, test262parallel, perf"/> 3.115 + <!-- run all tests --> 3.116 + <target name="alltests" depends="get-testng, externals, update-externals, test, test262parallel, testmarkdown, perf"/> 3.117 3.118 <import file="build-benchmark.xml"/> 3.119
4.1 --- a/make/project.properties Mon Jun 15 11:41:52 2015 -0700 4.2 +++ b/make/project.properties Wed Jun 17 23:30:09 2015 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 # 4.5 -# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 4.6 +# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 4.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 # 4.9 # This code is free software; you can redistribute it and/or modify it 4.10 @@ -77,8 +77,11 @@ 4.11 # configuration for java flight recorder 4.12 run.test.jvmargs.jfr=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,dumponexit=true,dumponexitpath=${build.dir},stackdepth=128 4.13 4.14 +# test library location 4.15 +test.lib=${basedir}${file.separator}test${file.separator}lib 4.16 + 4.17 # jars refererred 4.18 -file.reference.testng.jar=test/lib/testng.jar 4.19 +file.reference.testng.jar=${test.lib}${file.separator}testng.jar 4.20 4.21 # Set testng verbose level 4.22 # From TestNG docs: "the verbosity level (0 to 10 where 10 is most detailed) 4.23 @@ -237,9 +240,9 @@ 4.24 -fx \ 4.25 ${test.script.dir}${file.separator}jfx.js 4.26 4.27 -file.reference.jemmyfx.jar=test${file.separator}lib${file.separator}JemmyFX.jar 4.28 -file.reference.jemmycore.jar=test${file.separator}lib${file.separator}JemmyCore.jar 4.29 -file.reference.jemmyawtinput.jar=test${file.separator}lib${file.separator}JemmyAWTInput.jar 4.30 +file.reference.jemmyfx.jar=${test.lib}${file.separator}JemmyFX.jar 4.31 +file.reference.jemmycore.jar=${test.lib}${file.separator}JemmyCore.jar 4.32 +file.reference.jemmyawtinput.jar=${test.lib}${file.separator}JemmyAWTInput.jar 4.33 file.reference.jfxrt.jar=${java.home}${file.separator}lib${file.separator}ext${file.separator}jfxrt.jar 4.34 testjfx.run.test.classpath=\ 4.35 ${file.reference.jemmyfx.jar}${path.separator}\
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/samples/autoimports.js Wed Jun 17 23:30:09 2015 -0700 5.3 @@ -0,0 +1,163 @@ 5.4 +# autoimports script requires -scripting mode 5.5 + 5.6 +/* 5.7 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 5.8 + * 5.9 + * Redistribution and use in source and binary forms, with or without 5.10 + * modification, are permitted provided that the following conditions 5.11 + * are met: 5.12 + * 5.13 + * - Redistributions of source code must retain the above copyright 5.14 + * notice, this list of conditions and the following disclaimer. 5.15 + * 5.16 + * - Redistributions in binary form must reproduce the above copyright 5.17 + * notice, this list of conditions and the following disclaimer in the 5.18 + * documentation and/or other materials provided with the distribution. 5.19 + * 5.20 + * - Neither the name of Oracle nor the names of its 5.21 + * contributors may be used to endorse or promote products derived 5.22 + * from this software without specific prior written permission. 5.23 + * 5.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 5.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 5.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 5.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 5.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 5.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 5.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 5.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 5.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 5.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 5.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5.35 + */ 5.36 + 5.37 +/* 5.38 + * It is tedious to import Java classes used in a script. Sometimes it is easier 5.39 + * use simple names of java classes and have a script auto import Java classes. 5.40 + * You can load this script at the start of an interactive jjs session or at the 5.41 + * start of your script. This script defines a __noSuchProperty__ hook to auto 5.42 + * import Java classes as needed and when they are referred to for the first time 5.43 + * in your script. You can also call the "autoimports" function to print script 5.44 + * statements that you need to use in your script, i.e., have the function generate 5.45 + * a script to import Java classes used by your script so far. After running your 5.46 + * script, you can call autoimports to get the exact Java imports you need and replace 5.47 + * the autoimports load with the generated import statements (to avoid costly init of 5.48 + * the autoimports script). 5.49 + */ 5.50 + 5.51 +(function() { 5.52 + var ArrayList = Java.type("java.util.ArrayList"); 5.53 + var HashMap = Java.type("java.util.HashMap"); 5.54 + var JarFile = Java.type("java.util.jar.JarFile"); 5.55 + var File = Java.type("java.io.File"); 5.56 + var Files = Java.type("java.nio.file.Files"); 5.57 + var FileSystems = Java.type("java.nio.file.FileSystems"); 5.58 + var System = Java.type("java.lang.System"); 5.59 + var URI = Java.type("java.net.URI"); 5.60 + 5.61 + // initialize a class to package map by iterating all 5.62 + // classes available in the system by walking through "jrt fs" 5.63 + 5.64 + var clsToPkg = new HashMap(); 5.65 + 5.66 + // locate rt.jar from sun.boot.class.path 5.67 + function findRtJar() { 5.68 + var paths = System.getProperty("sun.boot.class.path").split(File.pathSeparator); 5.69 + for each (var p in paths) { 5.70 + if (p.endsWith("rt.jar") && new File(p).exists()) { 5.71 + return p; 5.72 + } 5.73 + } 5.74 + } 5.75 + 5.76 + 5.77 + function addToClsToPkg(c, p) { 5.78 + if (clsToPkg.containsKey(c)) { 5.79 + var val = clsToPkg.get(c); 5.80 + if (val instanceof ArrayList) { 5.81 + val.add(p); 5.82 + } else { 5.83 + var al = new ArrayList(); 5.84 + al.add(val); 5.85 + al.add(p); 5.86 + clsToPkg.put(c, al); 5.87 + } 5.88 + } else { 5.89 + clsToPkg.put(c, p); 5.90 + } 5.91 + } 5.92 + 5.93 + // handle collision and allow user to choose package 5.94 + function getPkgOfCls(c) { 5.95 + var val = clsToPkg.get(c); 5.96 + if (val instanceof ArrayList) { 5.97 + var count = 1; 5.98 + print("Multiple matches for " + c + ", choose package:"); 5.99 + for each (var v in val) { 5.100 + print(count + ". " + v); 5.101 + count++; 5.102 + } 5.103 + var choice = parseInt(readLine()); 5.104 + if (isNaN(choice) || choice < 1 || choice > val.size()) { 5.105 + print("invalid choice: " + choice); 5.106 + return undefined; 5.107 + } 5.108 + return val.get(choice - 1); 5.109 + } else { 5.110 + return val; 5.111 + } 5.112 + } 5.113 + 5.114 + var rtJar = findRtJar(); 5.115 + var stream = new JarFile(rtJar).stream(); 5.116 + try { 5.117 + stream.forEach( 5.118 + function(entry) { 5.119 + var str = entry.name; 5.120 + if (str.endsWith(".class")) { 5.121 + if (str.startsWith("java") || 5.122 + str.startsWith("javax") || 5.123 + str.startsWith("org")) { 5.124 + var lastIdx = str.lastIndexOf('/'); 5.125 + if (lastIdx != -1) { 5.126 + var pkg = str.substring(0, lastIdx).replaceAll('/', '.'); 5.127 + var cls = str.substring(lastIdx + 1, str.lastIndexOf(".class")); 5.128 + addToClsToPkg(cls, pkg); 5.129 + } 5.130 + } 5.131 + } 5.132 + }); 5.133 + } finally { 5.134 + stream.close(); 5.135 + } 5.136 + 5.137 + var imports = new ArrayList(); 5.138 + var global = this; 5.139 + var oldNoSuchProp = global.__noSuchProperty__; 5.140 + this.__noSuchProperty__ = function(name) { 5.141 + 'use strict'; 5.142 + 5.143 + if (clsToPkg.containsKey(name)) { 5.144 + var pkg = getPkgOfCls(name); 5.145 + if (pkg) { 5.146 + var clsName = pkg + "." + name; 5.147 + imports.add("var " + name + " = Java.type('" + clsName + "');"); 5.148 + return global[name] = Java.type(clsName); 5.149 + } 5.150 + } else if (typeof oldNoSuchProp == 'function') { 5.151 + return oldNoSuchProp.call(this, name); 5.152 + } 5.153 + 5.154 + if (typeof this == 'undefined') { 5.155 + throw new ReferenceError(name); 5.156 + } else { 5.157 + return undefined; 5.158 + } 5.159 + } 5.160 + 5.161 + this.autoimports = function() { 5.162 + for each (var im in imports) { 5.163 + print(im); 5.164 + } 5.165 + } 5.166 +})();
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/samples/dateconversion.js Wed Jun 17 23:30:09 2015 -0700 6.3 @@ -0,0 +1,73 @@ 6.4 +/* 6.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 6.6 + * 6.7 + * Redistribution and use in source and binary forms, with or without 6.8 + * modification, are permitted provided that the following conditions 6.9 + * are met: 6.10 + * 6.11 + * - Redistributions of source code must retain the above copyright 6.12 + * notice, this list of conditions and the following disclaimer. 6.13 + * 6.14 + * - Redistributions in binary form must reproduce the above copyright 6.15 + * notice, this list of conditions and the following disclaimer in the 6.16 + * documentation and/or other materials provided with the distribution. 6.17 + * 6.18 + * - Neither the name of Oracle nor the names of its 6.19 + * contributors may be used to endorse or promote products derived 6.20 + * from this software without specific prior written permission. 6.21 + * 6.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 6.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 6.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 6.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 6.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 6.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 6.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 6.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 6.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 6.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 6.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6.33 + */ 6.34 + 6.35 +// Converting between #javascript Date and #java8 LocalDateTime with #nashorn 6.36 + 6.37 +// JavaScript Date with current time 6.38 +var d = new Date(); 6.39 +print(d); 6.40 + 6.41 +// Java 8 java.time classes used 6.42 +var Instant = java.time.Instant; 6.43 +var LocalDateTime = java.time.LocalDateTime; 6.44 +var ZoneId = java.time.ZoneId; 6.45 + 6.46 +// Date.prototype.getTime 6.47 + 6.48 +// getTime() method returns the numeric value corresponding to the time 6.49 +// for the specified date according to universal time. The value returned 6.50 +// by the getTime() method is the number of milliseconds since 1 January 1970 00:00:00 UTC. 6.51 +// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime 6.52 + 6.53 +// Java Instant.ofEpochMilli to convert time in milliseconds to Instant object 6.54 +// https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#ofEpochMilli-long- 6.55 + 6.56 +var instant = Instant.ofEpochMilli(d.getTime()); 6.57 + 6.58 +// Instant to LocalDateTime using LocalDateTime.ofInstant 6.59 +// https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#ofInstant-java.time.Instant-java.time.ZoneId- 6.60 + 6.61 +var ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); 6.62 +print(ldt); 6.63 + 6.64 +// converting a LocalDateTime to JavaScript Date 6.65 +// convert LocalDateTime to Instant first 6.66 +// https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#atZone-java.time.ZoneId- 6.67 + 6.68 +var instant = ldt.atZone(ZoneId.systemDefault()).toInstant(); 6.69 + 6.70 +// instant to to epoch milliseconds 6.71 +// https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#toEpochMilli-- 6.72 +// and then to JavaScript Date from time in milliseconds 6.73 +// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date 6.74 + 6.75 +var d1 = new Date(instant.toEpochMilli()); 6.76 +print(d1);
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/samples/exec.js Wed Jun 17 23:30:09 2015 -0700 7.3 @@ -0,0 +1,50 @@ 7.4 +# exec script requires -scripting mode 7.5 + 7.6 +/* 7.7 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 7.8 + * 7.9 + * Redistribution and use in source and binary forms, with or without 7.10 + * modification, are permitted provided that the following conditions 7.11 + * are met: 7.12 + * 7.13 + * - Redistributions of source code must retain the above copyright 7.14 + * notice, this list of conditions and the following disclaimer. 7.15 + * 7.16 + * - Redistributions in binary form must reproduce the above copyright 7.17 + * notice, this list of conditions and the following disclaimer in the 7.18 + * documentation and/or other materials provided with the distribution. 7.19 + * 7.20 + * - Neither the name of Oracle nor the names of its 7.21 + * contributors may be used to endorse or promote products derived 7.22 + * from this software without specific prior written permission. 7.23 + * 7.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 7.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 7.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 7.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 7.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 7.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 7.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 7.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 7.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 7.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 7.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 7.35 + */ 7.36 + 7.37 +// The $EXEC builtin function can be used to run external commands: 7.38 +$EXEC("ls") 7.39 +$EXEC("ls -la") 7.40 + 7.41 +// It can also be given a string to use as stdin: 7.42 +$EXEC("cat", "Hello, world!") 7.43 + 7.44 +// Additional arguments can be passed after the stdin argument, as an array of 7.45 +// strings, or a sequence of varargs: 7.46 +$EXEC("ls", "" /* no stdin */, "-l", "-a") 7.47 +$EXEC("ls", "" /* no stdin */, ["-l", "-a"]) 7.48 + 7.49 +// Output of running external commands is returned from $EXEC: 7.50 +print($EXEC("ls")) 7.51 + 7.52 +// apply on $EXEC 7.53 +print($EXEC.apply(this, ["ls"]));
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/samples/javahelp.js Wed Jun 17 23:30:09 2015 -0700 8.3 @@ -0,0 +1,67 @@ 8.4 +/* 8.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 8.6 + * 8.7 + * Redistribution and use in source and binary forms, with or without 8.8 + * modification, are permitted provided that the following conditions 8.9 + * are met: 8.10 + * 8.11 + * - Redistributions of source code must retain the above copyright 8.12 + * notice, this list of conditions and the following disclaimer. 8.13 + * 8.14 + * - Redistributions in binary form must reproduce the above copyright 8.15 + * notice, this list of conditions and the following disclaimer in the 8.16 + * documentation and/or other materials provided with the distribution. 8.17 + * 8.18 + * - Neither the name of Oracle nor the names of its 8.19 + * contributors may be used to endorse or promote products derived 8.20 + * from this software without specific prior written permission. 8.21 + * 8.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 8.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 8.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 8.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 8.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 8.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 8.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 8.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 8.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 8.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 8.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8.33 + */ 8.34 + 8.35 +// script helpers to print meta info on Java instances and classes 8.36 + 8.37 +// print instance methods info on a Java object or static methods info of a Java class 8.38 +function methods(jobj) { 8.39 + if (! Java.isJavaObject(jobj)) { 8.40 + throw new TypeError("not a Java object"); 8.41 + } 8.42 + 8.43 + var isStatic = Java.isType(jobj); 8.44 + var obj = Object.bindProperties({}, jobj); 8.45 + for each (var i in obj) { 8.46 + if (Java.isJavaMethod(i)) { 8.47 + var str = String(i); 8.48 + var idx = str.indexOf(' '); 8.49 + var overloaded = str.substring(0, idx).endsWith("OverloadedDynamicMethod"); 8.50 + var lastIdx = isStatic? str.lastIndexOf('] on') : str.lastIndexOf(']'); 8.51 + print(str.substring(idx + 1, lastIdx) + (overloaded? "*" : "")) 8.52 + } 8.53 + } 8.54 +} 8.55 + 8.56 +// print instance field names of a Java object or static field names of a Java class 8.57 +function fields(jobj) { 8.58 + if (! Java.isJavaObject(jobj)) { 8.59 + throw new TypeError("not a Java object"); 8.60 + } 8.61 + 8.62 + var obj = Object.bindProperties({}, jobj); 8.63 + for (var i in obj) { 8.64 + if (! Java.isJavaMethod(obj[i])) { 8.65 + print(i); 8.66 + } 8.67 + } 8.68 +} 8.69 + 8.70 +undefined;
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/samples/secondssince.js Wed Jun 17 23:30:09 2015 -0700 9.3 @@ -0,0 +1,43 @@ 9.4 +# usage: jjs secondssince.js 9.5 + 9.6 +/* 9.7 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 9.8 + * 9.9 + * Redistribution and use in source and binary forms, with or without 9.10 + * modification, are permitted provided that the following conditions 9.11 + * are met: 9.12 + * 9.13 + * - Redistributions of source code must retain the above copyright 9.14 + * notice, this list of conditions and the following disclaimer. 9.15 + * 9.16 + * - Redistributions in binary form must reproduce the above copyright 9.17 + * notice, this list of conditions and the following disclaimer in the 9.18 + * documentation and/or other materials provided with the distribution. 9.19 + * 9.20 + * - Neither the name of Oracle nor the names of its 9.21 + * contributors may be used to endorse or promote products derived 9.22 + * from this software without specific prior written permission. 9.23 + * 9.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 9.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 9.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 9.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 9.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 9.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 9.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 9.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 9.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 9.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 9.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9.35 + */ 9.36 + 9.37 +// Number of seconds elapsed since the specified Instance #nashorn #javascript #java 9.38 +// Input date and time in ISO 8601 format 9.39 +// Example: 2001-01-01T00:00:00Z for 1 Jan 2001, 0 GMT 9.40 + 9.41 +var Instant = java.time.Instant; 9.42 +var ChronoUnit = java.time.temporal.ChronoUnit; 9.43 +print("Enter date time:"); 9.44 +var sec = Instant.parse(readLine()). 9.45 + until(Instant.now(), ChronoUnit.SECONDS); 9.46 +print(sec);
10.1 --- a/src/jdk/internal/dynalink/DynamicLinker.java Mon Jun 15 11:41:52 2015 -0700 10.2 +++ b/src/jdk/internal/dynalink/DynamicLinker.java Wed Jun 17 23:30:09 2015 -0700 10.3 @@ -99,10 +99,12 @@ 10.4 import jdk.internal.dynalink.support.RuntimeContextLinkRequestImpl; 10.5 10.6 /** 10.7 - * The linker for {@link RelinkableCallSite} objects. Users of it (scripting frameworks and language runtimes) have to 10.8 - * create a linker using the {@link DynamicLinkerFactory} and invoke its link method from the invokedynamic bootstrap 10.9 - * methods to set the target of all the call sites in the code they generate. Usual usage would be to create one class 10.10 - * per language runtime to contain one linker instance as: 10.11 + * The linker for {@link RelinkableCallSite} objects. Users of it (scripting 10.12 + * frameworks and language runtimes) have to create a linker using the 10.13 + * {@link DynamicLinkerFactory} and invoke its link method from the invokedynamic 10.14 + * bootstrap methods to set the target of all the call sites in the code they 10.15 + * generate. Usual usage would be to create one class per language runtime to 10.16 + * contain one linker instance as: 10.17 * 10.18 * <pre> 10.19 * class MyLanguageRuntime { 10.20 @@ -123,19 +125,27 @@ 10.21 * 10.22 * Note how there are three components you will need to provide here: 10.23 * <ul> 10.24 - * <li>You're expected to provide a {@link GuardingDynamicLinker} for your own language. If your runtime doesn't 10.25 - * have its own language and/or object model (i.e. it's a generic scripting shell), you don't need to implement a 10.26 - * dynamic linker; you would simply not invoke the {@code setPrioritizedLinker} method on the factory, or even better, 10.27 - * simply use {@link DefaultBootstrapper}.</li> 10.28 - * <li>The performance of the programs can depend on your choice of the class to represent call sites. The above 10.29 - * example used {@link MonomorphicCallSite}, but you might want to use {@link ChainedCallSite} instead. You'll need to 10.30 - * experiment and decide what fits your language runtime the best. You can subclass either of these or roll your own if 10.31 - * you need to.</li> 10.32 - * <li>You also need to provide {@link CallSiteDescriptor}s to your call sites. They are immutable objects that contain 10.33 - * all the information about the call site: the class performing the lookups, the name of the method being invoked, and 10.34 - * the method signature. The library has a default {@link CallSiteDescriptorFactory} for descriptors that you can use, 10.35 - * or you can create your own descriptor classes, especially if you need to add further information (values passed in 10.36 + * 10.37 + * <li>You're expected to provide a {@link GuardingDynamicLinker} for your own 10.38 + * language. If your runtime doesn't have its own language and/or object model 10.39 + * (i.e., it's a generic scripting shell), you don't need to implement a dynamic 10.40 + * linker; you would simply not invoke the {@code setPrioritizedLinker} method 10.41 + * on the factory, or even better, simply use {@link DefaultBootstrapper}.</li> 10.42 + * 10.43 + * <li>The performance of the programs can depend on your choice of the class to 10.44 + * represent call sites. The above example used {@link MonomorphicCallSite}, but 10.45 + * you might want to use {@link ChainedCallSite} instead. You'll need to 10.46 + * experiment and decide what fits your language runtime the best. You can 10.47 + * subclass either of these or roll your own if you need to.</li> 10.48 + * 10.49 + * <li>You also need to provide {@link CallSiteDescriptor}s to your call sites. 10.50 + * They are immutable objects that contain all the information about the call 10.51 + * site: the class performing the lookups, the name of the method being invoked, 10.52 + * and the method signature. The library has a default {@link CallSiteDescriptorFactory} 10.53 + * for descriptors that you can use, or you can create your own descriptor 10.54 + * classes, especially if you need to add further information (values passed in 10.55 * additional parameters to the bootstrap method) to them.</li> 10.56 + * 10.57 * </ul> 10.58 * 10.59 * @author Attila Szegedi 10.60 @@ -176,11 +186,15 @@ 10.61 } 10.62 10.63 /** 10.64 - * Links an invokedynamic call site. It will install a method handle into the call site that invokes the relinking 10.65 - * mechanism of this linker. Next time the call site is invoked, it will be linked for the actual arguments it was 10.66 - * invoked with. 10.67 + * Links an invokedynamic call site. It will install a method handle into 10.68 + * the call site that invokes the relinking mechanism of this linker. Next 10.69 + * time the call site is invoked, it will be linked for the actual arguments 10.70 + * it was invoked with. 10.71 * 10.72 + * @param <T> the particular subclass of {@link RelinkableCallSite} for 10.73 + * which to create a link. 10.74 * @param callSite the call site to link. 10.75 + * 10.76 * @return the callSite, for easy call chaining. 10.77 */ 10.78 public <T extends RelinkableCallSite> T link(final T callSite) { 10.79 @@ -189,10 +203,13 @@ 10.80 } 10.81 10.82 /** 10.83 - * Returns the object representing the lower level linker services of this class that are normally exposed to 10.84 - * individual language-specific linkers. While as a user of this class you normally only care about the 10.85 - * {@link #link(RelinkableCallSite)} method, in certain circumstances you might want to use the lower level services 10.86 - * directly; either to lookup specific method handles, to access the type converters, and so on. 10.87 + * Returns the object representing the lower level linker services of this 10.88 + * class that are normally exposed to individual language-specific linkers. 10.89 + * While as a user of this class you normally only care about the 10.90 + * {@link #link(RelinkableCallSite)} method, in certain circumstances you 10.91 + * might want to use the lower level services directly; either to lookup 10.92 + * specific method handles, to access the type converters, and so on. 10.93 + * 10.94 * @return the object representing the linker services of this class. 10.95 */ 10.96 public LinkerServices getLinkerServices() { 10.97 @@ -218,7 +235,9 @@ 10.98 * 10.99 * @param callSite the call site itself 10.100 * @param arguments arguments to the invocation 10.101 + * 10.102 * @return return the method handle for the invocation 10.103 + * 10.104 * @throws Exception rethrows any exception thrown by the linkers 10.105 */ 10.106 @SuppressWarnings("unused") 10.107 @@ -272,11 +291,15 @@ 10.108 } 10.109 10.110 /** 10.111 - * Returns a stack trace element describing the location of the call site currently being linked on the current 10.112 - * thread. The operation internally creates a Throwable object and inspects its stack trace, so it's potentially 10.113 - * expensive. The recommended usage for it is in writing diagnostics code. 10.114 - * @return a stack trace element describing the location of the call site currently being linked, or null if it is 10.115 - * not invoked while a call site is being linked. 10.116 + * Returns a stack trace element describing the location of the call site 10.117 + * currently being linked on the current thread. The operation internally 10.118 + * creates a Throwable object and inspects its stack trace, so it's 10.119 + * potentially expensive. The recommended usage for it is in writing 10.120 + * diagnostics code. 10.121 + * 10.122 + * @return a stack trace element describing the location of the call site 10.123 + * currently being linked, or null if it is not invoked while a call 10.124 + * site is being linked. 10.125 */ 10.126 public static StackTraceElement getLinkedCallSiteLocation() { 10.127 final StackTraceElement[] trace = new Throwable().getStackTrace(); 10.128 @@ -290,8 +313,10 @@ 10.129 } 10.130 10.131 /** 10.132 - * Deprecated because of not precise name. 10.133 + * Deprecated because of imprecise name. 10.134 + * 10.135 * @deprecated Use {@link #getLinkedCallSiteLocation()} instead. 10.136 + * 10.137 * @return see non-deprecated method 10.138 */ 10.139 @Deprecated 10.140 @@ -300,20 +325,26 @@ 10.141 } 10.142 10.143 /** 10.144 - * Returns true if the frame represents {@code MethodHandleNatives.linkCallSite()}, the frame immediately on top of 10.145 - * the call site frame when the call site is being linked for the first time. 10.146 + * Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()}, 10.147 + * the frame immediately on top of the call site frame when the call site is 10.148 + * being linked for the first time. 10.149 + * 10.150 * @param frame the frame 10.151 - * @return true if this frame represents {@code MethodHandleNatives.linkCallSite()} 10.152 + * 10.153 + * @return {@code true} if this frame represents {@code MethodHandleNatives.linkCallSite()}. 10.154 */ 10.155 private static boolean isInitialLinkFrame(final StackTraceElement frame) { 10.156 return testFrame(frame, INITIAL_LINK_METHOD_NAME, INITIAL_LINK_CLASS_NAME); 10.157 } 10.158 10.159 /** 10.160 - * Returns true if the frame represents {@code DynamicLinker.relink()}, the frame immediately on top of the call 10.161 - * site frame when the call site is being relinked (linked for second and subsequent times). 10.162 + * Returns {@code true} if the frame represents {@code DynamicLinker.relink()}, 10.163 + * the frame immediately on top of the call site frame when the call site is 10.164 + * being relinked (linked for second and subsequent times). 10.165 + * 10.166 * @param frame the frame 10.167 - * @return true if this frame represents {@code DynamicLinker.relink()} 10.168 + * 10.169 + * @return {@code true} if this frame represents {@code DynamicLinker.relink()}. 10.170 */ 10.171 private static boolean isRelinkFrame(final StackTraceElement frame) { 10.172 return testFrame(frame, RELINK_METHOD_NAME, CLASS_NAME);
11.1 --- a/src/jdk/nashorn/api/scripting/AbstractJSObject.java Mon Jun 15 11:41:52 2015 -0700 11.2 +++ b/src/jdk/nashorn/api/scripting/AbstractJSObject.java Wed Jun 17 23:30:09 2015 -0700 11.3 @@ -28,6 +28,7 @@ 11.4 import java.util.Collection; 11.5 import java.util.Collections; 11.6 import java.util.Set; 11.7 +import jdk.nashorn.internal.runtime.JSONListAdapter; 11.8 import jdk.nashorn.internal.runtime.JSType; 11.9 11.10 /** 11.11 @@ -282,6 +283,8 @@ 11.12 public static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) { 11.13 if (jsobj instanceof AbstractJSObject) { 11.14 return ((AbstractJSObject)jsobj).getDefaultValue(hint); 11.15 + } else if (jsobj instanceof JSONListAdapter) { 11.16 + return ((JSONListAdapter)jsobj).getDefaultValue(hint); 11.17 } 11.18 return DefaultValueImpl.getDefaultValue(jsobj, hint); 11.19 }
12.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Mon Jun 15 11:41:52 2015 -0700 12.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Wed Jun 17 23:30:09 2015 -0700 12.3 @@ -354,8 +354,7 @@ 12.4 } 12.5 }, CREATE_GLOBAL_ACC_CTXT); 12.6 12.7 - nashornContext.initGlobal(newGlobal, this); 12.8 - newGlobal.setScriptContext(ctxt); 12.9 + nashornContext.initGlobal(newGlobal, this, ctxt); 12.10 12.11 return newGlobal; 12.12 } 12.13 @@ -404,7 +403,7 @@ 12.14 return evalImpl(script, ctxt, getNashornGlobalFrom(ctxt)); 12.15 } 12.16 12.17 - private static Object evalImpl(final Context.MultiGlobalCompiledScript mgcs, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { 12.18 + private Object evalImpl(final Context.MultiGlobalCompiledScript mgcs, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { 12.19 final Global oldGlobal = Context.getGlobal(); 12.20 final boolean globalChanged = (oldGlobal != ctxtGlobal); 12.21 try { 12.22 @@ -413,8 +412,13 @@ 12.23 } 12.24 12.25 final ScriptFunction script = mgcs.getFunction(ctxtGlobal); 12.26 + final ScriptContext oldCtxt = ctxtGlobal.getScriptContext(); 12.27 ctxtGlobal.setScriptContext(ctxt); 12.28 - return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); 12.29 + try { 12.30 + return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); 12.31 + } finally { 12.32 + ctxtGlobal.setScriptContext(oldCtxt); 12.33 + } 12.34 } catch (final Exception e) { 12.35 throwAsScriptException(e, ctxtGlobal); 12.36 throw new AssertionError("should not reach here"); 12.37 @@ -425,7 +429,7 @@ 12.38 } 12.39 } 12.40 12.41 - private static Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { 12.42 + private Object evalImpl(final ScriptFunction script, final ScriptContext ctxt, final Global ctxtGlobal) throws ScriptException { 12.43 if (script == null) { 12.44 return null; 12.45 } 12.46 @@ -436,8 +440,13 @@ 12.47 Context.setGlobal(ctxtGlobal); 12.48 } 12.49 12.50 + final ScriptContext oldCtxt = ctxtGlobal.getScriptContext(); 12.51 ctxtGlobal.setScriptContext(ctxt); 12.52 - return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); 12.53 + try { 12.54 + return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal)); 12.55 + } finally { 12.56 + ctxtGlobal.setScriptContext(oldCtxt); 12.57 + } 12.58 } catch (final Exception e) { 12.59 throwAsScriptException(e, ctxtGlobal); 12.60 throw new AssertionError("should not reach here");
13.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Mon Jun 15 11:41:52 2015 -0700 13.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Wed Jun 17 23:30:09 2015 -0700 13.3 @@ -178,8 +178,7 @@ 13.4 * denies {@code RuntimePermission("nashorn.setConfig")} 13.5 */ 13.6 public ScriptEngine getScriptEngine(final ClassFilter classFilter) { 13.7 - Objects.requireNonNull(classFilter); 13.8 - return newEngine(DEFAULT_OPTIONS, getAppClassLoader(), classFilter); 13.9 + return newEngine(DEFAULT_OPTIONS, getAppClassLoader(), Objects.requireNonNull(classFilter)); 13.10 } 13.11 13.12 /** 13.13 @@ -193,8 +192,7 @@ 13.14 * denies {@code RuntimePermission("nashorn.setConfig")} 13.15 */ 13.16 public ScriptEngine getScriptEngine(final String... args) { 13.17 - Objects.requireNonNull(args); 13.18 - return newEngine(args, getAppClassLoader(), null); 13.19 + return newEngine(Objects.requireNonNull(args), getAppClassLoader(), null); 13.20 } 13.21 13.22 /** 13.23 @@ -209,8 +207,7 @@ 13.24 * denies {@code RuntimePermission("nashorn.setConfig")} 13.25 */ 13.26 public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader) { 13.27 - Objects.requireNonNull(args); 13.28 - return newEngine(args, appLoader, null); 13.29 + return newEngine(Objects.requireNonNull(args), appLoader, null); 13.30 } 13.31 13.32 /** 13.33 @@ -226,9 +223,7 @@ 13.34 * denies {@code RuntimePermission("nashorn.setConfig")} 13.35 */ 13.36 public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) { 13.37 - Objects.requireNonNull(args); 13.38 - Objects.requireNonNull(classFilter); 13.39 - return newEngine(args, appLoader, classFilter); 13.40 + return newEngine(Objects.requireNonNull(args), appLoader, Objects.requireNonNull(classFilter)); 13.41 } 13.42 13.43 private ScriptEngine newEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
14.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Mon Jun 15 11:41:52 2015 -0700 14.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Jun 17 23:30:09 2015 -0700 14.3 @@ -47,6 +47,7 @@ 14.4 import jdk.nashorn.internal.runtime.ConsString; 14.5 import jdk.nashorn.internal.runtime.Context; 14.6 import jdk.nashorn.internal.runtime.ECMAException; 14.7 +import jdk.nashorn.internal.runtime.JSONListAdapter; 14.8 import jdk.nashorn.internal.runtime.JSType; 14.9 import jdk.nashorn.internal.runtime.ScriptFunction; 14.10 import jdk.nashorn.internal.runtime.ScriptObject; 14.11 @@ -72,6 +73,7 @@ 14.12 private final ScriptObject sobj; 14.13 private final Global global; 14.14 private final boolean strict; 14.15 + private final boolean jsonCompatible; 14.16 14.17 @Override 14.18 public boolean equals(final Object other) { 14.19 @@ -110,9 +112,9 @@ 14.20 } 14.21 14.22 if (sobj instanceof ScriptFunction) { 14.23 - final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; 14.24 - final Object self = globalChanged? wrap(thiz, oldGlobal) : thiz; 14.25 - return wrap(ScriptRuntime.apply((ScriptFunction)sobj, unwrap(self, global), unwrapArray(modArgs, global)), global); 14.26 + final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args; 14.27 + final Object self = globalChanged? wrapLikeMe(thiz, oldGlobal) : thiz; 14.28 + return wrapLikeMe(ScriptRuntime.apply((ScriptFunction)sobj, unwrap(self, global), unwrapArray(modArgs, global))); 14.29 } 14.30 14.31 throw new RuntimeException("not a function: " + toString()); 14.32 @@ -140,8 +142,8 @@ 14.33 } 14.34 14.35 if (sobj instanceof ScriptFunction) { 14.36 - final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; 14.37 - return wrap(ScriptRuntime.construct((ScriptFunction)sobj, unwrapArray(modArgs, global)), global); 14.38 + final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args; 14.39 + return wrapLikeMe(ScriptRuntime.construct((ScriptFunction)sobj, unwrapArray(modArgs, global))); 14.40 } 14.41 14.42 throw new RuntimeException("not a constructor: " + toString()); 14.43 @@ -170,7 +172,7 @@ 14.44 return Context.getContext(); 14.45 } 14.46 }, GET_CONTEXT_ACC_CTXT); 14.47 - return wrap(context.eval(global, s, sobj, null, false), global); 14.48 + return wrapLikeMe(context.eval(global, s, sobj, null)); 14.49 } 14.50 }); 14.51 } 14.52 @@ -193,8 +195,8 @@ 14.53 14.54 final Object val = sobj.get(functionName); 14.55 if (val instanceof ScriptFunction) { 14.56 - final Object[] modArgs = globalChanged? wrapArray(args, oldGlobal) : args; 14.57 - return wrap(ScriptRuntime.apply((ScriptFunction)val, sobj, unwrapArray(modArgs, global)), global); 14.58 + final Object[] modArgs = globalChanged? wrapArrayLikeMe(args, oldGlobal) : args; 14.59 + return wrapLikeMe(ScriptRuntime.apply((ScriptFunction)val, sobj, unwrapArray(modArgs, global))); 14.60 } else if (val instanceof JSObject && ((JSObject)val).isFunction()) { 14.61 return ((JSObject)val).call(sobj, args); 14.62 } 14.63 @@ -218,7 +220,7 @@ 14.64 Objects.requireNonNull(name); 14.65 return inGlobal(new Callable<Object>() { 14.66 @Override public Object call() { 14.67 - return wrap(sobj.get(name), global); 14.68 + return wrapLikeMe(sobj.get(name)); 14.69 } 14.70 }); 14.71 } 14.72 @@ -227,7 +229,7 @@ 14.73 public Object getSlot(final int index) { 14.74 return inGlobal(new Callable<Object>() { 14.75 @Override public Object call() { 14.76 - return wrap(sobj.get(index), global); 14.77 + return wrapLikeMe(sobj.get(index)); 14.78 } 14.79 }); 14.80 } 14.81 @@ -253,14 +255,12 @@ 14.82 14.83 @Override 14.84 public void removeMember(final String name) { 14.85 - Objects.requireNonNull(name); 14.86 - remove(name); 14.87 + remove(Objects.requireNonNull(name)); 14.88 } 14.89 14.90 @Override 14.91 public void setMember(final String name, final Object value) { 14.92 - Objects.requireNonNull(name); 14.93 - put(name, value); 14.94 + put(Objects.requireNonNull(name), value); 14.95 } 14.96 14.97 @Override 14.98 @@ -368,7 +368,7 @@ 14.99 14.100 while (iter.hasNext()) { 14.101 final String key = iter.next(); 14.102 - final Object value = translateUndefined(wrap(sobj.get(key), global)); 14.103 + final Object value = translateUndefined(wrapLikeMe(sobj.get(key))); 14.104 entries.add(new AbstractMap.SimpleImmutableEntry<>(key, value)); 14.105 } 14.106 14.107 @@ -382,7 +382,7 @@ 14.108 checkKey(key); 14.109 return inGlobal(new Callable<Object>() { 14.110 @Override public Object call() { 14.111 - return translateUndefined(wrap(sobj.get(key), global)); 14.112 + return translateUndefined(wrapLikeMe(sobj.get(key))); 14.113 } 14.114 }); 14.115 } 14.116 @@ -419,22 +419,22 @@ 14.117 final boolean globalChanged = (oldGlobal != global); 14.118 return inGlobal(new Callable<Object>() { 14.119 @Override public Object call() { 14.120 - final Object modValue = globalChanged? wrap(value, oldGlobal) : value; 14.121 - return translateUndefined(wrap(sobj.put(key, unwrap(modValue, global), strict), global)); 14.122 + final Object modValue = globalChanged? wrapLikeMe(value, oldGlobal) : value; 14.123 + return translateUndefined(wrapLikeMe(sobj.put(key, unwrap(modValue, global), strict))); 14.124 } 14.125 }); 14.126 } 14.127 14.128 @Override 14.129 public void putAll(final Map<? extends String, ? extends Object> map) { 14.130 - Objects.requireNonNull(map, "map is null"); 14.131 + Objects.requireNonNull(map); 14.132 final ScriptObject oldGlobal = Context.getGlobal(); 14.133 final boolean globalChanged = (oldGlobal != global); 14.134 inGlobal(new Callable<Object>() { 14.135 @Override public Object call() { 14.136 for (final Map.Entry<? extends String, ? extends Object> entry : map.entrySet()) { 14.137 final Object value = entry.getValue(); 14.138 - final Object modValue = globalChanged? wrap(value, oldGlobal) : value; 14.139 + final Object modValue = globalChanged? wrapLikeMe(value, oldGlobal) : value; 14.140 final String key = entry.getKey(); 14.141 checkKey(key); 14.142 sobj.set(key, unwrap(modValue, global), getCallSiteFlags()); 14.143 @@ -449,7 +449,7 @@ 14.144 checkKey(key); 14.145 return inGlobal(new Callable<Object>() { 14.146 @Override public Object call() { 14.147 - return translateUndefined(wrap(sobj.remove(key, strict), global)); 14.148 + return translateUndefined(wrapLikeMe(sobj.remove(key, strict))); 14.149 } 14.150 }); 14.151 } 14.152 @@ -486,7 +486,7 @@ 14.153 final Iterator<Object> iter = sobj.valueIterator(); 14.154 14.155 while (iter.hasNext()) { 14.156 - values.add(translateUndefined(wrap(iter.next(), global))); 14.157 + values.add(translateUndefined(wrapLikeMe(iter.next()))); 14.158 } 14.159 14.160 return Collections.unmodifiableList(values); 14.161 @@ -503,7 +503,7 @@ 14.162 public Object getProto() { 14.163 return inGlobal(new Callable<Object>() { 14.164 @Override public Object call() { 14.165 - return wrap(sobj.getProto(), global); 14.166 + return wrapLikeMe(sobj.getProto()); 14.167 } 14.168 }); 14.169 } 14.170 @@ -532,7 +532,7 @@ 14.171 public Object getOwnPropertyDescriptor(final String key) { 14.172 return inGlobal(new Callable<Object>() { 14.173 @Override public Object call() { 14.174 - return wrap(sobj.getOwnPropertyDescriptor(key), global); 14.175 + return wrapLikeMe(sobj.getOwnPropertyDescriptor(key)); 14.176 } 14.177 }); 14.178 } 14.179 @@ -661,16 +661,76 @@ 14.180 * @return wrapped/converted object 14.181 */ 14.182 public static Object wrap(final Object obj, final Object homeGlobal) { 14.183 + return wrap(obj, homeGlobal, false); 14.184 + } 14.185 + 14.186 + /** 14.187 + * Make a script object mirror on given object if needed. Also converts ConsString instances to Strings. The 14.188 + * created wrapper will implement the Java {@code List} interface if {@code obj} is a JavaScript 14.189 + * {@code Array} object; this is compatible with Java JSON libraries expectations. Arrays retrieved through its 14.190 + * properties (transitively) will also implement the list interface. 14.191 + * 14.192 + * @param obj object to be wrapped/converted 14.193 + * @param homeGlobal global to which this object belongs. Not used for ConsStrings. 14.194 + * @return wrapped/converted object 14.195 + */ 14.196 + public static Object wrapAsJSONCompatible(final Object obj, final Object homeGlobal) { 14.197 + return wrap(obj, homeGlobal, true); 14.198 + } 14.199 + 14.200 + /** 14.201 + * Make a script object mirror on given object if needed. Also converts ConsString instances to Strings. 14.202 + * 14.203 + * @param obj object to be wrapped/converted 14.204 + * @param homeGlobal global to which this object belongs. Not used for ConsStrings. 14.205 + * @param jsonCompatible if true, the created wrapper will implement the Java {@code List} interface if 14.206 + * {@code obj} is a JavaScript {@code Array} object. Arrays retrieved through its properties (transitively) 14.207 + * will also implement the list interface. 14.208 + * @return wrapped/converted object 14.209 + */ 14.210 + private static Object wrap(final Object obj, final Object homeGlobal, final boolean jsonCompatible) { 14.211 if(obj instanceof ScriptObject) { 14.212 - return homeGlobal instanceof Global ? new ScriptObjectMirror((ScriptObject)obj, (Global)homeGlobal) : obj; 14.213 - } 14.214 - if(obj instanceof ConsString) { 14.215 + if (!(homeGlobal instanceof Global)) { 14.216 + return obj; 14.217 + } 14.218 + final ScriptObject sobj = (ScriptObject)obj; 14.219 + final Global global = (Global)homeGlobal; 14.220 + final ScriptObjectMirror mirror = new ScriptObjectMirror(sobj, global, jsonCompatible); 14.221 + if (jsonCompatible && sobj.isArray()) { 14.222 + return new JSONListAdapter(mirror, global); 14.223 + } 14.224 + return mirror; 14.225 + } else if(obj instanceof ConsString) { 14.226 return obj.toString(); 14.227 + } else if (jsonCompatible && obj instanceof ScriptObjectMirror) { 14.228 + // Since choosing JSON compatible representation is an explicit decision on user's part, if we're asked to 14.229 + // wrap a mirror that was not JSON compatible, explicitly create its compatible counterpart following the 14.230 + // principle of least surprise. 14.231 + return ((ScriptObjectMirror)obj).asJSONCompatible(); 14.232 } 14.233 return obj; 14.234 } 14.235 14.236 /** 14.237 + * Wraps the passed object with the same jsonCompatible flag as this mirror. 14.238 + * @param obj the object 14.239 + * @param homeGlobal the object's home global. 14.240 + * @return a wrapper for the object. 14.241 + */ 14.242 + private Object wrapLikeMe(final Object obj, final Object homeGlobal) { 14.243 + return wrap(obj, homeGlobal, jsonCompatible); 14.244 + } 14.245 + 14.246 + /** 14.247 + * Wraps the passed object with the same home global and jsonCompatible flag as this mirror. 14.248 + * @param obj the object 14.249 + * @return a wrapper for the object. 14.250 + */ 14.251 + private Object wrapLikeMe(final Object obj) { 14.252 + return wrapLikeMe(obj, global); 14.253 + } 14.254 + 14.255 + /** 14.256 * Unwrap a script object mirror if needed. 14.257 * 14.258 * @param obj object to be unwrapped 14.259 @@ -681,6 +741,8 @@ 14.260 if (obj instanceof ScriptObjectMirror) { 14.261 final ScriptObjectMirror mirror = (ScriptObjectMirror)obj; 14.262 return (mirror.global == homeGlobal)? mirror.sobj : obj; 14.263 + } else if (obj instanceof JSONListAdapter) { 14.264 + return ((JSONListAdapter)obj).unwrap(homeGlobal); 14.265 } 14.266 14.267 return obj; 14.268 @@ -694,6 +756,10 @@ 14.269 * @return wrapped array 14.270 */ 14.271 public static Object[] wrapArray(final Object[] args, final Object homeGlobal) { 14.272 + return wrapArray(args, homeGlobal, false); 14.273 + } 14.274 + 14.275 + private static Object[] wrapArray(final Object[] args, final Object homeGlobal, final boolean jsonCompatible) { 14.276 if (args == null || args.length == 0) { 14.277 return args; 14.278 } 14.279 @@ -701,12 +767,16 @@ 14.280 final Object[] newArgs = new Object[args.length]; 14.281 int index = 0; 14.282 for (final Object obj : args) { 14.283 - newArgs[index] = wrap(obj, homeGlobal); 14.284 + newArgs[index] = wrap(obj, homeGlobal, jsonCompatible); 14.285 index++; 14.286 } 14.287 return newArgs; 14.288 } 14.289 14.290 + private Object[] wrapArrayLikeMe(final Object[] args, final Object homeGlobal) { 14.291 + return wrapArray(args, homeGlobal, jsonCompatible); 14.292 + } 14.293 + 14.294 /** 14.295 * Unwrap an array of script object mirrors if needed. 14.296 * 14.297 @@ -748,12 +818,17 @@ 14.298 // package-privates below this. 14.299 14.300 ScriptObjectMirror(final ScriptObject sobj, final Global global) { 14.301 + this(sobj, global, false); 14.302 + } 14.303 + 14.304 + private ScriptObjectMirror(final ScriptObject sobj, final Global global, final boolean jsonCompatible) { 14.305 assert sobj != null : "ScriptObjectMirror on null!"; 14.306 assert global != null : "home Global is null"; 14.307 14.308 this.sobj = sobj; 14.309 this.global = global; 14.310 this.strict = global.isStrictContext(); 14.311 + this.jsonCompatible = jsonCompatible; 14.312 } 14.313 14.314 // accessors for script engine 14.315 @@ -838,4 +913,11 @@ 14.316 } 14.317 }); 14.318 } 14.319 + 14.320 + private ScriptObjectMirror asJSONCompatible() { 14.321 + if (this.jsonCompatible) { 14.322 + return this; 14.323 + } 14.324 + return new ScriptObjectMirror(sobj, global, true); 14.325 + } 14.326 }
15.1 --- a/src/jdk/nashorn/api/scripting/URLReader.java Mon Jun 15 11:41:52 2015 -0700 15.2 +++ b/src/jdk/nashorn/api/scripting/URLReader.java Wed Jun 17 23:30:09 2015 -0700 15.3 @@ -78,8 +78,7 @@ 15.4 * @throws NullPointerException if url is null 15.5 */ 15.6 public URLReader(final URL url, final Charset cs) { 15.7 - Objects.requireNonNull(url); 15.8 - this.url = url; 15.9 + this.url = Objects.requireNonNull(url); 15.10 this.cs = cs; 15.11 } 15.12
16.1 --- a/src/jdk/nashorn/internal/codegen/ClassEmitter.java Mon Jun 15 11:41:52 2015 -0700 16.2 +++ b/src/jdk/nashorn/internal/codegen/ClassEmitter.java Wed Jun 17 23:30:09 2015 -0700 16.3 @@ -100,7 +100,6 @@ 16.4 * There is also a very nice debug interface that can emit formatted 16.5 * bytecodes that have been written. This is enabled by setting the 16.6 * environment "nashorn.codegen.debug" to true, or --log=codegen:{@literal <level>} 16.7 - * <p> 16.8 * 16.9 * @see Compiler 16.10 */ 16.11 @@ -144,7 +143,7 @@ 16.12 16.13 /** 16.14 * Constructor - only used internally in this class as it breaks 16.15 - * abstraction towards ASM or other code generator below 16.16 + * abstraction towards ASM or other code generator below. 16.17 * 16.18 * @param env script environment 16.19 * @param cw ASM classwriter 16.20 @@ -157,7 +156,8 @@ 16.21 } 16.22 16.23 /** 16.24 - * Return the method names encountered 16.25 + * Return the method names encountered. 16.26 + * 16.27 * @return method names 16.28 */ 16.29 public Set<String> getMethodNames() { 16.30 @@ -165,12 +165,13 @@ 16.31 } 16.32 16.33 /** 16.34 - * Constructor 16.35 + * Constructor. 16.36 * 16.37 * @param env script environment 16.38 * @param className name of class to weave 16.39 * @param superClassName super class name for class 16.40 - * @param interfaceNames names of interfaces implemented by this class, or null if none 16.41 + * @param interfaceNames names of interfaces implemented by this class, or 16.42 + * {@code null} if none 16.43 */ 16.44 ClassEmitter(final Context context, final String className, final String superClassName, final String... interfaceNames) { 16.45 this(context, new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS)); 16.46 @@ -178,7 +179,7 @@ 16.47 } 16.48 16.49 /** 16.50 - * Constructor from the compiler 16.51 + * Constructor from the compiler. 16.52 * 16.53 * @param env Script environment 16.54 * @param sourceName Source name 16.55 @@ -217,7 +218,6 @@ 16.56 } 16.57 16.58 /** 16.59 - * Returns the name of the compile unit class name. 16.60 * @return the name of the compile unit class name. 16.61 */ 16.62 String getUnitClassName() { 16.63 @@ -225,7 +225,8 @@ 16.64 } 16.65 16.66 /** 16.67 - * Get the method count, including init and clinit methods 16.68 + * Get the method count, including init and clinit methods. 16.69 + * 16.70 * @return method count 16.71 */ 16.72 public int getMethodCount() { 16.73 @@ -233,7 +234,8 @@ 16.74 } 16.75 16.76 /** 16.77 - * Get the clinit count 16.78 + * Get the clinit count. 16.79 + * 16.80 * @return clinit count 16.81 */ 16.82 public int getClinitCount() { 16.83 @@ -241,7 +243,8 @@ 16.84 } 16.85 16.86 /** 16.87 - * Get the init count 16.88 + * Get the init count. 16.89 + * 16.90 * @return init count 16.91 */ 16.92 public int getInitCount() { 16.93 @@ -249,7 +252,8 @@ 16.94 } 16.95 16.96 /** 16.97 - * Get the field count 16.98 + * Get the field count. 16.99 + * 16.100 * @return field count 16.101 */ 16.102 public int getFieldCount() { 16.103 @@ -260,6 +264,7 @@ 16.104 * Convert a binary name to a package/class name. 16.105 * 16.106 * @param name Binary name. 16.107 + * 16.108 * @return Package/class name. 16.109 */ 16.110 private static String pathName(final String name) { 16.111 @@ -268,6 +273,7 @@ 16.112 16.113 /** 16.114 * Define the static fields common in all scripts. 16.115 + * 16.116 * @param strictMode Should we generate this method in strict mode 16.117 */ 16.118 private void defineCommonStatics(final boolean strictMode) { 16.119 @@ -284,8 +290,8 @@ 16.120 } 16.121 16.122 /** 16.123 - * Define static utilities common needed in scripts. These are per compile unit 16.124 - * and therefore have to be defined here and not in code gen. 16.125 + * Define static utilities common needed in scripts. These are per compile 16.126 + * unit and therefore have to be defined here and not in code gen. 16.127 */ 16.128 private void defineCommonUtilities() { 16.129 assert unitClassName != null; 16.130 @@ -333,7 +339,9 @@ 16.131 } 16.132 16.133 /** 16.134 - * Constructs a primitive specific method for getting the ith entry from the constants table as an array. 16.135 + * Constructs a primitive specific method for getting the ith entry from the 16.136 + * constants table as an array. 16.137 + * 16.138 * @param clazz Array class. 16.139 */ 16.140 private void defineGetArrayMethod(final Class<?> clazz) { 16.141 @@ -356,7 +364,9 @@ 16.142 16.143 /** 16.144 * Generate the name of a get array from constant pool method. 16.145 + * 16.146 * @param clazz Name of array class. 16.147 + * 16.148 * @return Method name. 16.149 */ 16.150 static String getArrayMethodName(final Class<?> clazz) { 16.151 @@ -366,6 +376,7 @@ 16.152 16.153 /** 16.154 * Ensure a get constant method is issued for the class. 16.155 + * 16.156 * @param clazz Class of constant. 16.157 */ 16.158 void needGetConstantMethod(final Class<?> clazz) { 16.159 @@ -373,12 +384,12 @@ 16.160 } 16.161 16.162 /** 16.163 - * Inspect class name and decide whether we are generating a ScriptObject class 16.164 + * Inspect class name and decide whether we are generating a ScriptObject class. 16.165 * 16.166 * @param scriptPrefix the script class prefix for the current script 16.167 * @param type the type to check 16.168 * 16.169 - * @return true if type is ScriptObject 16.170 + * @return {@code true} if type is ScriptObject 16.171 */ 16.172 private static boolean isScriptObject(final String scriptPrefix, final String type) { 16.173 if (type.startsWith(scriptPrefix)) { 16.174 @@ -393,14 +404,14 @@ 16.175 } 16.176 16.177 /** 16.178 - * Call at beginning of class emission 16.179 + * Call at beginning of class emission. 16.180 */ 16.181 public void begin() { 16.182 classStarted = true; 16.183 } 16.184 16.185 /** 16.186 - * Call at end of class emission 16.187 + * Call at end of class emission. 16.188 */ 16.189 public void end() { 16.190 assert classStarted : "class not started for " + unitClassName; 16.191 @@ -424,7 +435,9 @@ 16.192 16.193 /** 16.194 * Disassemble an array of byte code. 16.195 + * 16.196 * @param bytecode byte array representing bytecode 16.197 + * 16.198 * @return disassembly as human readable string 16.199 */ 16.200 static String disassemble(final byte[] bytecode) { 16.201 @@ -446,7 +459,7 @@ 16.202 } 16.203 16.204 /** 16.205 - * Call back from MethodEmitter for method start 16.206 + * Call back from MethodEmitter for method start. 16.207 * 16.208 * @see MethodEmitter 16.209 * 16.210 @@ -458,7 +471,7 @@ 16.211 } 16.212 16.213 /** 16.214 - * Call back from MethodEmitter for method end 16.215 + * Call back from MethodEmitter for method end. 16.216 * 16.217 * @see MethodEmitter 16.218 * 16.219 @@ -470,7 +483,7 @@ 16.220 } 16.221 16.222 /** 16.223 - * Add a new method to the class - defaults to public method 16.224 + * Add a new method to the class - defaults to public method. 16.225 * 16.226 * @param methodName name of method 16.227 * @param rtype return type of the method 16.228 @@ -483,7 +496,7 @@ 16.229 } 16.230 16.231 /** 16.232 - * Add a new method to the class - defaults to public method 16.233 + * Add a new method to the class - defaults to public method. 16.234 * 16.235 * @param methodFlags access flags for the method 16.236 * @param methodName name of method 16.237 @@ -499,7 +512,7 @@ 16.238 } 16.239 16.240 /** 16.241 - * Add a new method to the class - defaults to public method 16.242 + * Add a new method to the class - defaults to public method. 16.243 * 16.244 * @param methodName name of method 16.245 * @param descriptor descriptor of method 16.246 @@ -511,7 +524,7 @@ 16.247 } 16.248 16.249 /** 16.250 - * Add a new method to the class - defaults to public method 16.251 + * Add a new method to the class - defaults to public method. 16.252 * 16.253 * @param methodFlags access flags for the method 16.254 * @param methodName name of method 16.255 @@ -526,9 +539,10 @@ 16.256 } 16.257 16.258 /** 16.259 - * Add a new method to the class, representing a function node 16.260 + * Add a new method to the class, representing a function node. 16.261 * 16.262 * @param functionNode the function node to generate a method for 16.263 + * 16.264 * @return method emitter to use for weaving this method 16.265 */ 16.266 MethodEmitter method(final FunctionNode functionNode) { 16.267 @@ -546,9 +560,11 @@ 16.268 } 16.269 16.270 /** 16.271 - * Add a new method to the class, representing a rest-of version of the function node 16.272 + * Add a new method to the class, representing a rest-of version of the 16.273 + * function node. 16.274 * 16.275 * @param functionNode the function node to generate a method for 16.276 + * 16.277 * @return method emitter to use for weaving this method 16.278 */ 16.279 MethodEmitter restOfMethod(final FunctionNode functionNode) { 16.280 @@ -566,7 +582,7 @@ 16.281 16.282 16.283 /** 16.284 - * Start generating the <clinit> method in the class 16.285 + * Start generating the <clinit> method in the class. 16.286 * 16.287 * @return method emitter to use for weaving <clinit> 16.288 */ 16.289 @@ -576,7 +592,7 @@ 16.290 } 16.291 16.292 /** 16.293 - * Start generating an <init>()V method in the class 16.294 + * Start generating an <init>()V method in the class. 16.295 * 16.296 * @return method emitter to use for weaving <init>()V 16.297 */ 16.298 @@ -586,7 +602,7 @@ 16.299 } 16.300 16.301 /** 16.302 - * Start generating an <init>()V method in the class 16.303 + * Start generating an <init>()V method in the class. 16.304 * 16.305 * @param ptypes parameter types for constructor 16.306 * @return method emitter to use for weaving <init>()V 16.307 @@ -597,7 +613,7 @@ 16.308 } 16.309 16.310 /** 16.311 - * Start generating an <init>(...)V method in the class 16.312 + * Start generating an <init>(...)V method in the class. 16.313 * 16.314 * @param flags access flags for the constructor 16.315 * @param ptypes parameter types for the constructor 16.316 @@ -610,7 +626,7 @@ 16.317 } 16.318 16.319 /** 16.320 - * Add a field to the class, initialized to a value 16.321 + * Add a field to the class, initialized to a value. 16.322 * 16.323 * @param fieldFlags flags, e.g. should it be static or public etc 16.324 * @param fieldName name of field 16.325 @@ -625,7 +641,7 @@ 16.326 } 16.327 16.328 /** 16.329 - * Add a field to the class 16.330 + * Add a field to the class. 16.331 * 16.332 * @param fieldFlags access flags for the field 16.333 * @param fieldName name of field 16.334 @@ -638,7 +654,7 @@ 16.335 } 16.336 16.337 /** 16.338 - * Add a field to the class - defaults to public 16.339 + * Add a field to the class - defaults to public. 16.340 * 16.341 * @param fieldName name of field 16.342 * @param fieldType type of field 16.343 @@ -651,7 +667,8 @@ 16.344 * Return a bytecode array from this ClassEmitter. The ClassEmitter must 16.345 * have been ended (having its end function called) for this to work. 16.346 * 16.347 - * @return byte code array for generated class, null if class generation hasn't been ended with {@link ClassEmitter#end()} 16.348 + * @return byte code array for generated class, {@code null} if class 16.349 + * generation hasn't been ended with {@link ClassEmitter#end()}. 16.350 */ 16.351 byte[] toByteArray() { 16.352 assert classEnded; 16.353 @@ -663,13 +680,9 @@ 16.354 } 16.355 16.356 /** 16.357 - * Abstraction for flags used in class emission 16.358 - * 16.359 - * We provide abstraction separating these from the underlying bytecode 16.360 - * emitter. 16.361 - * 16.362 - * Flags are provided for method handles, protection levels, static/virtual 16.363 - * fields/methods. 16.364 + * Abstraction for flags used in class emission. We provide abstraction 16.365 + * separating these from the underlying bytecode emitter. Flags are provided 16.366 + * for method handles, protection levels, static/virtual fields/methods. 16.367 */ 16.368 static enum Flag { 16.369 /** method handle with static access */ 16.370 @@ -707,10 +720,12 @@ 16.371 } 16.372 16.373 /** 16.374 - * Return the corresponding ASM flag value for an enum set of flags 16.375 + * Return the corresponding ASM flag value for an enum set of flags. 16.376 * 16.377 * @param flags enum set of flags 16.378 - * @return an integer value representing the flags intrinsic values or:ed together 16.379 + * 16.380 + * @return an integer value representing the flags intrinsic values 16.381 + * or:ed together 16.382 */ 16.383 static int getValue(final EnumSet<Flag> flags) { 16.384 int v = 0;
17.1 --- a/src/jdk/nashorn/internal/codegen/CompilationPhase.java Mon Jun 15 11:41:52 2015 -0700 17.2 +++ b/src/jdk/nashorn/internal/codegen/CompilationPhase.java Wed Jun 17 23:30:09 2015 -0700 17.3 @@ -363,7 +363,7 @@ 17.4 //partial code generation 17.5 final FunctionNode newFunctionNode = transformFunction(fn, new ReplaceCompileUnits() { 17.6 @Override 17.7 - CompileUnit getReplacement(CompileUnit original) { 17.8 + CompileUnit getReplacement(final CompileUnit original) { 17.9 return map.get(original); 17.10 } 17.11
18.1 --- a/src/jdk/nashorn/internal/codegen/CompileUnit.java Mon Jun 15 11:41:52 2015 -0700 18.2 +++ b/src/jdk/nashorn/internal/codegen/CompileUnit.java Wed Jun 17 23:30:09 2015 -0700 18.3 @@ -122,8 +122,7 @@ 18.4 * @param clazz class with code for this compile unit 18.5 */ 18.6 void setCode(final Class<?> clazz) { 18.7 - Objects.requireNonNull(clazz); 18.8 - this.clazz = clazz; 18.9 + this.clazz = Objects.requireNonNull(clazz); 18.10 // Revisit this - refactor to avoid null-ed out non-final fields 18.11 // null out emitter 18.12 this.classEmitter = null;
19.1 --- a/src/jdk/nashorn/internal/codegen/SplitIntoFunctions.java Mon Jun 15 11:41:52 2015 -0700 19.2 +++ b/src/jdk/nashorn/internal/codegen/SplitIntoFunctions.java Wed Jun 17 23:30:09 2015 -0700 19.3 @@ -101,7 +101,7 @@ 19.4 public SplitIntoFunctions(final Compiler compiler) { 19.5 super(new BlockLexicalContext() { 19.6 @Override 19.7 - protected Block afterSetStatements(Block block) { 19.8 + protected Block afterSetStatements(final Block block) { 19.9 for(Statement stmt: block.getStatements()) { 19.10 assert !(stmt instanceof SplitNode); 19.11 } 19.12 @@ -301,7 +301,7 @@ 19.13 } 19.14 19.15 @Override 19.16 - public boolean enterVarNode(VarNode varNode) { 19.17 + public boolean enterVarNode(final VarNode varNode) { 19.18 if (!inSplitNode()) { 19.19 return super.enterVarNode(varNode); 19.20 }
20.1 --- a/src/jdk/nashorn/internal/ir/LexicalContext.java Mon Jun 15 11:41:52 2015 -0700 20.2 +++ b/src/jdk/nashorn/internal/ir/LexicalContext.java Wed Jun 17 23:30:09 2015 -0700 20.3 @@ -1,5 +1,5 @@ 20.4 /* 20.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 20.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 20.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.8 * 20.9 * This code is free software; you can redistribute it and/or modify it 20.10 @@ -31,11 +31,13 @@ 20.11 import jdk.nashorn.internal.runtime.Source; 20.12 20.13 /** 20.14 - * A class that tracks the current lexical context of node visitation as a stack of {@link Block} nodes. Has special 20.15 - * methods to retrieve useful subsets of the context. 20.16 + * A class that tracks the current lexical context of node visitation as a stack 20.17 + * of {@link Block} nodes. Has special methods to retrieve useful subsets of the 20.18 + * context. 20.19 * 20.20 - * This is implemented with a primitive array and a stack pointer, because it really makes a difference 20.21 - * performance wise. None of the collection classes were optimal 20.22 + * This is implemented with a primitive array and a stack pointer, because it 20.23 + * really makes a difference performance-wise. None of the collection classes 20.24 + * were optimal. 20.25 */ 20.26 public class LexicalContext { 20.27 private LexicalContextNode[] stack; 20.28 @@ -79,6 +81,7 @@ 20.29 * {@link Block#NEEDS_SCOPE} because it atomically also sets the 20.30 * {@link FunctionNode#HAS_SCOPE_BLOCK} flag on the block's containing 20.31 * function. 20.32 + * 20.33 * @param block the block that needs to be marked as creating a scope. 20.34 */ 20.35 public void setBlockNeedsScope(final Block block) { 20.36 @@ -97,8 +100,10 @@ 20.37 } 20.38 20.39 /** 20.40 - * Get the flags for a lexical context node on the stack 20.41 + * Get the flags for a lexical context node on the stack. 20.42 + * 20.43 * @param node node 20.44 + * 20.45 * @return the flags for the node 20.46 */ 20.47 public int getFlags(final LexicalContextNode node) { 20.48 @@ -112,8 +117,10 @@ 20.49 20.50 /** 20.51 * Get the function body of a function node on the lexical context 20.52 - * stack. This will trigger an assertion if node isn't present 20.53 + * stack. This will trigger an assertion if node isn't present. 20.54 + * 20.55 * @param functionNode function node 20.56 + * 20.57 * @return body of function node 20.58 */ 20.59 public Block getFunctionBody(final FunctionNode functionNode) { 20.60 @@ -126,15 +133,16 @@ 20.61 } 20.62 20.63 /** 20.64 - * Return all nodes in the LexicalContext 20.65 - * @return all nodes 20.66 + * @return all nodes in the LexicalContext. 20.67 */ 20.68 public Iterator<LexicalContextNode> getAllNodes() { 20.69 return new NodeIterator<>(LexicalContextNode.class); 20.70 } 20.71 20.72 /** 20.73 - * Returns the outermost function in this context. It is either the program, or a lazily compiled function. 20.74 + * Returns the outermost function in this context. It is either the program, 20.75 + * or a lazily compiled function. 20.76 + * 20.77 * @return the outermost function in this context. 20.78 */ 20.79 public FunctionNode getOutermostFunction() { 20.80 @@ -142,8 +150,12 @@ 20.81 } 20.82 20.83 /** 20.84 - * Pushes a new block on top of the context, making it the innermost open block. 20.85 + * Pushes a new block on top of the context, making it the innermost open 20.86 + * block. 20.87 + * 20.88 + * @param <T> the type of the new node 20.89 * @param node the new node 20.90 + * 20.91 * @return the node that was pushed 20.92 */ 20.93 public <T extends LexicalContextNode> T push(final T node) { 20.94 @@ -168,25 +180,28 @@ 20.95 20.96 /** 20.97 * Is the context empty? 20.98 - * @return true if empty 20.99 + * 20.100 + * @return {@code true} if empty 20.101 */ 20.102 public boolean isEmpty() { 20.103 return sp == 0; 20.104 } 20.105 20.106 /** 20.107 - * The depth of the lexical context 20.108 - * @return depth 20.109 + * @return the depth of the lexical context. 20.110 */ 20.111 public int size() { 20.112 return sp; 20.113 } 20.114 20.115 /** 20.116 - * Pops the innermost block off the context and all nodes that has been contributed 20.117 - * since it was put there 20.118 + * Pops the innermost block off the context and all nodes that has been 20.119 + * contributed since it was put there. 20.120 * 20.121 - * @param node the node expected to be popped, used to detect unbalanced pushes/pops 20.122 + * @param <T> the type of the node to be popped 20.123 + * @param node the node expected to be popped, used to detect unbalanced 20.124 + * pushes/pops 20.125 + * 20.126 * @return the node that was popped 20.127 */ 20.128 @SuppressWarnings("unchecked") 20.129 @@ -202,11 +217,17 @@ 20.130 } 20.131 20.132 /** 20.133 - * Explicitly apply flags to the topmost element on the stack. This is only valid to use from a 20.134 - * {@code NodeVisitor.leaveXxx()} method and only on the node being exited at the time. It is not mandatory to use, 20.135 - * as {@link #pop(Node)} will apply the flags automatically, but this method can be used to apply them 20.136 - * during the {@code leaveXxx()} method in case its logic depends on the value of the flags. 20.137 - * @param node the node to apply the flags to. Must be the topmost node on the stack. 20.138 + * Explicitly apply flags to the topmost element on the stack. This is only 20.139 + * valid to use from a {@code NodeVisitor.leaveXxx()} method and only on the 20.140 + * node being exited at the time. It is not mandatory to use, as 20.141 + * {@link #pop(Node)} will apply the flags automatically, but this method 20.142 + * can be used to apply them during the {@code leaveXxx()} method in case 20.143 + * its logic depends on the value of the flags. 20.144 + * 20.145 + * @param <T> the type of the node to apply the flags to. 20.146 + * @param node the node to apply the flags to. Must be the topmost node on 20.147 + * the stack. 20.148 + * 20.149 * @return the passed in node, or a modified node (if any flags were modified) 20.150 */ 20.151 public <T extends LexicalContextNode & Flags<T>> T applyTopFlags(final T node) { 20.152 @@ -215,7 +236,8 @@ 20.153 } 20.154 20.155 /** 20.156 - * Return the top element in the context 20.157 + * Return the top element in the context. 20.158 + * 20.159 * @return the node that was pushed last 20.160 */ 20.161 public LexicalContextNode peek() { 20.162 @@ -223,9 +245,11 @@ 20.163 } 20.164 20.165 /** 20.166 - * Check if a node is in the lexical context 20.167 + * Check if a node is in the lexical context. 20.168 + * 20.169 * @param node node to check for 20.170 - * @return true if in the context 20.171 + * 20.172 + * @return {@code true} if in the context 20.173 */ 20.174 public boolean contains(final LexicalContextNode node) { 20.175 for (int i = 0; i < sp; i++) { 20.176 @@ -242,6 +266,7 @@ 20.177 * 20.178 * @param oldNode old node 20.179 * @param newNode new node 20.180 + * 20.181 * @return the new node 20.182 */ 20.183 public LexicalContextNode replace(final LexicalContextNode oldNode, final LexicalContextNode newNode) { 20.184 @@ -256,7 +281,9 @@ 20.185 } 20.186 20.187 /** 20.188 - * Returns an iterator over all blocks in the context, with the top block (innermost lexical context) first. 20.189 + * Returns an iterator over all blocks in the context, with the top block 20.190 + * (innermost lexical context) first. 20.191 + * 20.192 * @return an iterator over all blocks in the context. 20.193 */ 20.194 public Iterator<Block> getBlocks() { 20.195 @@ -264,7 +291,9 @@ 20.196 } 20.197 20.198 /** 20.199 - * Returns an iterator over all functions in the context, with the top (innermost open) function first. 20.200 + * Returns an iterator over all functions in the context, with the top 20.201 + * (innermost open) function first. 20.202 + * 20.203 * @return an iterator over all functions in the context. 20.204 */ 20.205 public Iterator<FunctionNode> getFunctions() { 20.206 @@ -273,6 +302,7 @@ 20.207 20.208 /** 20.209 * Get the parent block for the current lexical context block 20.210 + * 20.211 * @return parent block 20.212 */ 20.213 public Block getParentBlock() { 20.214 @@ -283,7 +313,9 @@ 20.215 20.216 /** 20.217 * Gets the label node of the current block. 20.218 - * @return the label node of the current block, if it is labeled. Otherwise returns null. 20.219 + * 20.220 + * @return the label node of the current block, if it is labeled. Otherwise 20.221 + * returns {@code null}. 20.222 */ 20.223 public LabelNode getCurrentBlockLabelNode() { 20.224 assert stack[sp - 1] instanceof Block; 20.225 @@ -294,21 +326,12 @@ 20.226 return parent instanceof LabelNode ? (LabelNode)parent : null; 20.227 } 20.228 20.229 - 20.230 - /* 20.231 - public FunctionNode getProgram() { 20.232 - final Iterator<FunctionNode> iter = getFunctions(); 20.233 - FunctionNode last = null; 20.234 - while (iter.hasNext()) { 20.235 - last = iter.next(); 20.236 - } 20.237 - assert last != null; 20.238 - return last; 20.239 - }*/ 20.240 - 20.241 /** 20.242 - * Returns an iterator over all ancestors block of the given block, with its parent block first. 20.243 + * Returns an iterator over all ancestors block of the given block, with its 20.244 + * parent block first. 20.245 + * 20.246 * @param block the block whose ancestors are returned 20.247 + * 20.248 * @return an iterator over all ancestors block of the given block. 20.249 */ 20.250 public Iterator<Block> getAncestorBlocks(final Block block) { 20.251 @@ -323,8 +346,11 @@ 20.252 } 20.253 20.254 /** 20.255 - * Returns an iterator over a block and all its ancestors blocks, with the block first. 20.256 + * Returns an iterator over a block and all its ancestors blocks, with the 20.257 + * block first. 20.258 + * 20.259 * @param block the block that is the starting point of the iteration. 20.260 + * 20.261 * @return an iterator over a block and all its ancestors. 20.262 */ 20.263 public Iterator<Block> getBlocks(final Block block) { 20.264 @@ -352,7 +378,9 @@ 20.265 20.266 /** 20.267 * Get the function for this block. 20.268 + * 20.269 * @param block block for which to get function 20.270 + * 20.271 * @return function for block 20.272 */ 20.273 public FunctionNode getFunction(final Block block) { 20.274 @@ -373,7 +401,6 @@ 20.275 } 20.276 20.277 /** 20.278 - * Returns the innermost block in the context. 20.279 * @return the innermost block in the context. 20.280 */ 20.281 public Block getCurrentBlock() { 20.282 @@ -381,7 +408,6 @@ 20.283 } 20.284 20.285 /** 20.286 - * Returns the innermost function in the context. 20.287 * @return the innermost function in the context. 20.288 */ 20.289 public FunctionNode getCurrentFunction() { 20.290 @@ -394,9 +420,12 @@ 20.291 } 20.292 20.293 /** 20.294 - * Get the block in which a symbol is defined 20.295 + * Get the block in which a symbol is defined. 20.296 + * 20.297 * @param symbol symbol 20.298 - * @return block in which the symbol is defined, assert if no such block in context 20.299 + * 20.300 + * @return block in which the symbol is defined, assert if no such block in 20.301 + * context. 20.302 */ 20.303 public Block getDefiningBlock(final Symbol symbol) { 20.304 final String name = symbol.getName(); 20.305 @@ -410,9 +439,12 @@ 20.306 } 20.307 20.308 /** 20.309 - * Get the function in which a symbol is defined 20.310 + * Get the function in which a symbol is defined. 20.311 + * 20.312 * @param symbol symbol 20.313 - * @return function node in which this symbol is defined, assert if no such symbol exists in context 20.314 + * 20.315 + * @return function node in which this symbol is defined, assert if no such 20.316 + * symbol exists in context. 20.317 */ 20.318 public FunctionNode getDefiningFunction(final Symbol symbol) { 20.319 final String name = symbol.getName(); 20.320 @@ -433,7 +465,8 @@ 20.321 20.322 /** 20.323 * Is the topmost lexical context element a function body? 20.324 - * @return true if function body 20.325 + * 20.326 + * @return {@code true} if function body. 20.327 */ 20.328 public boolean isFunctionBody() { 20.329 return getParentBlock() == null; 20.330 @@ -441,16 +474,20 @@ 20.331 20.332 /** 20.333 * Is the topmost lexical context element body of a SplitNode? 20.334 - * @return true if it's the body of a split node. 20.335 + * 20.336 + * @return {@code true} if it's the body of a split node. 20.337 */ 20.338 public boolean isSplitBody() { 20.339 return sp >= 2 && stack[sp - 1] instanceof Block && stack[sp - 2] instanceof SplitNode; 20.340 } 20.341 20.342 /** 20.343 - * Get the parent function for a function in the lexical context 20.344 + * Get the parent function for a function in the lexical context. 20.345 + * 20.346 * @param functionNode function for which to get parent 20.347 - * @return parent function of functionNode or null if none (e.g. if functionNode is the program) 20.348 + * 20.349 + * @return parent function of functionNode or {@code null} if none (e.g., if 20.350 + * functionNode is the program). 20.351 */ 20.352 public FunctionNode getParentFunction(final FunctionNode functionNode) { 20.353 final Iterator<FunctionNode> iter = new NodeIterator<>(FunctionNode.class); 20.354 @@ -465,12 +502,16 @@ 20.355 } 20.356 20.357 /** 20.358 - * Count the number of scopes until a given node. Note that this method is solely used to figure out the number of 20.359 - * scopes that need to be explicitly popped in order to perform a break or continue jump within the current bytecode 20.360 - * method. For this reason, the method returns 0 if it encounters a {@code SplitNode} between the current location 20.361 - * and the break/continue target. 20.362 - * @param until node to stop counting at. Must be within the current function 20.363 - * @return number of with scopes encountered in the context 20.364 + * Count the number of scopes until a given node. Note that this method is 20.365 + * solely used to figure out the number of scopes that need to be explicitly 20.366 + * popped in order to perform a break or continue jump within the current 20.367 + * bytecode method. For this reason, the method returns 0 if it encounters a 20.368 + * {@code SplitNode} between the current location and the break/continue 20.369 + * target. 20.370 + * 20.371 + * @param until node to stop counting at. Must be within the current function. 20.372 + * 20.373 + * @return number of with scopes encountered in the context. 20.374 */ 20.375 public int getScopeNestingLevelTo(final LexicalContextNode until) { 20.376 assert until != null; 20.377 @@ -500,16 +541,17 @@ 20.378 } 20.379 20.380 /** 20.381 - * Check whether the lexical context is currently inside a loop 20.382 - * @return true if inside a loop 20.383 + * Check whether the lexical context is currently inside a loop. 20.384 + * 20.385 + * @return {@code true} if inside a loop 20.386 */ 20.387 public boolean inLoop() { 20.388 return getCurrentLoop() != null; 20.389 } 20.390 20.391 /** 20.392 - * Returns the loop header of the current loop, or null if not inside a loop 20.393 - * @return loop header 20.394 + * @return the loop header of the current loop, or {@code null} if not 20.395 + * inside a loop. 20.396 */ 20.397 public LoopNode getCurrentLoop() { 20.398 final Iterator<LoopNode> iter = new NodeIterator<>(LoopNode.class, getCurrentFunction()); 20.399 @@ -518,9 +560,12 @@ 20.400 20.401 /** 20.402 * Find the breakable node corresponding to this label. 20.403 - * @param labelName name of the label to search for. If null, the closest breakable node will be returned 20.404 - * unconditionally, e.g. a while loop with no label 20.405 - * @return closest breakable node 20.406 + * 20.407 + * @param labelName name of the label to search for. If {@code null}, the 20.408 + * closest breakable node will be returned unconditionally, e.g., a 20.409 + * while loop with no label. 20.410 + * 20.411 + * @return closest breakable node. 20.412 */ 20.413 public BreakableNode getBreakable(final String labelName) { 20.414 if (labelName != null) { 20.415 @@ -544,9 +589,12 @@ 20.416 20.417 /** 20.418 * Find the continue target node corresponding to this label. 20.419 - * @param labelName label name to search for. If null the closest loop node will be returned unconditionally, e.g. a 20.420 - * while loop with no label 20.421 - * @return closest continue target node 20.422 + * 20.423 + * @param labelName label name to search for. If {@code null} the closest 20.424 + * loop node will be returned unconditionally, e.g., a while loop 20.425 + * with no label. 20.426 + * 20.427 + * @return closest continue target node. 20.428 */ 20.429 public LoopNode getContinueTo(final String labelName) { 20.430 if (labelName != null) { 20.431 @@ -566,8 +614,10 @@ 20.432 20.433 /** 20.434 * Find the inlined finally block node corresponding to this label. 20.435 - * @param labelName label name to search for. Must not be null. 20.436 - * @return closest inlined finally block with the given label 20.437 + * 20.438 + * @param labelName label name to search for. Must not be {@code null}. 20.439 + * 20.440 + * @return closest inlined finally block with the given label. 20.441 */ 20.442 public Block getInlinedFinally(final String labelName) { 20.443 for (final NodeIterator<TryNode> iter = new NodeIterator<>(TryNode.class); iter.hasNext(); ) { 20.444 @@ -581,7 +631,9 @@ 20.445 20.446 /** 20.447 * Find the try node for an inlined finally block corresponding to this label. 20.448 - * @param labelName label name to search for. Must not be null. 20.449 + * 20.450 + * @param labelName label name to search for. Must not be {@code null}. 20.451 + * 20.452 * @return the try node to which the labelled inlined finally block belongs. 20.453 */ 20.454 public TryNode getTryNodeForInlinedFinally(final String labelName) { 20.455 @@ -595,9 +647,11 @@ 20.456 } 20.457 20.458 /** 20.459 - * Check the lexical context for a given label node by name 20.460 - * @param name name of the label 20.461 - * @return LabelNode if found, null otherwise 20.462 + * Check the lexical context for a given label node by name. 20.463 + * 20.464 + * @param name name of the label. 20.465 + * 20.466 + * @return LabelNode if found, {@code null} otherwise. 20.467 */ 20.468 public LabelNode findLabel(final String name) { 20.469 for (final Iterator<LabelNode> iter = new NodeIterator<>(LabelNode.class, getCurrentFunction()); iter.hasNext(); ) { 20.470 @@ -610,10 +664,13 @@ 20.471 } 20.472 20.473 /** 20.474 - * Checks whether a given target is a jump destination that lies outside a given split node 20.475 - * @param splitNode the split node 20.476 - * @param target the target node 20.477 - * @return true if target resides outside the split node 20.478 + * Checks whether a given target is a jump destination that lies outside a 20.479 + * given split node. 20.480 + * 20.481 + * @param splitNode the split node. 20.482 + * @param target the target node. 20.483 + * 20.484 + * @return {@code true} if target resides outside the split node. 20.485 */ 20.486 public boolean isExternalTarget(final SplitNode splitNode, final BreakableNode target) { 20.487 for (int i = sp; i-- > 0;) { 20.488 @@ -634,8 +691,10 @@ 20.489 } 20.490 20.491 /** 20.492 - * Checks whether the current context is inside a switch statement without explicit blocks (curly braces). 20.493 - * @return true if in unprotected switch statement 20.494 + * Checks whether the current context is inside a switch statement without 20.495 + * explicit blocks (curly braces). 20.496 + * 20.497 + * @return {@code true} if in unprotected switch statement. 20.498 */ 20.499 public boolean inUnprotectedSwitchContext() { 20.500 for (int i = sp; i > 0; i--) {
21.1 --- a/src/jdk/nashorn/internal/ir/SplitReturn.java Mon Jun 15 11:41:52 2015 -0700 21.2 +++ b/src/jdk/nashorn/internal/ir/SplitReturn.java Wed Jun 17 23:30:09 2015 -0700 21.3 @@ -54,7 +54,7 @@ 21.4 } 21.5 21.6 @Override 21.7 - public void toString(StringBuilder sb, boolean printType) { 21.8 + public void toString(final StringBuilder sb, final boolean printType) { 21.9 sb.append(":splitreturn;"); 21.10 } 21.11
22.1 --- a/src/jdk/nashorn/internal/ir/TryNode.java Mon Jun 15 11:41:52 2015 -0700 22.2 +++ b/src/jdk/nashorn/internal/ir/TryNode.java Wed Jun 17 23:30:09 2015 -0700 22.3 @@ -122,7 +122,7 @@ 22.4 * @param visitor IR navigating visitor. 22.5 */ 22.6 @Override 22.7 - public Node accept(final LexicalContext lc, NodeVisitor<? extends LexicalContext> visitor) { 22.8 + public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) { 22.9 if (visitor.enterTryNode(this)) { 22.10 // Need to do finallybody first for termination analysis. TODO still necessary? 22.11 final Block newFinallyBody = finallyBody == null ? null : (Block)finallyBody.accept(visitor);
23.1 --- a/src/jdk/nashorn/internal/ir/debug/NashornTextifier.java Mon Jun 15 11:41:52 2015 -0700 23.2 +++ b/src/jdk/nashorn/internal/ir/debug/NashornTextifier.java Wed Jun 17 23:30:09 2015 -0700 23.3 @@ -1,5 +1,5 @@ 23.4 /* 23.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 23.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 23.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.8 * 23.9 * This code is free software; you can redistribute it and/or modify it 23.10 @@ -1109,7 +1109,7 @@ 23.11 } 23.12 final String ex = catches.get(node); 23.13 if (ex != null) { 23.14 - sb.append("*** CATCH: ").append(ex).append(" ***\n"); 23.15 + sb.append("*** CATCH: ").append(ex).append(" ***\\l"); 23.16 } 23.17 sb.append(c); 23.18 sb.append("\"]\n");
24.1 --- a/src/jdk/nashorn/internal/objects/Global.java Mon Jun 15 11:41:52 2015 -0700 24.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Wed Jun 17 23:30:09 2015 -0700 24.3 @@ -928,9 +928,11 @@ 24.4 private final Context context; 24.5 24.6 // current ScriptContext to use - can be null. 24.7 - private ScriptContext scontext; 24.8 + private ThreadLocal<ScriptContext> scontext; 24.9 // current ScriptEngine associated - can be null. 24.10 private ScriptEngine engine; 24.11 + // initial ScriptContext - can be null 24.12 + private volatile ScriptContext initscontext; 24.13 24.14 // ES6 global lexical scope. 24.15 private final LexicalScope lexicalScope; 24.16 @@ -940,10 +942,25 @@ 24.17 24.18 /** 24.19 * Set the current script context 24.20 - * @param scontext script context 24.21 + * @param ctxt script context 24.22 */ 24.23 - public void setScriptContext(final ScriptContext scontext) { 24.24 - this.scontext = scontext; 24.25 + public void setScriptContext(final ScriptContext ctxt) { 24.26 + assert scontext != null; 24.27 + scontext.set(ctxt); 24.28 + } 24.29 + 24.30 + /** 24.31 + * Get the current script context 24.32 + * @return current script context 24.33 + */ 24.34 + public ScriptContext getScriptContext() { 24.35 + assert scontext != null; 24.36 + return scontext.get(); 24.37 + } 24.38 + 24.39 + private ScriptContext currentContext() { 24.40 + final ScriptContext sc = scontext != null? scontext.get() : null; 24.41 + return sc == null? initscontext : sc; 24.42 } 24.43 24.44 @Override 24.45 @@ -988,9 +1005,7 @@ 24.46 * @return the global singleton 24.47 */ 24.48 public static Global instance() { 24.49 - final Global global = Context.getGlobal(); 24.50 - Objects.requireNonNull(global); 24.51 - return global; 24.52 + return Objects.requireNonNull(Context.getGlobal()); 24.53 } 24.54 24.55 private static Global instanceFrom(final Object self) { 24.56 @@ -1055,17 +1070,21 @@ 24.57 * as well as our extension builtin objects like "Java", "JSAdapter" as properties 24.58 * of the global scope object. 24.59 * 24.60 - * @param engine ScriptEngine to initialize 24.61 + * @param eng ScriptEngine to initialize 24.62 + * @param ctxt ScriptContext to initialize 24.63 */ 24.64 - @SuppressWarnings("hiding") 24.65 - public void initBuiltinObjects(final ScriptEngine engine) { 24.66 + public void initBuiltinObjects(final ScriptEngine eng, final ScriptContext ctxt) { 24.67 if (this.builtinObject != null) { 24.68 // already initialized, just return 24.69 return; 24.70 } 24.71 24.72 - this.engine = engine; 24.73 - init(engine); 24.74 + this.engine = eng; 24.75 + this.initscontext = ctxt; 24.76 + if (this.engine != null) { 24.77 + this.scontext = new ThreadLocal<>(); 24.78 + } 24.79 + init(eng); 24.80 } 24.81 24.82 /** 24.83 @@ -1393,7 +1412,7 @@ 24.84 */ 24.85 public static Object __noSuchProperty__(final Object self, final Object name) { 24.86 final Global global = Global.instance(); 24.87 - final ScriptContext sctxt = global.scontext; 24.88 + final ScriptContext sctxt = global.currentContext(); 24.89 final String nameStr = name.toString(); 24.90 24.91 if (sctxt != null) { 24.92 @@ -1432,7 +1451,7 @@ 24.93 * @return the result of eval 24.94 */ 24.95 public static Object eval(final Object self, final Object str) { 24.96 - return directEval(self, str, UNDEFINED, UNDEFINED, false); 24.97 + return directEval(self, str, Global.instanceFrom(self), UNDEFINED, false); 24.98 } 24.99 24.100 /** 24.101 @@ -1442,7 +1461,7 @@ 24.102 * @param str Evaluated code 24.103 * @param callThis "this" to be passed to the evaluated code 24.104 * @param location location of the eval call 24.105 - * @param strict is eval called a strict mode code? 24.106 + * @param strict is eval called from a strict mode code? 24.107 * 24.108 * @return the return value of the eval 24.109 * 24.110 @@ -2485,7 +2504,7 @@ 24.111 } 24.112 24.113 @SuppressWarnings("hiding") 24.114 - private void init(final ScriptEngine engine) { 24.115 + private void init(final ScriptEngine eng) { 24.116 assert Context.getGlobal() == this : "this global is not set as current"; 24.117 24.118 final ScriptEnvironment env = getContext().getEnv(); 24.119 @@ -2601,7 +2620,7 @@ 24.120 addOwnProperty("$ARG", Attribute.NOT_ENUMERABLE, arguments); 24.121 } 24.122 24.123 - if (engine != null) { 24.124 + if (eng != null) { 24.125 // default file name 24.126 addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null); 24.127 // __noSuchProperty__ hook for ScriptContext search of missing variables 24.128 @@ -2692,6 +2711,14 @@ 24.129 // Retrieve current state of ENV variables. 24.130 final ScriptObject env = newObject(); 24.131 env.putAll(System.getenv(), scriptEnv._strict); 24.132 + 24.133 + // Some platforms, e.g., Windows, do not define the PWD environment 24.134 + // variable, so that the $ENV.PWD property needs to be explicitly 24.135 + // set. 24.136 + if (!env.containsKey(ScriptingFunctions.PWD_NAME)) { 24.137 + env.put(ScriptingFunctions.PWD_NAME, System.getProperty("user.dir"), scriptEnv._strict); 24.138 + } 24.139 + 24.140 addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env); 24.141 } else { 24.142 addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED); 24.143 @@ -2739,8 +2766,9 @@ 24.144 } 24.145 24.146 private Object printImpl(final boolean newLine, final Object... objects) { 24.147 + final ScriptContext sc = currentContext(); 24.148 @SuppressWarnings("resource") 24.149 - final PrintWriter out = scontext != null? new PrintWriter(scontext.getWriter()) : getContext().getEnv().getOut(); 24.150 + final PrintWriter out = sc != null? new PrintWriter(sc.getWriter()) : getContext().getEnv().getOut(); 24.151 final StringBuilder sb = new StringBuilder(); 24.152 24.153 for (final Object obj : objects) {
25.1 --- a/src/jdk/nashorn/internal/objects/NativeFunction.java Mon Jun 15 11:41:52 2015 -0700 25.2 +++ b/src/jdk/nashorn/internal/objects/NativeFunction.java Wed Jun 17 23:30:09 2015 -0700 25.3 @@ -279,8 +279,8 @@ 25.4 sb.append("})"); 25.5 25.6 final Global global = Global.instance(); 25.7 - 25.8 - return (ScriptFunction)Global.directEval(global, sb.toString(), global, "<function>", global.isStrictContext()); 25.9 + final Context context = global.getContext(); 25.10 + return (ScriptFunction)context.eval(global, sb.toString(), global, "<function>"); 25.11 } 25.12 25.13 private static void checkFunctionParameters(final String params) {
26.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java Mon Jun 15 11:41:52 2015 -0700 26.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java Wed Jun 17 23:30:09 2015 -0700 26.3 @@ -33,10 +33,12 @@ 26.4 import java.util.Collection; 26.5 import java.util.Deque; 26.6 import java.util.List; 26.7 +import java.util.Map; 26.8 import java.util.Queue; 26.9 import jdk.internal.dynalink.beans.StaticClass; 26.10 import jdk.internal.dynalink.support.TypeUtilities; 26.11 import jdk.nashorn.api.scripting.JSObject; 26.12 +import jdk.nashorn.api.scripting.ScriptObjectMirror; 26.13 import jdk.nashorn.internal.objects.annotations.Attribute; 26.14 import jdk.nashorn.internal.objects.annotations.Function; 26.15 import jdk.nashorn.internal.objects.annotations.ScriptClass; 26.16 @@ -656,4 +658,20 @@ 26.17 public static Object _super(final Object self, final Object adapter) { 26.18 return Bootstrap.createSuperAdapter(adapter); 26.19 } 26.20 + 26.21 + /** 26.22 + * Returns an object that is compatible with Java JSON libraries expectations; namely, that if it itself, or any 26.23 + * object transitively reachable through it is a JavaScript array, then such objects will be exposed as 26.24 + * {@link JSObject} that also implements the {@link List} interface for exposing the array elements. An explicit 26.25 + * API is required as otherwise Nashorn exposes all objects externally as {@link JSObject}s that also implement the 26.26 + * {@link Map} interface instead. By using this method, arrays will be exposed as {@link List}s and all other 26.27 + * objects as {@link Map}s. 26.28 + * @param self not used 26.29 + * @param obj the object to be exposed in a Java JSON library compatible manner. 26.30 + * @return a wrapper around the object that will enforce Java JSON library compatible exposure. 26.31 + */ 26.32 + @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 26.33 + public static Object asJSONCompatible(final Object self, final Object obj) { 26.34 + return ScriptObjectMirror.wrapAsJSONCompatible(obj, Context.getGlobal()); 26.35 + } 26.36 }
27.1 --- a/src/jdk/nashorn/internal/objects/annotations/Constructor.java Mon Jun 15 11:41:52 2015 -0700 27.2 +++ b/src/jdk/nashorn/internal/objects/annotations/Constructor.java Wed Jun 17 23:30:09 2015 -0700 27.3 @@ -1,5 +1,5 @@ 27.4 /* 27.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 27.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 27.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.8 * 27.9 * This code is free software; you can redistribute it and/or modify it 27.10 @@ -37,13 +37,15 @@ 27.11 @Target(ElementType.METHOD) 27.12 public @interface Constructor { 27.13 /** 27.14 - * Name of the constructor function. If empty, the name is inferred. 27.15 + * @return the name of the constructor function. If empty, the name is 27.16 + * inferred. 27.17 */ 27.18 public String name() default ""; 27.19 27.20 /** 27.21 - * The arity of the function. By default computed from the method signature. 27.22 - * Note that -1 means varargs. So, -2 is used as invalid arity. 27.23 + * @return the arity of the function. By default computed from the method 27.24 + * signature. Note that -1 means varargs. So, -2 is used as invalid 27.25 + * arity. 27.26 */ 27.27 public int arity() default -2; 27.28 }
28.1 --- a/src/jdk/nashorn/internal/objects/annotations/Function.java Mon Jun 15 11:41:52 2015 -0700 28.2 +++ b/src/jdk/nashorn/internal/objects/annotations/Function.java Wed Jun 17 23:30:09 2015 -0700 28.3 @@ -1,5 +1,5 @@ 28.4 /* 28.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 28.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.8 * 28.9 * This code is free software; you can redistribute it and/or modify it 28.10 @@ -41,22 +41,23 @@ 28.11 @Target(ElementType.METHOD) 28.12 public @interface Function { 28.13 /** 28.14 - * Name of the property. If empty, the name is inferred. 28.15 + * @return the name of the property. If empty, the name is inferred. 28.16 */ 28.17 public String name() default ""; 28.18 28.19 /** 28.20 - * Attribute flags for this function. 28.21 + * @return the attribute flags for this function. 28.22 */ 28.23 public int attributes() default DEFAULT_ATTRIBUTES; 28.24 28.25 /** 28.26 - * The arity of the function. By default computed from the method signature 28.27 + * @return the arity of the function. By default computed from the method 28.28 + * signature. 28.29 */ 28.30 public int arity() default -2; 28.31 28.32 /** 28.33 - * where this function lives 28.34 + * @return where this function lives. 28.35 */ 28.36 public Where where() default Where.PROTOTYPE; 28.37 }
29.1 --- a/src/jdk/nashorn/internal/objects/annotations/Getter.java Mon Jun 15 11:41:52 2015 -0700 29.2 +++ b/src/jdk/nashorn/internal/objects/annotations/Getter.java Wed Jun 17 23:30:09 2015 -0700 29.3 @@ -1,5 +1,5 @@ 29.4 /* 29.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 29.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 29.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.8 * 29.9 * This code is free software; you can redistribute it and/or modify it 29.10 @@ -39,17 +39,17 @@ 29.11 @Target(ElementType.METHOD) 29.12 public @interface Getter { 29.13 /** 29.14 - * Name of the property. If empty, the name is inferred. 29.15 + * @return the name of the property. If empty, the name is inferred. 29.16 */ 29.17 public String name() default ""; 29.18 29.19 /** 29.20 - * Attribute flags for this setter. 29.21 + * @return the attribute flags for this setter. 29.22 */ 29.23 public int attributes() default DEFAULT_ATTRIBUTES; 29.24 29.25 /** 29.26 - * Where this getter lives? 29.27 + * @return where this getter lives. 29.28 */ 29.29 public Where where() default Where.INSTANCE; 29.30 }
30.1 --- a/src/jdk/nashorn/internal/objects/annotations/ScriptClass.java Mon Jun 15 11:41:52 2015 -0700 30.2 +++ b/src/jdk/nashorn/internal/objects/annotations/ScriptClass.java Wed Jun 17 23:30:09 2015 -0700 30.3 @@ -1,5 +1,5 @@ 30.4 /* 30.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 30.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 30.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.8 * 30.9 * This code is free software; you can redistribute it and/or modify it 30.10 @@ -37,8 +37,8 @@ 30.11 @Target(ElementType.TYPE) 30.12 public @interface ScriptClass { 30.13 /** 30.14 - * Name of the script class. By default, the name is derived from 30.15 - * the Java class name. 30.16 + * @return the name of the script class. By default, the name is derived 30.17 + * from the Java class name. 30.18 */ 30.19 public String value() default ""; 30.20 }
31.1 --- a/src/jdk/nashorn/internal/objects/annotations/Setter.java Mon Jun 15 11:41:52 2015 -0700 31.2 +++ b/src/jdk/nashorn/internal/objects/annotations/Setter.java Wed Jun 17 23:30:09 2015 -0700 31.3 @@ -1,5 +1,5 @@ 31.4 /* 31.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 31.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 31.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.8 * 31.9 * This code is free software; you can redistribute it and/or modify it 31.10 @@ -39,17 +39,17 @@ 31.11 @Target(ElementType.METHOD) 31.12 public @interface Setter { 31.13 /** 31.14 - * Name of the script property. If empty, the name is inferred. 31.15 + * @return the name of the script property. If empty, the name is inferred. 31.16 */ 31.17 public String name() default ""; 31.18 31.19 /** 31.20 - * Attribute flags for this setter. 31.21 + * @return the attribute flags for this setter. 31.22 */ 31.23 public int attributes() default DEFAULT_ATTRIBUTES; 31.24 31.25 /** 31.26 - * Where this setter lives? 31.27 + * @return where this setter lives. 31.28 */ 31.29 public Where where() default Where.INSTANCE; 31.30 }
32.1 --- a/src/jdk/nashorn/internal/objects/annotations/SpecializedFunction.java Mon Jun 15 11:41:52 2015 -0700 32.2 +++ b/src/jdk/nashorn/internal/objects/annotations/SpecializedFunction.java Wed Jun 17 23:30:09 2015 -0700 32.3 @@ -1,5 +1,5 @@ 32.4 /* 32.5 - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 32.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 32.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.8 * 32.9 * This code is free software; you can redistribute it and/or modify it 32.10 @@ -33,10 +33,11 @@ 32.11 import jdk.internal.dynalink.CallSiteDescriptor; 32.12 import jdk.internal.dynalink.linker.LinkRequest; 32.13 import jdk.nashorn.internal.runtime.ScriptFunction; 32.14 +import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; 32.15 32.16 /** 32.17 * The SpecializedFunction annotation is used to flag more type specific 32.18 - * functions than the standard one in the native objects 32.19 + * functions than the standard one in the native objects. 32.20 */ 32.21 @Retention(RetentionPolicy.RUNTIME) 32.22 @Target(ElementType.METHOD) 32.23 @@ -45,23 +46,23 @@ 32.24 /** 32.25 * Functionality for testing if we are allowed to link a specialized 32.26 * function the first time we encounter it. Then the guard will handle the 32.27 - * rest of the invocations 32.28 + * rest of the invocations. 32.29 * 32.30 - * This is the same for all callsites in Nashorn, the first time callsite is 32.31 + * This is the same for all callsites in Nashorn; the first time a callsite is 32.32 * linked, we have to manually check that the linkage is OK. Even if we add 32.33 * a guard and it fails upon the first try, this is not good enough. 32.34 - * (Symmetrical to how it works everywhere else in the Nashorn runtime). 32.35 + * (Symmetrical to how it works everywhere else in the Nashorn runtime.) 32.36 * 32.37 * Here we abstract out a few of the most common link guard checks. 32.38 */ 32.39 public static abstract class LinkLogic { 32.40 /** 32.41 - * Empty link logic instance - this is the default 32.42 + * Empty link logic instance - this is the default. 32.43 * "no special linking or runtime guard behavior" 32.44 */ 32.45 public static final LinkLogic EMPTY_INSTANCE = new Empty(); 32.46 32.47 - /** Empty link logic class - allow all linking, no guards */ 32.48 + /** Empty link logic class - allow all linking, no guards. */ 32.49 private static final class Empty extends LinkLogic { 32.50 @Override 32.51 public boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request) { 32.52 @@ -75,7 +76,8 @@ 32.53 } 32.54 32.55 /** 32.56 - * Get the class representing the empty link logic 32.57 + * Get the class representing the empty link logic. 32.58 + * 32.59 * @return class representing empty link logic 32.60 */ 32.61 public static Class<? extends LinkLogic> getEmptyLinkLogicClass() { 32.62 @@ -83,31 +85,31 @@ 32.63 } 32.64 32.65 /** 32.66 - * Should this callsite relink when an exception is thrown 32.67 + * Should this callsite relink when an exception is thrown? 32.68 * 32.69 - * @return the relink exception, or null if none 32.70 + * @return the relink exception, or {@code null} if none 32.71 */ 32.72 public Class<? extends Throwable> getRelinkException() { 32.73 return null; 32.74 } 32.75 32.76 /** 32.77 - * Is this link logic class empty - i.e. no special linking logic 32.78 - * supplied 32.79 + * Is this link logic class empty - i.e., no special linking logic 32.80 + * supplied? 32.81 * 32.82 * @param clazz class to check 32.83 * 32.84 - * @return true if this link logic is empty 32.85 + * @return {@code true} if this link logic is empty 32.86 */ 32.87 public static boolean isEmpty(final Class<? extends LinkLogic> clazz) { 32.88 return clazz == Empty.class; 32.89 } 32.90 32.91 /** 32.92 - * Is this link logic instance empty - i.e. no special linking logic 32.93 - * supplied 32.94 + * Is this link logic instance empty - i.e., no special linking logic 32.95 + * supplied? 32.96 * 32.97 - * @return true if this link logic instance is empty 32.98 + * @return {@code true} if this link logic instance is empty 32.99 */ 32.100 public boolean isEmpty() { 32.101 return false; 32.102 @@ -121,7 +123,7 @@ 32.103 * @param desc callsite descriptor 32.104 * @param request link request 32.105 * 32.106 - * @return true if we can link this callsite at this time 32.107 + * @return {@code true} if we can link this callsite at this time 32.108 */ 32.109 public abstract boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request); 32.110 32.111 @@ -131,7 +133,7 @@ 32.112 * 32.113 * @param self receiver 32.114 * 32.115 - * @return true if a guard is to be woven into the callsite 32.116 + * @return {@code true} if a guard is to be woven into the callsite 32.117 */ 32.118 public boolean needsGuard(final Object self) { 32.119 return true; 32.120 @@ -139,13 +141,13 @@ 32.121 32.122 /** 32.123 * Given a callsite, and optional arguments, do we need an extra guard 32.124 - * for specialization to go through - this guard can be a function of 32.125 - * the arguments too 32.126 + * for specialization to go through? This guard can be a function of 32.127 + * the arguments too. 32.128 * 32.129 * @param self receiver 32.130 * @param args arguments 32.131 * 32.132 - * @return true if a guard is to be woven into the callsite 32.133 + * @return {@code true} if a guard is to be woven into the callsite 32.134 */ 32.135 public boolean needsGuard(final Object self, final Object... args) { 32.136 return true; 32.137 @@ -169,9 +171,9 @@ 32.138 * @param self receiver 32.139 * @param desc callsite descriptor 32.140 * @param request link request 32.141 - 32.142 - * @return true if we can link, false otherwise - that means we have to 32.143 - * pick a non specialized target 32.144 + * 32.145 + * @return {@code true} if we can link, {@code false} otherwise - that 32.146 + * means we have to pick a non specialized target 32.147 */ 32.148 public boolean checkLinkable(final Object self, final CallSiteDescriptor desc, final LinkRequest request) { 32.149 // check the link guard, if it says we can link, go ahead 32.150 @@ -180,11 +182,11 @@ 32.151 } 32.152 32.153 /** 32.154 - * name override for return value polymorphism, for example we can't have 32.155 + * Name override for return value polymorphism, for example we can't have 32.156 * pop(V)I and pop(V)D in the same Java class, so they need to be named, 32.157 - * e.g. popInt(V)I and popDouble(V)D for disambiguation, however, their 32.158 + * e.g., popInt(V)I and popDouble(V)D for disambiguation, however, their 32.159 * names still need to resolve to "pop" to JavaScript so we can still 32.160 - * specialize on return values and so that the linker can find them 32.161 + * specialize on return values and so that the linker can find them. 32.162 * 32.163 * @return name, "" means no override, use the Java function name, e.g. 32.164 * "push" 32.165 @@ -199,16 +201,18 @@ 32.166 Class<?> linkLogic() default LinkLogic.Empty.class; 32.167 32.168 /** 32.169 - * Is this a specialized constructor? 32.170 + * @return whether this is a specialized constructor. 32.171 */ 32.172 boolean isConstructor() default false; 32.173 32.174 /** 32.175 - * Can this function throw UnwarrantedOptimismExceptions? This works just 32.176 - * like the normal functions, but we need the function to be 32.177 + * Can this function throw {@link UnwarrantedOptimismException}s? This works 32.178 + * just like the normal functions, but we need the function to be 32.179 * immutable/non-state modifying, as we can't generate continuations for 32.180 * native code. Luckily a lot of the methods we want to specialize have this 32.181 - * property 32.182 + * property. 32.183 + * 32.184 + * @return whether this function can throw {@link UnwarrantedOptimismException}. 32.185 */ 32.186 boolean isOptimistic() default false; 32.187 }
33.1 --- a/src/jdk/nashorn/internal/parser/JSONParser.java Mon Jun 15 11:41:52 2015 -0700 33.2 +++ b/src/jdk/nashorn/internal/parser/JSONParser.java Wed Jun 17 23:30:09 2015 -0700 33.3 @@ -47,7 +47,8 @@ 33.4 import static jdk.nashorn.internal.parser.TokenType.STRING; 33.5 33.6 /** 33.7 - * Parses JSON text and returns the corresponding IR node. This is derived from the objectLiteral production of the main parser. 33.8 + * Parses JSON text and returns the corresponding IR node. This is derived from 33.9 + * the objectLiteral production of the main parser. 33.10 * 33.11 * See: 15.12.1.2 The JSON Syntactic Grammar 33.12 */ 33.13 @@ -70,9 +71,11 @@ 33.14 private static final int STATE_COMMA_PARSED = 2; 33.15 33.16 /** 33.17 - * Constructor 33.18 - * @param source the source 33.19 - * @param global the global object 33.20 + * Constructor. 33.21 + * 33.22 + * @param source the source 33.23 + * @param global the global object 33.24 + * @param dualFields whether the parser should regard dual field representation 33.25 */ 33.26 public JSONParser(final String source, final Global global, final boolean dualFields) { 33.27 this.source = source; 33.28 @@ -82,8 +85,9 @@ 33.29 } 33.30 33.31 /** 33.32 - * Implementation of the Quote(value) operation as defined in the ECMA script spec 33.33 - * It wraps a String value in double quotes and escapes characters within in 33.34 + * Implementation of the Quote(value) operation as defined in the ECMAscript 33.35 + * spec. It wraps a String value in double quotes and escapes characters 33.36 + * within. 33.37 * 33.38 * @param value string to quote 33.39 *
34.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Mon Jun 15 11:41:52 2015 -0700 34.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Wed Jun 17 23:30:09 2015 -0700 34.3 @@ -2635,8 +2635,12 @@ 34.4 name = getIdent(); 34.5 verifyStrictIdent(name, "function name"); 34.6 } else if (isStatement) { 34.7 - // Nashorn extension: anonymous function statements 34.8 - if (env._no_syntax_extensions) { 34.9 + // Nashorn extension: anonymous function statements. 34.10 + // Do not allow anonymous function statement if extensions 34.11 + // are now allowed. But if we are reparsing then anon function 34.12 + // statement is possible - because it was used as function 34.13 + // expression in surrounding code. 34.14 + if (env._no_syntax_extensions && reparsedFunction == null) { 34.15 expect(IDENT); 34.16 } 34.17 }
35.1 --- a/src/jdk/nashorn/internal/parser/TokenType.java Mon Jun 15 11:41:52 2015 -0700 35.2 +++ b/src/jdk/nashorn/internal/parser/TokenType.java Wed Jun 17 23:30:09 2015 -0700 35.3 @@ -1,5 +1,5 @@ 35.4 /* 35.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 35.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 35.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.8 * 35.9 * This code is free software; you can redistribute it and/or modify it 35.10 @@ -222,9 +222,11 @@ 35.11 35.12 /** 35.13 * Determines if the token has greater precedence than other. 35.14 + * 35.15 * @param other Compare token. 35.16 * @param isLeft Is to the left of the other. 35.17 - * @return True if greater precedence. 35.18 + * 35.19 + * @return {@code true} if greater precedence. 35.20 */ 35.21 public boolean needsParens(final TokenType other, final boolean isLeft) { 35.22 return other.precedence != 0 && 35.23 @@ -234,16 +236,16 @@ 35.24 35.25 /** 35.26 * Determines if the type is a valid operator. 35.27 - * @param noIn TRUE if IN operator should be ignored. 35.28 - * @return TRUE if valid operator. 35.29 + * 35.30 + * @param noIn {@code true} if IN operator should be ignored. 35.31 + * 35.32 + * @return {@code true} if valid operator. 35.33 */ 35.34 public boolean isOperator(final boolean noIn) { 35.35 return kind == BINARY && (!noIn || this != IN) && precedence != 0; 35.36 } 35.37 35.38 - /** 35.39 - * Accessors. 35.40 - */ 35.41 + 35.42 public int getLength() { 35.43 assert name != null : "Token name not set"; 35.44 return name.length();
36.1 --- a/src/jdk/nashorn/internal/runtime/CompiledFunction.java Mon Jun 15 11:41:52 2015 -0700 36.2 +++ b/src/jdk/nashorn/internal/runtime/CompiledFunction.java Wed Jun 17 23:30:09 2015 -0700 36.3 @@ -528,8 +528,9 @@ 36.4 36.5 final int fnParamCountNoCallee = fnParamCount - thisThisIndex; 36.6 final int minParams = Math.min(csParamCount - 1, fnParamCountNoCallee); // callSiteType always has callee, so subtract 1 36.7 - // We must match all incoming parameters, except "this". Starting from 1 to skip "this". 36.8 - for(int i = 1; i < minParams; ++i) { 36.9 + // We must match all incoming parameters, including "this". "this" will usually be Object, but there 36.10 + // are exceptions, e.g. when calling functions with primitive "this" in strict mode or through call/apply. 36.11 + for(int i = 0; i < minParams; ++i) { 36.12 final Type fnType = Type.typeFor(type.parameterType(i + thisThisIndex)); 36.13 final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(other.parameterType(i + 1)); 36.14 if(!fnType.isEquivalentTo(csType)) {
37.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Mon Jun 15 11:41:52 2015 -0700 37.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Wed Jun 17 23:30:09 2015 -0700 37.3 @@ -66,6 +66,7 @@ 37.4 import java.util.function.Consumer; 37.5 import java.util.function.Supplier; 37.6 import java.util.logging.Level; 37.7 +import javax.script.ScriptContext; 37.8 import javax.script.ScriptEngine; 37.9 import jdk.internal.org.objectweb.asm.ClassReader; 37.10 import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; 37.11 @@ -667,12 +668,11 @@ 37.12 * @param string Evaluated code as a String 37.13 * @param callThis "this" to be passed to the evaluated code 37.14 * @param location location of the eval call 37.15 - * @param strict is this {@code eval} call from a strict mode code? 37.16 * @return the return value of the {@code eval} 37.17 */ 37.18 public Object eval(final ScriptObject initialScope, final String string, 37.19 - final Object callThis, final Object location, final boolean strict) { 37.20 - return eval(initialScope, string, callThis, location, strict, false); 37.21 + final Object callThis, final Object location) { 37.22 + return eval(initialScope, string, callThis, location, false, false); 37.23 } 37.24 37.25 /** 37.26 @@ -691,14 +691,16 @@ 37.27 final Object callThis, final Object location, final boolean strict, final boolean evalCall) { 37.28 final String file = location == UNDEFINED || location == null ? "<eval>" : location.toString(); 37.29 final Source source = sourceFor(file, string, evalCall); 37.30 - final boolean directEval = location != UNDEFINED; // is this direct 'eval' call or indirectly invoked eval? 37.31 + // is this direct 'eval' builtin call? 37.32 + final boolean directEval = evalCall && (location != UNDEFINED); 37.33 final Global global = Context.getGlobal(); 37.34 ScriptObject scope = initialScope; 37.35 37.36 // ECMA section 10.1.1 point 2 says eval code is strict if it begins 37.37 // with "use strict" directive or eval direct call itself is made 37.38 // from from strict mode code. We are passed with caller's strict mode. 37.39 - boolean strictFlag = directEval && strict; 37.40 + // Nashorn extension: any 'eval' is unconditionally strict when -strict is specified. 37.41 + boolean strictFlag = strict || this._strict; 37.42 37.43 Class<?> clazz = null; 37.44 try { 37.45 @@ -739,7 +741,8 @@ 37.46 if (directEval) { 37.47 evalThis = (callThis != UNDEFINED && callThis != null) || strictFlag ? callThis : global; 37.48 } else { 37.49 - evalThis = global; 37.50 + // either indirect evalCall or non-eval (Function, engine.eval, ScriptObjectMirror.eval..) 37.51 + evalThis = callThis; 37.52 } 37.53 37.54 return ScriptRuntime.apply(func, evalThis); 37.55 @@ -1095,16 +1098,17 @@ 37.56 * 37.57 * @param global the global 37.58 * @param engine the associated ScriptEngine instance, can be null 37.59 + * @param ctxt the initial ScriptContext, can be null 37.60 * @return the initialized global scope object. 37.61 */ 37.62 - public Global initGlobal(final Global global, final ScriptEngine engine) { 37.63 + public Global initGlobal(final Global global, final ScriptEngine engine, final ScriptContext ctxt) { 37.64 // Need only minimal global object, if we are just compiling. 37.65 if (!env._compile_only) { 37.66 final Global oldGlobal = Context.getGlobal(); 37.67 try { 37.68 Context.setGlobal(global); 37.69 // initialize global scope with builtin global objects 37.70 - global.initBuiltinObjects(engine); 37.71 + global.initBuiltinObjects(engine, ctxt); 37.72 } finally { 37.73 Context.setGlobal(oldGlobal); 37.74 } 37.75 @@ -1120,7 +1124,7 @@ 37.76 * @return the initialized global scope object. 37.77 */ 37.78 public Global initGlobal(final Global global) { 37.79 - return initGlobal(global, null); 37.80 + return initGlobal(global, null, null); 37.81 } 37.82 37.83 /**
38.1 --- a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Mon Jun 15 11:41:52 2015 -0700 38.2 +++ b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Wed Jun 17 23:30:09 2015 -0700 38.3 @@ -156,7 +156,7 @@ 38.4 final Context context = global.getContext(); 38.5 38.6 try { 38.7 - return context.eval(initialScope, string, callThis, ScriptRuntime.UNDEFINED, false); 38.8 + return context.eval(initialScope, string, callThis, ScriptRuntime.UNDEFINED); 38.9 } catch (final Throwable ex) { 38.10 return returnException ? ex : null; 38.11 }
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/src/jdk/nashorn/internal/runtime/JSONListAdapter.java Wed Jun 17 23:30:09 2015 -0700 39.3 @@ -0,0 +1,169 @@ 39.4 +/* 39.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. Oracle designates this 39.11 + * particular file as subject to the "Classpath" exception as provided 39.12 + * by Oracle in the LICENSE file that accompanied this code. 39.13 + * 39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.17 + * version 2 for more details (a copy is included in the LICENSE file that 39.18 + * accompanied this code). 39.19 + * 39.20 + * You should have received a copy of the GNU General Public License version 39.21 + * 2 along with this work; if not, write to the Free Software Foundation, 39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.23 + * 39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.25 + * or visit www.oracle.com if you need additional information or have any 39.26 + * questions. 39.27 + */ 39.28 + 39.29 +package jdk.nashorn.internal.runtime; 39.30 + 39.31 +import java.util.Collection; 39.32 +import java.util.List; 39.33 +import java.util.Set; 39.34 +import jdk.nashorn.api.scripting.AbstractJSObject; 39.35 +import jdk.nashorn.api.scripting.JSObject; 39.36 +import jdk.nashorn.api.scripting.ScriptObjectMirror; 39.37 +import jdk.nashorn.internal.objects.Global; 39.38 + 39.39 +/** 39.40 + * A {@link ListAdapter} that also implements {@link JSObject}. Named {@code JSONListAdapter} as it is used as a 39.41 + * {@code JSObject} implementing the {@link List} interface, which is the expected interface to be implemented by 39.42 + * JSON-parsed arrays when they are handled in Java. We aren't implementing {@link JSObject} on {@link ListAdapter} 39.43 + * directly since that'd have implications for other uses of list adapter (e.g. interferences of JSObject default 39.44 + * value calculation vs. List's {@code toString()} etc.) 39.45 + */ 39.46 +public final class JSONListAdapter extends ListAdapter implements JSObject { 39.47 + /** 39.48 + * Creates a new JSON list adapter. 39.49 + * @param obj the underlying object being exposed as a list. 39.50 + * @param global the home global of the underlying object. 39.51 + */ 39.52 + public JSONListAdapter(final JSObject obj, final Global global) { 39.53 + super(obj, global); 39.54 + } 39.55 + 39.56 + /** 39.57 + * Unwraps this adapter into its underlying non-JSObject representative. 39.58 + * @param homeGlobal the home global for unwrapping 39.59 + * @return either the unwrapped object or this if it should not be unwrapped in the specified global. 39.60 + */ 39.61 + public Object unwrap(final Object homeGlobal) { 39.62 + final Object unwrapped = ScriptObjectMirror.unwrap(obj, homeGlobal); 39.63 + return unwrapped != obj ? unwrapped : this; 39.64 + } 39.65 + 39.66 + @Override 39.67 + public Object call(final Object thiz, final Object... args) { 39.68 + return obj.call(thiz, args); 39.69 + } 39.70 + 39.71 + @Override 39.72 + public Object newObject(final Object... args) { 39.73 + return obj.newObject(args); 39.74 + } 39.75 + 39.76 + @Override 39.77 + public Object eval(final String s) { 39.78 + return obj.eval(s); 39.79 + } 39.80 + 39.81 + @Override 39.82 + public Object getMember(final String name) { 39.83 + return obj.getMember(name); 39.84 + } 39.85 + 39.86 + @Override 39.87 + public Object getSlot(final int index) { 39.88 + return obj.getSlot(index); 39.89 + } 39.90 + 39.91 + @Override 39.92 + public boolean hasMember(final String name) { 39.93 + return obj.hasMember(name); 39.94 + } 39.95 + 39.96 + @Override 39.97 + public boolean hasSlot(final int slot) { 39.98 + return obj.hasSlot(slot); 39.99 + } 39.100 + 39.101 + @Override 39.102 + public void removeMember(final String name) { 39.103 + obj.removeMember(name); 39.104 + } 39.105 + 39.106 + @Override 39.107 + public void setMember(final String name, final Object value) { 39.108 + obj.setMember(name, value); 39.109 + } 39.110 + 39.111 + @Override 39.112 + public void setSlot(final int index, final Object value) { 39.113 + obj.setSlot(index, value); 39.114 + } 39.115 + 39.116 + @Override 39.117 + public Set<String> keySet() { 39.118 + return obj.keySet(); 39.119 + } 39.120 + 39.121 + @Override 39.122 + public Collection<Object> values() { 39.123 + return obj.values(); 39.124 + } 39.125 + 39.126 + @Override 39.127 + public boolean isInstance(final Object instance) { 39.128 + return obj.isInstance(instance); 39.129 + } 39.130 + 39.131 + @Override 39.132 + public boolean isInstanceOf(final Object clazz) { 39.133 + return obj.isInstanceOf(clazz); 39.134 + } 39.135 + 39.136 + @Override 39.137 + public String getClassName() { 39.138 + return obj.getClassName(); 39.139 + } 39.140 + 39.141 + @Override 39.142 + public boolean isFunction() { 39.143 + return obj.isFunction(); 39.144 + } 39.145 + 39.146 + @Override 39.147 + public boolean isStrictFunction() { 39.148 + return obj.isStrictFunction(); 39.149 + } 39.150 + 39.151 + @Override 39.152 + public boolean isArray() { 39.153 + return obj.isArray(); 39.154 + } 39.155 + 39.156 + @Override @Deprecated 39.157 + public double toNumber() { 39.158 + return obj.toNumber(); 39.159 + } 39.160 + 39.161 + /** 39.162 + * Implements this object's {@code [[DefaultValue]]} method by returning its wrapped object's {@code [[DefaultValue]]}. 39.163 + * 39.164 + * @param hint the type hint. Should be either {@code null}, {@code Number.class} or {@code String.class}. 39.165 + * @return the wrapped object's default value. 39.166 + * @throws UnsupportedOperationException if the conversion can't be performed. The engine will convert this 39.167 + * exception into a JavaScript {@code TypeError}. 39.168 + */ 39.169 + public Object getDefaultValue(final Class<?> hint) { 39.170 + return AbstractJSObject.getDefaultValue(obj, hint); 39.171 + } 39.172 +}
40.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Mon Jun 15 11:41:52 2015 -0700 40.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Wed Jun 17 23:30:09 2015 -0700 40.3 @@ -36,6 +36,7 @@ 40.4 import java.util.concurrent.Callable; 40.5 import jdk.nashorn.api.scripting.JSObject; 40.6 import jdk.nashorn.api.scripting.ScriptObjectMirror; 40.7 +import jdk.nashorn.internal.objects.Global; 40.8 import jdk.nashorn.internal.runtime.linker.Bootstrap; 40.9 40.10 /** 40.11 @@ -51,57 +52,43 @@ 40.12 * operations respectively, while {@link #addLast(Object)} and {@link #removeLast()} will translate to {@code push} and 40.13 * {@code pop}. 40.14 */ 40.15 -public final class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 40.16 +public class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 40.17 // Invoker creator for methods that add to the start or end of the list: PUSH and UNSHIFT. Takes fn, this, and value, returns void. 40.18 private static final Callable<MethodHandle> ADD_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, Object.class); 40.19 40.20 - // PUSH adds to the end of the list 40.21 + // PUSH adds to the start of the list 40.22 private static final Object PUSH = new Object(); 40.23 - private static MethodHandle getPushInvoker() { 40.24 - return getDynamicInvoker(PUSH, ADD_INVOKER_CREATOR); 40.25 - } 40.26 - 40.27 - // UNSHIFT adds to the start of the list 40.28 + // UNSHIFT adds to the end of the list 40.29 private static final Object UNSHIFT = new Object(); 40.30 - private static MethodHandle getUnshiftInvoker() { 40.31 - return getDynamicInvoker(UNSHIFT, ADD_INVOKER_CREATOR); 40.32 - } 40.33 40.34 // Invoker creator for methods that remove from the tail or head of the list: POP and SHIFT. Takes fn, this, returns Object. 40.35 private static final Callable<MethodHandle> REMOVE_INVOKER_CREATOR = invokerCreator(Object.class, Object.class, JSObject.class); 40.36 40.37 - // POP removes from the to the end of the list 40.38 + // POP removes from the start of the list 40.39 private static final Object POP = new Object(); 40.40 - private static MethodHandle getPopInvoker() { 40.41 - return getDynamicInvoker(POP, REMOVE_INVOKER_CREATOR); 40.42 - } 40.43 - 40.44 - // SHIFT removes from the to the start of the list 40.45 + // SHIFT removes from the end of the list 40.46 private static final Object SHIFT = new Object(); 40.47 - private static MethodHandle getShiftInvoker() { 40.48 - return getDynamicInvoker(SHIFT, REMOVE_INVOKER_CREATOR); 40.49 - } 40.50 40.51 // SPLICE can be used to add a value in the middle of the list. 40.52 private static final Object SPLICE_ADD = new Object(); 40.53 private static final Callable<MethodHandle> SPLICE_ADD_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, int.class, int.class, Object.class); 40.54 - private static MethodHandle getSpliceAddInvoker() { 40.55 - return getDynamicInvoker(SPLICE_ADD, SPLICE_ADD_INVOKER_CREATOR); 40.56 - } 40.57 40.58 // SPLICE can also be used to remove values from the middle of the list. 40.59 private static final Object SPLICE_REMOVE = new Object(); 40.60 private static final Callable<MethodHandle> SPLICE_REMOVE_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, int.class, int.class); 40.61 - private static MethodHandle getSpliceRemoveInvoker() { 40.62 - return getDynamicInvoker(SPLICE_REMOVE, SPLICE_REMOVE_INVOKER_CREATOR); 40.63 - } 40.64 40.65 /** wrapped object */ 40.66 - protected final JSObject obj; 40.67 + final JSObject obj; 40.68 + private final Global global; 40.69 40.70 // allow subclasses only in this package 40.71 - ListAdapter(final JSObject obj) { 40.72 + ListAdapter(final JSObject obj, final Global global) { 40.73 + if (global == null) { 40.74 + throw new IllegalStateException(ECMAErrors.getMessage("list.adapter.null.global")); 40.75 + } 40.76 + 40.77 this.obj = obj; 40.78 + this.global = global; 40.79 } 40.80 40.81 /** 40.82 @@ -111,12 +98,13 @@ 40.83 * @return A ListAdapter wrapper object 40.84 */ 40.85 public static ListAdapter create(final Object obj) { 40.86 - return new ListAdapter(getJSObject(obj)); 40.87 + final Global global = Context.getGlobal(); 40.88 + return new ListAdapter(getJSObject(obj, global), global); 40.89 } 40.90 40.91 - private static JSObject getJSObject(final Object obj) { 40.92 + private static JSObject getJSObject(final Object obj, final Global global) { 40.93 if (obj instanceof ScriptObject) { 40.94 - return (JSObject)ScriptObjectMirror.wrap(obj, Context.getGlobal()); 40.95 + return (JSObject)ScriptObjectMirror.wrap(obj, global); 40.96 } else if (obj instanceof JSObject) { 40.97 return (JSObject)obj; 40.98 } 40.99 @@ -166,7 +154,7 @@ 40.100 @Override 40.101 public final void addFirst(final Object e) { 40.102 try { 40.103 - getUnshiftInvoker().invokeExact(getFunction("unshift"), obj, e); 40.104 + getDynamicInvoker(UNSHIFT, ADD_INVOKER_CREATOR).invokeExact(getFunction("unshift"), obj, e); 40.105 } catch(RuntimeException | Error ex) { 40.106 throw ex; 40.107 } catch(final Throwable t) { 40.108 @@ -177,7 +165,7 @@ 40.109 @Override 40.110 public final void addLast(final Object e) { 40.111 try { 40.112 - getPushInvoker().invokeExact(getFunction("push"), obj, e); 40.113 + getDynamicInvoker(PUSH, ADD_INVOKER_CREATOR).invokeExact(getFunction("push"), obj, e); 40.114 } catch(RuntimeException | Error ex) { 40.115 throw ex; 40.116 } catch(final Throwable t) { 40.117 @@ -195,7 +183,7 @@ 40.118 } else { 40.119 final int size = size(); 40.120 if(index < size) { 40.121 - getSpliceAddInvoker().invokeExact(obj.getMember("splice"), obj, index, 0, e); 40.122 + getDynamicInvoker(SPLICE_ADD, SPLICE_ADD_INVOKER_CREATOR).invokeExact(obj.getMember("splice"), obj, index, 0, e); 40.123 } else if(index == size) { 40.124 addLast(e); 40.125 } else { 40.126 @@ -287,7 +275,7 @@ 40.127 40.128 private Object invokeShift() { 40.129 try { 40.130 - return getShiftInvoker().invokeExact(getFunction("shift"), obj); 40.131 + return getDynamicInvoker(SHIFT, REMOVE_INVOKER_CREATOR).invokeExact(getFunction("shift"), obj); 40.132 } catch(RuntimeException | Error ex) { 40.133 throw ex; 40.134 } catch(final Throwable t) { 40.135 @@ -297,7 +285,7 @@ 40.136 40.137 private Object invokePop() { 40.138 try { 40.139 - return getPopInvoker().invokeExact(getFunction("pop"), obj); 40.140 + return getDynamicInvoker(POP, REMOVE_INVOKER_CREATOR).invokeExact(getFunction("pop"), obj); 40.141 } catch(RuntimeException | Error ex) { 40.142 throw ex; 40.143 } catch(final Throwable t) { 40.144 @@ -312,7 +300,7 @@ 40.145 40.146 private void invokeSpliceRemove(final int fromIndex, final int count) { 40.147 try { 40.148 - getSpliceRemoveInvoker().invokeExact(getFunction("splice"), obj, fromIndex, count); 40.149 + getDynamicInvoker(SPLICE_REMOVE, SPLICE_REMOVE_INVOKER_CREATOR).invokeExact(getFunction("splice"), obj, fromIndex, count); 40.150 } catch(RuntimeException | Error ex) { 40.151 throw ex; 40.152 } catch(final Throwable t) { 40.153 @@ -417,7 +405,7 @@ 40.154 }; 40.155 } 40.156 40.157 - private static MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 40.158 - return Context.getGlobal().getDynamicInvoker(key, creator); 40.159 + private MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 40.160 + return global.getDynamicInvoker(key, creator); 40.161 } 40.162 }
41.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Mon Jun 15 11:41:52 2015 -0700 41.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Wed Jun 17 23:30:09 2015 -0700 41.3 @@ -342,6 +342,9 @@ 41.4 if (functionNode.isVarArg()) { 41.5 flags |= IS_VARIABLE_ARITY; 41.6 } 41.7 + if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) { 41.8 + flags |= IS_PROPERTY_ACCESSOR; 41.9 + } 41.10 return flags; 41.11 } 41.12 41.13 @@ -382,7 +385,7 @@ 41.14 parser.setReparsedFunction(this); 41.15 41.16 final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition, 41.17 - Token.descLength(token), true); 41.18 + Token.descLength(token), isPropertyAccessor()); 41.19 // Parser generates a program AST even if we're recompiling a single function, so when we are only 41.20 // recompiling a single function, extract it from the program. 41.21 return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
42.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Mon Jun 15 11:41:52 2015 -0700 42.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Jun 17 23:30:09 2015 -0700 42.3 @@ -80,24 +80,24 @@ 42.4 private static final MethodHandle BIND_VAR_ARGS = findOwnMH("bindVarArgs", Object[].class, Object[].class, Object[].class); 42.5 42.6 /** Is this a strict mode function? */ 42.7 - public static final int IS_STRICT = 1 << 0; 42.8 + public static final int IS_STRICT = 1 << 0; 42.9 /** Is this a built-in function? */ 42.10 - public static final int IS_BUILTIN = 1 << 1; 42.11 + public static final int IS_BUILTIN = 1 << 1; 42.12 /** Is this a constructor function? */ 42.13 - public static final int IS_CONSTRUCTOR = 1 << 2; 42.14 + public static final int IS_CONSTRUCTOR = 1 << 2; 42.15 /** Does this function expect a callee argument? */ 42.16 - public static final int NEEDS_CALLEE = 1 << 3; 42.17 + public static final int NEEDS_CALLEE = 1 << 3; 42.18 /** Does this function make use of the this-object argument? */ 42.19 - public static final int USES_THIS = 1 << 4; 42.20 + public static final int USES_THIS = 1 << 4; 42.21 /** Is this a variable arity function? */ 42.22 - public static final int IS_VARIABLE_ARITY = 1 << 5; 42.23 + public static final int IS_VARIABLE_ARITY = 1 << 5; 42.24 + /** Is this a object literal property getter or setter? */ 42.25 + public static final int IS_PROPERTY_ACCESSOR = 1 << 6; 42.26 42.27 /** Flag for strict or built-in functions */ 42.28 public static final int IS_STRICT_OR_BUILTIN = IS_STRICT | IS_BUILTIN; 42.29 /** Flag for built-in constructors */ 42.30 public static final int IS_BUILTIN_CONSTRUCTOR = IS_BUILTIN | IS_CONSTRUCTOR; 42.31 - /** Flag for strict constructors */ 42.32 - public static final int IS_STRICT_CONSTRUCTOR = IS_STRICT | IS_CONSTRUCTOR; 42.33 42.34 private static final long serialVersionUID = 4252901245508769114L; 42.35 42.36 @@ -122,6 +122,10 @@ 42.37 return (flags & IS_VARIABLE_ARITY) != 0; 42.38 } 42.39 42.40 + final boolean isPropertyAccessor() { 42.41 + return (flags & IS_PROPERTY_ACCESSOR) != 0; 42.42 + } 42.43 + 42.44 /** 42.45 * Used from e.g. Native*$Constructors as an explicit call. TODO - make arity immutable and final 42.46 * @param arity new arity
43.1 --- a/src/jdk/nashorn/internal/runtime/ScriptLoader.java Mon Jun 15 11:41:52 2015 -0700 43.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptLoader.java Wed Jun 17 23:30:09 2015 -0700 43.3 @@ -70,7 +70,6 @@ 43.4 * @return Installed class. 43.5 */ 43.6 synchronized Class<?> installClass(final String name, final byte[] data, final CodeSource cs) { 43.7 - Objects.requireNonNull(cs); 43.8 - return defineClass(name, data, 0, data.length, cs); 43.9 + return defineClass(name, data, 0, data.length, Objects.requireNonNull(cs)); 43.10 } 43.11 }
44.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Jun 15 11:41:52 2015 -0700 44.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Jun 17 23:30:09 2015 -0700 44.3 @@ -2582,7 +2582,7 @@ 44.4 final int callCount = callType.parameterCount(); 44.5 44.6 final boolean isCalleeVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); 44.7 - final boolean isCallerVarArg = callerVarArg != null ? callerVarArg.booleanValue() : callCount > 0 && 44.8 + final boolean isCallerVarArg = callerVarArg != null ? callerVarArg : callCount > 0 && 44.9 callType.parameterType(callCount - 1).isArray(); 44.10 44.11 if (isCalleeVarArg) {
45.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Mon Jun 15 11:41:52 2015 -0700 45.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed Jun 17 23:30:09 2015 -0700 45.3 @@ -39,8 +39,10 @@ 45.4 import java.lang.invoke.MethodHandle; 45.5 import java.lang.invoke.MethodHandles; 45.6 import java.util.ArrayList; 45.7 +import java.util.Arrays; 45.8 import java.util.List; 45.9 import java.util.Map; 45.10 +import jdk.nashorn.internal.objects.NativeArray; 45.11 45.12 /** 45.13 * Global functions supported only in scripting mode. 45.14 @@ -54,7 +56,7 @@ 45.15 public static final MethodHandle READFULLY = findOwnMH("readFully", Object.class, Object.class, Object.class); 45.16 45.17 /** Handle to implementation of {@link ScriptingFunctions#exec} - Nashorn extension */ 45.18 - public static final MethodHandle EXEC = findOwnMH("exec", Object.class, Object.class, Object.class, Object.class); 45.19 + public static final MethodHandle EXEC = findOwnMH("exec", Object.class, Object.class, Object[].class); 45.20 45.21 /** EXEC name - special property used by $EXEC API. */ 45.22 public static final String EXEC_NAME = "$EXEC"; 45.23 @@ -71,7 +73,8 @@ 45.24 /** Names of special properties used by $ENV API. */ 45.25 public static final String ENV_NAME = "$ENV"; 45.26 45.27 - private static final String PWD_NAME = "PWD"; 45.28 + /** Name of the environment variable for the current working directory. */ 45.29 + public static final String PWD_NAME = "PWD"; 45.30 45.31 private ScriptingFunctions() { 45.32 } 45.33 @@ -125,19 +128,32 @@ 45.34 * Nashorn extension: exec a string in a separate process. 45.35 * 45.36 * @param self self reference 45.37 - * @param string string to execute 45.38 - * @param input input 45.39 + * @param args string to execute, input and additional arguments, to be appended to {@code string}. Additional arguments can be passed as 45.40 + * either one JavaScript array, whose elements will be converted to strings; or as a sequence of 45.41 + * varargs, each of which will be converted to a string. 45.42 * 45.43 * @return output string from the request 45.44 + * 45.45 * @throws IOException if any stream access fails 45.46 * @throws InterruptedException if execution is interrupted 45.47 */ 45.48 - public static Object exec(final Object self, final Object string, final Object input) throws IOException, InterruptedException { 45.49 + public static Object exec(final Object self, final Object... args) throws IOException, InterruptedException { 45.50 // Current global is need to fetch additional inputs and for additional results. 45.51 final ScriptObject global = Context.getGlobal(); 45.52 + final Object string = args.length > 0? args[0] : UNDEFINED; 45.53 + final Object input = args.length > 1? args[1] : UNDEFINED; 45.54 + final Object[] argv = (args.length > 2)? Arrays.copyOfRange(args, 2, args.length) : ScriptRuntime.EMPTY_ARRAY; 45.55 + // Assemble command line, process additional arguments. 45.56 + final List<String> cmdLine = tokenizeString(JSType.toString(string)); 45.57 + final Object[] additionalArgs = argv.length == 1 && argv[0] instanceof NativeArray ? 45.58 + ((NativeArray) argv[0]).asObjectArray() : 45.59 + argv; 45.60 + for (Object arg : additionalArgs) { 45.61 + cmdLine.add(JSType.toString(arg)); 45.62 + } 45.63 45.64 // Set up initial process. 45.65 - final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeCommandLine(JSType.toString(string))); 45.66 + final ProcessBuilder processBuilder = new ProcessBuilder(cmdLine); 45.67 45.68 // Current ENV property state. 45.69 final Object env = global.get(ENV_NAME); 45.70 @@ -237,23 +253,22 @@ 45.71 } 45.72 45.73 /** 45.74 - * Break an exec string into tokens, honoring quoted arguments and escaped 45.75 - * spaces. 45.76 + * Break a string into tokens, honoring quoted arguments and escaped spaces. 45.77 * 45.78 - * @param execString a {@link String} with the command line to execute. 45.79 + * @param str a {@link String} to tokenize. 45.80 * @return a {@link List} of {@link String}s representing the tokens that 45.81 - * constitute the command line. 45.82 + * constitute the string. 45.83 * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it. 45.84 */ 45.85 - public static List<String> tokenizeCommandLine(final String execString) throws IOException { 45.86 - final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(execString)); 45.87 + public static List<String> tokenizeString(final String str) throws IOException { 45.88 + final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(str)); 45.89 tokenizer.resetSyntax(); 45.90 tokenizer.wordChars(0, 255); 45.91 tokenizer.whitespaceChars(0, ' '); 45.92 tokenizer.commentChar('#'); 45.93 tokenizer.quoteChar('"'); 45.94 tokenizer.quoteChar('\''); 45.95 - final List<String> cmdList = new ArrayList<>(); 45.96 + final List<String> tokenList = new ArrayList<>(); 45.97 final StringBuilder toAppend = new StringBuilder(); 45.98 while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { 45.99 final String s = tokenizer.sval; 45.100 @@ -265,13 +280,13 @@ 45.101 // omit trailing \, append space instead 45.102 toAppend.append(s.substring(0, s.length() - 1)).append(' '); 45.103 } else { 45.104 - cmdList.add(toAppend.append(s).toString()); 45.105 + tokenList.add(toAppend.append(s).toString()); 45.106 toAppend.setLength(0); 45.107 } 45.108 } 45.109 if (toAppend.length() != 0) { 45.110 - cmdList.add(toAppend.toString()); 45.111 + tokenList.add(toAppend.toString()); 45.112 } 45.113 - return cmdList; 45.114 + return tokenList; 45.115 } 45.116 }
46.1 --- a/src/jdk/nashorn/internal/runtime/Source.java Mon Jun 15 11:41:52 2015 -0700 46.2 +++ b/src/jdk/nashorn/internal/runtime/Source.java Wed Jun 17 23:30:09 2015 -0700 46.3 @@ -910,14 +910,16 @@ 46.4 start = 2; 46.5 cs = StandardCharsets.UTF_16BE; 46.6 } else if (bytes.length > 1 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE) { 46.7 - start = 2; 46.8 - cs = StandardCharsets.UTF_16LE; 46.9 + if (bytes.length > 3 && bytes[2] == 0 && bytes[3] == 0) { 46.10 + start = 4; 46.11 + cs = Charset.forName("UTF-32LE"); 46.12 + } else { 46.13 + start = 2; 46.14 + cs = StandardCharsets.UTF_16LE; 46.15 + } 46.16 } else if (bytes.length > 2 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF) { 46.17 start = 3; 46.18 cs = StandardCharsets.UTF_8; 46.19 - } else if (bytes.length > 3 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE && bytes[2] == 0 && bytes[3] == 0) { 46.20 - start = 4; 46.21 - cs = Charset.forName("UTF-32LE"); 46.22 } else if (bytes.length > 3 && bytes[0] == 0 && bytes[1] == 0 && bytes[2] == (byte) 0xFE && bytes[3] == (byte) 0xFF) { 46.23 start = 4; 46.24 cs = Charset.forName("UTF-32BE");
47.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Mon Jun 15 11:41:52 2015 -0700 47.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Wed Jun 17 23:30:09 2015 -0700 47.3 @@ -1,5 +1,5 @@ 47.4 /* 47.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 47.6 + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 47.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.8 * 47.9 * This code is free software; you can redistribute it and/or modify it 47.10 @@ -54,23 +54,28 @@ 47.11 import jdk.nashorn.internal.runtime.ScriptObject; 47.12 47.13 /** 47.14 - * <p>A factory class that generates adapter classes. Adapter classes allow implementation of Java interfaces and 47.15 - * extending of Java classes from JavaScript. For every combination of a superclass to extend and interfaces to 47.16 - * implement (collectively: "original types"), exactly one adapter class is generated that extends the specified 47.17 - * superclass and implements the specified interfaces. (But see the discussion of class-based overrides for exceptions.) 47.18 - * </p><p> 47.19 - * The adapter class is generated in a new secure class loader that inherits Nashorn's protection domain, and has either 47.20 - * one of the original types' class loader or the Nashorn's class loader as its parent - the parent class loader 47.21 - * is chosen so that all the original types and the Nashorn core classes are visible from it (as the adapter will have 47.22 - * constant pool references to ScriptObject and ScriptFunction classes). In case none of the candidate class loaders has 47.23 - * visibility of all the required types, an error is thrown. The class uses {@link JavaAdapterBytecodeGenerator} to 47.24 - * generate the adapter class itself; see its documentation for details about the generated class. 47.25 - * </p><p> 47.26 - * You normally don't use this class directly, but rather either create adapters from script using 47.27 - * {@link jdk.nashorn.internal.objects.NativeJava#extend(Object, Object...)}, using the {@code new} operator on abstract classes and interfaces (see 47.28 - * {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)}), or implicitly when passing script functions to Java methods expecting SAM 47.29 - * types. 47.30 - * </p> 47.31 + * A factory class that generates adapter classes. Adapter classes allow 47.32 + * implementation of Java interfaces and extending of Java classes from 47.33 + * JavaScript. For every combination of a superclass to extend and interfaces to 47.34 + * implement (collectively: "original types"), exactly one adapter class is 47.35 + * generated that extends the specified superclass and implements the specified 47.36 + * interfaces. (But see the discussion of class-based overrides for exceptions.) 47.37 + * <p> 47.38 + * The adapter class is generated in a new secure class loader that inherits 47.39 + * Nashorn's protection domain, and has either one of the original types' class 47.40 + * loader or the Nashorn's class loader as its parent - the parent class loader 47.41 + * is chosen so that all the original types and the Nashorn core classes are 47.42 + * visible from it (as the adapter will have constant pool references to 47.43 + * ScriptObject and ScriptFunction classes). In case none of the candidate class 47.44 + * loaders has visibility of all the required types, an error is thrown. The 47.45 + * class uses {@link JavaAdapterBytecodeGenerator} to generate the adapter class 47.46 + * itself; see its documentation for details about the generated class. 47.47 + * <p> 47.48 + * You normally don't use this class directly, but rather either create adapters 47.49 + * from script using {@link jdk.nashorn.internal.objects.NativeJava#extend(Object, Object...)}, 47.50 + * using the {@code new} operator on abstract classes and interfaces (see 47.51 + * {@link jdk.nashorn.internal.objects.NativeJava#type(Object, Object)}), or 47.52 + * implicitly when passing script functions to Java methods expecting SAM types. 47.53 */ 47.54 47.55 @SuppressWarnings("javadoc") 47.56 @@ -93,25 +98,39 @@ 47.57 }; 47.58 47.59 /** 47.60 - * Returns an adapter class for the specified original types. The adapter class extends/implements the original 47.61 - * class/interfaces. 47.62 - * @param types the original types. The caller must pass at least one Java type representing either a public 47.63 - * interface or a non-final public class with at least one public or protected constructor. If more than one type is 47.64 - * specified, at most one can be a class and the rest have to be interfaces. The class can be in any position in the 47.65 - * array. Invoking the method twice with exactly the same types in the same order will return the same adapter 47.66 - * class, any reordering of types or even addition or removal of redundant types (i.e. interfaces that other types 47.67 - * in the list already implement/extend, or {@code java.lang.Object} in a list of types consisting purely of 47.68 - * interfaces) will result in a different adapter class, even though those adapter classes are functionally 47.69 - * identical; we deliberately don't want to incur the additional processing cost of canonicalizing type lists. 47.70 - * @param classOverrides a JavaScript object with functions serving as the class-level overrides and 47.71 - * implementations. These overrides are defined for all instances of the class, and can be further overridden on a 47.72 - * per-instance basis by passing additional objects in the constructor. 47.73 - * @param lookup the lookup object identifying the caller class. The generated adapter class will have the 47.74 - * protection domain of the caller class iff the lookup object is full-strength, otherwise it will be completely 47.75 - * unprivileged. 47.76 - * @return an adapter class. See this class' documentation for details on the generated adapter class. 47.77 - * @throws ECMAException with a TypeError if the adapter class can not be generated because the original class is 47.78 - * final, non-public, or has no public or protected constructors. 47.79 + * Returns an adapter class for the specified original types. The adapter 47.80 + * class extends/implements the original class/interfaces. 47.81 + * 47.82 + * @param types the original types. The caller must pass at least one Java 47.83 + * type representing either a public interface or a non-final public 47.84 + * class with at least one public or protected constructor. If more 47.85 + * than one type is specified, at most one can be a class and the 47.86 + * rest have to be interfaces. The class can be in any position in 47.87 + * the array. Invoking the method twice with exactly the same types 47.88 + * in the same order will return the same adapter class, any 47.89 + * reordering of types or even addition or removal of redundant types 47.90 + * (i.e., interfaces that other types in the list already 47.91 + * implement/extend, or {@code java.lang.Object} in a list of types 47.92 + * consisting purely of interfaces) will result in a different 47.93 + * adapter class, even though those adapter classes are functionally 47.94 + * identical; we deliberately don't want to incur the additional 47.95 + * processing cost of canonicalizing type lists. 47.96 + * @param classOverrides a JavaScript object with functions serving as the 47.97 + * class-level overrides and implementations. These overrides are 47.98 + * defined for all instances of the class, and can be further 47.99 + * overridden on a per-instance basis by passing additional objects 47.100 + * in the constructor. 47.101 + * @param lookup the lookup object identifying the caller class. The 47.102 + * generated adapter class will have the protection domain of the 47.103 + * caller class iff the lookup object is full-strength, otherwise it 47.104 + * will be completely unprivileged. 47.105 + * 47.106 + * @return an adapter class. See this class' documentation for details on 47.107 + * the generated adapter class. 47.108 + * 47.109 + * @throws ECMAException with a TypeError if the adapter class can not be 47.110 + * generated because the original class is final, non-public, or has 47.111 + * no public or protected constructors. 47.112 */ 47.113 public static StaticClass getAdapterClassFor(final Class<?>[] types, final ScriptObject classOverrides, final MethodHandles.Lookup lookup) { 47.114 return getAdapterClassFor(types, classOverrides, getProtectionDomain(lookup)); 47.115 @@ -148,15 +167,23 @@ 47.116 } 47.117 47.118 /** 47.119 - * Returns a method handle representing a constructor that takes a single argument of the source type (which, 47.120 - * really, should be one of {@link ScriptObject}, {@link ScriptFunction}, or {@link Object}, and returns an instance 47.121 - * of the adapter for the target type. Used to implement the function autoconverters as well as the Nashorn's 47.122 - * JSR-223 script engine's {@code getInterface()} method. 47.123 - * @param sourceType the source type; should be either {@link ScriptObject}, {@link ScriptFunction}, or 47.124 - * {@link Object}. In case of {@code Object}, it will return a method handle that dispatches to either the script 47.125 - * object or function constructor at invocation based on the actual argument. 47.126 + * Returns a method handle representing a constructor that takes a single 47.127 + * argument of the source type (which, really, should be one of {@link ScriptObject}, 47.128 + * {@link ScriptFunction}, or {@link Object}, and returns an instance of the 47.129 + * adapter for the target type. Used to implement the function autoconverters 47.130 + * as well as the Nashorn JSR-223 script engine's {@code getInterface()} 47.131 + * method. 47.132 + * 47.133 + * @param sourceType the source type; should be either {@link ScriptObject}, 47.134 + * {@link ScriptFunction}, or {@link Object}. In case of {@code Object}, 47.135 + * it will return a method handle that dispatches to either the script 47.136 + * object or function constructor at invocation based on the actual 47.137 + * argument. 47.138 * @param targetType the target type, for which adapter instances will be created 47.139 + * @param lookup method handle lookup to use 47.140 + * 47.141 * @return the constructor method handle. 47.142 + * 47.143 * @throws Exception if anything goes wrong 47.144 */ 47.145 public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType, final MethodHandles.Lookup lookup) throws Exception { 47.146 @@ -168,13 +195,18 @@ 47.147 } 47.148 47.149 /** 47.150 - * Returns whether an instance of the specified class/interface can be generated from a ScriptFunction. Returns true 47.151 - * iff: the adapter for the class/interface can be created, it is abstract (this includes interfaces), it has at 47.152 - * least one abstract method, all the abstract methods share the same name, and it has a public or protected default 47.153 - * constructor. Note that invoking this class will most likely result in the adapter class being defined in the JVM 47.154 - * if it hasn't been already. 47.155 + * Returns whether an instance of the specified class/interface can be 47.156 + * generated from a ScriptFunction. Returns {@code true} iff: the adapter 47.157 + * for the class/interface can be created, it is abstract (this includes 47.158 + * interfaces), it has at least one abstract method, all the abstract 47.159 + * methods share the same name, and it has a public or protected default 47.160 + * constructor. Note that invoking this class will most likely result in the 47.161 + * adapter class being defined in the JVM if it hasn't been already. 47.162 + * 47.163 * @param clazz the inspected class 47.164 - * @return true iff an instance of the specified class/interface can be generated from a ScriptFunction. 47.165 + * 47.166 + * @return {@code true} iff an instance of the specified class/interface can 47.167 + * be generated from a ScriptFunction. 47.168 */ 47.169 static boolean isAutoConvertibleFromFunction(final Class<?> clazz) { 47.170 return getAdapterInfo(new Class<?>[] { clazz }).autoConvertibleFromFunction; 47.171 @@ -198,7 +230,9 @@ 47.172 47.173 /** 47.174 * For a given class, create its adapter class and associated info. 47.175 + * 47.176 * @param type the class for which the adapter is created 47.177 + * 47.178 * @return the adapter info for the class. 47.179 */ 47.180 private static AdapterInfo createAdapterInfo(final Class<?>[] types, final ClassAndLoader definingClassAndLoader) { 47.181 @@ -311,11 +345,14 @@ 47.182 } 47.183 47.184 /** 47.185 - * Choose between the passed class loader and the class loader that defines the ScriptObject class, based on which 47.186 - * of the two can see the classes in both. 47.187 - * @param classAndLoader the loader and a representative class from it that will be used to add the generated 47.188 - * adapter to its ADAPTER_INFO_MAPS. 47.189 + * Choose between the passed class loader and the class loader that defines the 47.190 + * ScriptObject class, based on which of the two can see the classes in both. 47.191 + * 47.192 + * @param classAndLoader the loader and a representative class from it that will 47.193 + * be used to add the generated adapter to its ADAPTER_INFO_MAPS. 47.194 + * 47.195 * @return the class loader that sees both the specified class and Nashorn classes. 47.196 + * 47.197 * @throws IllegalStateException if no such class loader is found. 47.198 */ 47.199 private static ClassLoader findCommonLoader(final ClassAndLoader classAndLoader) throws AdaptationException {
48.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapter.java Mon Jun 15 11:41:52 2015 -0700 48.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaSuperAdapter.java Wed Jun 17 23:30:09 2015 -0700 48.3 @@ -36,8 +36,7 @@ 48.4 private final Object adapter; 48.5 48.6 JavaSuperAdapter(final Object adapter) { 48.7 - Objects.requireNonNull(adapter); 48.8 - this.adapter = adapter; 48.9 + this.adapter = Objects.requireNonNull(adapter); 48.10 } 48.11 48.12 public Object getAdapter() {
49.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Mon Jun 15 11:41:52 2015 -0700 49.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Wed Jun 17 23:30:09 2015 -0700 49.3 @@ -246,7 +246,7 @@ 49.4 } 49.5 49.6 @Override 49.7 - public MethodHandle filterInternalObjects(MethodHandle target) { 49.8 + public MethodHandle filterInternalObjects(final MethodHandle target) { 49.9 return linkerServices.filterInternalObjects(target); 49.10 } 49.11 }
50.1 --- a/src/jdk/nashorn/internal/runtime/options/Options.java Mon Jun 15 11:41:52 2015 -0700 50.2 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Wed Jun 17 23:30:09 2015 -0700 50.3 @@ -136,6 +136,12 @@ 50.4 return options.toString(); 50.5 } 50.6 50.7 + private static void checkPropertyName(final String name) { 50.8 + if (! Objects.requireNonNull(name).startsWith("nashorn.")) { 50.9 + throw new IllegalArgumentException(name); 50.10 + } 50.11 + } 50.12 + 50.13 /** 50.14 * Convenience function for getting system properties in a safe way 50.15 50.16 @@ -144,11 +150,7 @@ 50.17 * @return true if set to true, default value if unset or set to false 50.18 */ 50.19 public static boolean getBooleanProperty(final String name, final Boolean defValue) { 50.20 - Objects.requireNonNull(name); 50.21 - if (!name.startsWith("nashorn.")) { 50.22 - throw new IllegalArgumentException(name); 50.23 - } 50.24 - 50.25 + checkPropertyName(name); 50.26 return AccessController.doPrivileged( 50.27 new PrivilegedAction<Boolean>() { 50.28 @Override 50.29 @@ -185,11 +187,7 @@ 50.30 * @return string property if set or default value 50.31 */ 50.32 public static String getStringProperty(final String name, final String defValue) { 50.33 - Objects.requireNonNull(name); 50.34 - if (! name.startsWith("nashorn.")) { 50.35 - throw new IllegalArgumentException(name); 50.36 - } 50.37 - 50.38 + checkPropertyName(name); 50.39 return AccessController.doPrivileged( 50.40 new PrivilegedAction<String>() { 50.41 @Override 50.42 @@ -212,11 +210,7 @@ 50.43 * @return integer property if set or default value 50.44 */ 50.45 public static int getIntProperty(final String name, final int defValue) { 50.46 - Objects.requireNonNull(name); 50.47 - if (! name.startsWith("nashorn.")) { 50.48 - throw new IllegalArgumentException(name); 50.49 - } 50.50 - 50.51 + checkPropertyName(name); 50.52 return AccessController.doPrivileged( 50.53 new PrivilegedAction<Integer>() { 50.54 @Override
51.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/EncodingHelper.java Mon Jun 15 11:41:52 2015 -0700 51.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/EncodingHelper.java Wed Jun 17 23:30:09 2015 -0700 51.3 @@ -229,6 +229,11 @@ 51.4 51.5 /** 51.6 * @see <a href="http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt">http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt</a> 51.7 + * 51.8 + * @param code code 51.9 + * @param ctype ctype 51.10 + * 51.11 + * @return isCodeCType 51.12 */ 51.13 public static boolean isCodeCType(final int code, final int ctype) { 51.14 int type;
52.1 --- a/src/jdk/nashorn/internal/runtime/regexp/joni/Syntax.java Mon Jun 15 11:41:52 2015 -0700 52.2 +++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Syntax.java Wed Jun 17 23:30:09 2015 -0700 52.3 @@ -57,10 +57,10 @@ 52.4 } 52.5 } 52.6 52.7 - /** 52.8 - * OP 52.9 - * 52.10 - */ 52.11 + // 52.12 + // OP 52.13 + // 52.14 + 52.15 protected boolean isOp(final int opm) { 52.16 return (op & opm) != 0; 52.17 } 52.18 @@ -189,11 +189,10 @@ 52.19 return isOp(OP_ESC_X_BRACE_HEX8); 52.20 } 52.21 52.22 + // 52.23 + // OP2 52.24 + // 52.25 52.26 - /** 52.27 - * OP 52.28 - * 52.29 - */ 52.30 protected boolean isOp2(final int opm) { 52.31 return (op2 & opm) != 0; 52.32 } 52.33 @@ -278,10 +277,10 @@ 52.34 return isOp2(OP2_INEFFECTIVE_ESCAPE); 52.35 } 52.36 52.37 - /** 52.38 - * BEHAVIOR 52.39 - * 52.40 - */ 52.41 + // 52.42 + // BEHAVIOR 52.43 + // 52.44 + 52.45 protected boolean isBehavior(final int bvm) { 52.46 return (behavior & bvm) != 0; 52.47 }
53.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Mon Jun 15 11:41:52 2015 -0700 53.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed Jun 17 23:30:09 2015 -0700 53.3 @@ -174,4 +174,4 @@ 53.4 config.error.no.dest=no destination directory supplied 53.5 53.6 uri.error.bad.uri=Bad URI "{0}" near offset {1} 53.7 - 53.8 +list.adapter.null.global=Attempted to create the adapter from outside a JavaScript execution context.
54.1 --- a/src/jdk/nashorn/tools/Shell.java Mon Jun 15 11:41:52 2015 -0700 54.2 +++ b/src/jdk/nashorn/tools/Shell.java Wed Jun 17 23:30:09 2015 -0700 54.3 @@ -439,7 +439,7 @@ 54.4 } 54.5 54.6 try { 54.7 - final Object res = context.eval(global, source, global, "<shell>", env._strict); 54.8 + final Object res = context.eval(global, source, global, "<shell>"); 54.9 if (res != ScriptRuntime.UNDEFINED) { 54.10 err.println(JSType.toString(res)); 54.11 }
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/script/basic/JDK-8066220.js Wed Jun 17 23:30:09 2015 -0700 55.3 @@ -0,0 +1,38 @@ 55.4 +/* 55.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +/** 55.28 + * JDK-8066220: Fuzzing bug: MethodHandle bug (Object,Object) != (boolean)Object 55.29 + * 55.30 + * @test 55.31 + * @run 55.32 + */ 55.33 + 55.34 + 55.35 +function f() {} 55.36 +// Call f with primitive this first, then as constructor 55.37 +f.call(1); 55.38 +new f(); 55.39 + 55.40 +// Same as above in strict mode 55.41 +eval('"use strict"; function e() { print(typeof this); } e.call(1); new e();');
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/test/script/basic/JDK-8066220.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 56.3 @@ -0,0 +1,2 @@ 56.4 +number 56.5 +object
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/test/script/basic/JDK-8066237.js Wed Jun 17 23:30:09 2015 -0700 57.3 @@ -0,0 +1,38 @@ 57.4 +/* 57.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. 57.11 + * 57.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.15 + * version 2 for more details (a copy is included in the LICENSE file that 57.16 + * accompanied this code). 57.17 + * 57.18 + * You should have received a copy of the GNU General Public License version 57.19 + * 2 along with this work; if not, write to the Free Software Foundation, 57.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.21 + * 57.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 57.23 + * or visit www.oracle.com if you need additional information or have any 57.24 + * questions. 57.25 + */ 57.26 + 57.27 +/** 57.28 + * JDK-8066237: Fuzzing bug: Parser error on optimistic recompilation 57.29 + * 57.30 + * @test 57.31 + * @run 57.32 + */ 57.33 + 57.34 +try { 57.35 + (function() { 57.36 + eval("get, a") 57.37 + })(); 57.38 + fail("should have thrown"); 57.39 +} catch (e) { 57.40 + Assert.assertTrue(e.name === "ReferenceError"); 57.41 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/test/script/basic/JDK-8085802.js Wed Jun 17 23:30:09 2015 -0700 58.3 @@ -0,0 +1,35 @@ 58.4 +/* 58.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 + * 58.8 + * This code is free software; you can redistribute it and/or modify it 58.9 + * under the terms of the GNU General Public License version 2 only, as 58.10 + * published by the Free Software Foundation. 58.11 + * 58.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 58.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.15 + * version 2 for more details (a copy is included in the LICENSE file that 58.16 + * accompanied this code). 58.17 + * 58.18 + * You should have received a copy of the GNU General Public License version 58.19 + * 2 along with this work; if not, write to the Free Software Foundation, 58.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.21 + * 58.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 58.23 + * or visit www.oracle.com if you need additional information or have any 58.24 + * questions. 58.25 + */ 58.26 + 58.27 +/** 58.28 + * JDK-8085802: Nashorn -nse option causes parse error on anonymous function definition 58.29 + * 58.30 + * @test 58.31 + * @run 58.32 + * @option -nse 58.33 + */ 58.34 + 58.35 +// even with -nse passed, the following should run fine 58.36 +// because anonymous function is used as expression here 58.37 + 58.38 +(function (){})()
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/test/script/basic/JDK-8087211.js Wed Jun 17 23:30:09 2015 -0700 59.3 @@ -0,0 +1,63 @@ 59.4 +/* 59.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. 59.11 + * 59.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.15 + * version 2 for more details (a copy is included in the LICENSE file that 59.16 + * accompanied this code). 59.17 + * 59.18 + * You should have received a copy of the GNU General Public License version 59.19 + * 2 along with this work; if not, write to the Free Software Foundation, 59.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.21 + * 59.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 59.23 + * or visit www.oracle.com if you need additional information or have any 59.24 + * questions. 59.25 + */ 59.26 + 59.27 +/** 59.28 + * JDK-8087211: Indirect evals should be strict with -strict option 59.29 + * 59.30 + * @test 59.31 + * @run 59.32 + * @option -strict 59.33 + */ 59.34 + 59.35 +var global = this; 59.36 + 59.37 +try { 59.38 + // indirect eval call. 59.39 + global.eval("x = 34;"); 59.40 + throw new Error("should have thrown ReferenceError"); 59.41 +} catch (e if e instanceof ReferenceError) { 59.42 +} 59.43 + 59.44 + 59.45 +function teststrict() { 59.46 + "use strict"; 59.47 + // strict caller, indirect eval. 59.48 + global.eval('public = 1;'); 59.49 +} 59.50 + 59.51 +try { 59.52 + teststrict(); 59.53 + throw new Error("should have thrown SyntaxError"); 59.54 +} catch (e if e instanceof SyntaxError) { 59.55 +} 59.56 + 59.57 +function testnonstrict() { 59.58 + // non strict caller, indirect eval. 59.59 + global.eval('public = 1;'); 59.60 +} 59.61 + 59.62 +try { 59.63 + testnonstrict(); 59.64 + throw new Error("should have thrown SyntaxError"); 59.65 +} catch (e if e instanceof SyntaxError) { 59.66 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 60.2 +++ b/test/script/basic/JDK-8087211_2.js Wed Jun 17 23:30:09 2015 -0700 60.3 @@ -0,0 +1,50 @@ 60.4 +/* 60.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 60.7 + * 60.8 + * This code is free software; you can redistribute it and/or modify it 60.9 + * under the terms of the GNU General Public License version 2 only, as 60.10 + * published by the Free Software Foundation. 60.11 + * 60.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 60.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 60.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 60.15 + * version 2 for more details (a copy is included in the LICENSE file that 60.16 + * accompanied this code). 60.17 + * 60.18 + * You should have received a copy of the GNU General Public License version 60.19 + * 2 along with this work; if not, write to the Free Software Foundation, 60.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 60.21 + * 60.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 60.23 + * or visit www.oracle.com if you need additional information or have any 60.24 + * questions. 60.25 + */ 60.26 + 60.27 +/** 60.28 + * JDK-8087211: Indirect evals should be strict with -strict option 60.29 + * Make sure without -strict option, indirect evals are not strict. 60.30 + * 60.31 + * @test 60.32 + * @run 60.33 + */ 60.34 + 60.35 +var global = this; 60.36 + 60.37 +// indirect eval call. 60.38 +global.eval("x = 34;"); 60.39 + 60.40 +function teststrict() { 60.41 + "use strict"; 60.42 + // strict caller, indirect eval. 60.43 + global.eval('public = 1;'); 60.44 +} 60.45 + 60.46 +teststrict(); 60.47 + 60.48 +function testnonstrict() { 60.49 + // non strict caller, indirect eval. 60.50 + global.eval('public = 1;'); 60.51 +} 60.52 + 60.53 +testnonstrict();
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 61.2 +++ b/test/script/error/anon_func_stat_nse.js Wed Jun 17 23:30:09 2015 -0700 61.3 @@ -0,0 +1,31 @@ 61.4 +/* 61.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 61.7 + * 61.8 + * This code is free software; you can redistribute it and/or modify it 61.9 + * under the terms of the GNU General Public License version 2 only, as 61.10 + * published by the Free Software Foundation. 61.11 + * 61.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 61.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 61.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 61.15 + * version 2 for more details (a copy is included in the LICENSE file that 61.16 + * accompanied this code). 61.17 + * 61.18 + * You should have received a copy of the GNU General Public License version 61.19 + * 2 along with this work; if not, write to the Free Software Foundation, 61.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 61.21 + * 61.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 61.23 + * or visit www.oracle.com if you need additional information or have any 61.24 + * questions. 61.25 + */ 61.26 + 61.27 +/** 61.28 + * Anonymous function statement should result in error in -nse 61.29 + * 61.30 + * @option -nse 61.31 + * @test/compile-error 61.32 + */ 61.33 + 61.34 +function() {}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 62.2 +++ b/test/script/error/anon_func_stat_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 62.3 @@ -0,0 +1,3 @@ 62.4 +test/script/error/anon_func_stat_nse.js:31:8 Expected ident but found ( 62.5 +function() {} 62.6 + ^
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 63.2 +++ b/test/script/error/backquote_string_nse.js Wed Jun 17 23:30:09 2015 -0700 63.3 @@ -0,0 +1,32 @@ 63.4 +/* 63.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 63.7 + * 63.8 + * This code is free software; you can redistribute it and/or modify it 63.9 + * under the terms of the GNU General Public License version 2 only, as 63.10 + * published by the Free Software Foundation. 63.11 + * 63.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 63.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 63.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 63.15 + * version 2 for more details (a copy is included in the LICENSE file that 63.16 + * accompanied this code). 63.17 + * 63.18 + * You should have received a copy of the GNU General Public License version 63.19 + * 2 along with this work; if not, write to the Free Software Foundation, 63.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 63.21 + * 63.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 63.23 + * or visit www.oracle.com if you need additional information or have any 63.24 + * questions. 63.25 + */ 63.26 + 63.27 +/** 63.28 + * Backquote string should result in error with -nse even with -scripting 63.29 + * 63.30 + * @option -nse 63.31 + * @option -scripting 63.32 + * @test/compile-error 63.33 + */ 63.34 + 63.35 +`ls -l`;
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 64.2 +++ b/test/script/error/backquote_string_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 64.3 @@ -0,0 +1,3 @@ 64.4 +test/script/error/backquote_string_nse.js:32:0 Expected an operand but found error 64.5 +`ls -l`; 64.6 +^
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 65.2 +++ b/test/script/error/conditional_catch_nse.js Wed Jun 17 23:30:09 2015 -0700 65.3 @@ -0,0 +1,34 @@ 65.4 +/* 65.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 65.7 + * 65.8 + * This code is free software; you can redistribute it and/or modify it 65.9 + * under the terms of the GNU General Public License version 2 only, as 65.10 + * published by the Free Software Foundation. 65.11 + * 65.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 65.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 65.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 65.15 + * version 2 for more details (a copy is included in the LICENSE file that 65.16 + * accompanied this code). 65.17 + * 65.18 + * You should have received a copy of the GNU General Public License version 65.19 + * 2 along with this work; if not, write to the Free Software Foundation, 65.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 65.21 + * 65.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 65.23 + * or visit www.oracle.com if you need additional information or have any 65.24 + * questions. 65.25 + */ 65.26 + 65.27 +/** 65.28 + * conditional catch should result in error with -nse 65.29 + * 65.30 + * @option -nse 65.31 + * @test/compile-error 65.32 + */ 65.33 + 65.34 +try { 65.35 + func(); 65.36 +} catch (e if e instanceof ReferenceError) { 65.37 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 66.2 +++ b/test/script/error/conditional_catch_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 66.3 @@ -0,0 +1,6 @@ 66.4 +test/script/error/conditional_catch_nse.js:33:11 Expected ) but found if 66.5 +} catch (e if e instanceof ReferenceError) { 66.6 + ^ 66.7 +test/script/error/conditional_catch_nse.js:34:0 Expected eof but found } 66.8 +} 66.9 +^
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 67.2 +++ b/test/script/error/expr_closure_nse.js Wed Jun 17 23:30:09 2015 -0700 67.3 @@ -0,0 +1,31 @@ 67.4 +/* 67.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 67.7 + * 67.8 + * This code is free software; you can redistribute it and/or modify it 67.9 + * under the terms of the GNU General Public License version 2 only, as 67.10 + * published by the Free Software Foundation. 67.11 + * 67.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 67.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 67.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 67.15 + * version 2 for more details (a copy is included in the LICENSE file that 67.16 + * accompanied this code). 67.17 + * 67.18 + * You should have received a copy of the GNU General Public License version 67.19 + * 2 along with this work; if not, write to the Free Software Foundation, 67.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 67.21 + * 67.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 67.23 + * or visit www.oracle.com if you need additional information or have any 67.24 + * questions. 67.25 + */ 67.26 + 67.27 +/** 67.28 + * Expression closures should result in error with -nse 67.29 + * 67.30 + * @option -nse 67.31 + * @test/compile-error 67.32 + */ 67.33 + 67.34 +function square(x) x*x;
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 68.2 +++ b/test/script/error/expr_closure_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 68.3 @@ -0,0 +1,3 @@ 68.4 +test/script/error/expr_closure_nse.js:31:19 Expected { but found x 68.5 +function square(x) x*x; 68.6 + ^
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 69.2 +++ b/test/script/error/for_each_nse.js Wed Jun 17 23:30:09 2015 -0700 69.3 @@ -0,0 +1,33 @@ 69.4 +/* 69.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 69.7 + * 69.8 + * This code is free software; you can redistribute it and/or modify it 69.9 + * under the terms of the GNU General Public License version 2 only, as 69.10 + * published by the Free Software Foundation. 69.11 + * 69.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 69.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 69.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 69.15 + * version 2 for more details (a copy is included in the LICENSE file that 69.16 + * accompanied this code). 69.17 + * 69.18 + * You should have received a copy of the GNU General Public License version 69.19 + * 2 along with this work; if not, write to the Free Software Foundation, 69.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 69.21 + * 69.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 69.23 + * or visit www.oracle.com if you need additional information or have any 69.24 + * questions. 69.25 + */ 69.26 + 69.27 +/** 69.28 + * for..each should result in error with -nse 69.29 + * 69.30 + * @option -nse 69.31 + * @test/compile-error 69.32 + */ 69.33 + 69.34 +for each (var x in [3, 454, 4]) { 69.35 + print(x); 69.36 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 70.2 +++ b/test/script/error/for_each_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 70.3 @@ -0,0 +1,6 @@ 70.4 +test/script/error/for_each_nse.js:31:4 Expected ( but found each 70.5 +for each (var x in [3, 454, 4]) { 70.6 + ^ 70.7 +test/script/error/for_each_nse.js:33:0 Expected eof but found } 70.8 +} 70.9 +^
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 71.2 +++ b/test/script/error/hash_comment_nse.js Wed Jun 17 23:30:09 2015 -0700 71.3 @@ -0,0 +1,32 @@ 71.4 +/* 71.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 71.7 + * 71.8 + * This code is free software; you can redistribute it and/or modify it 71.9 + * under the terms of the GNU General Public License version 2 only, as 71.10 + * published by the Free Software Foundation. 71.11 + * 71.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 71.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 71.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 71.15 + * version 2 for more details (a copy is included in the LICENSE file that 71.16 + * accompanied this code). 71.17 + * 71.18 + * You should have received a copy of the GNU General Public License version 71.19 + * 2 along with this work; if not, write to the Free Software Foundation, 71.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 71.21 + * 71.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 71.23 + * or visit www.oracle.com if you need additional information or have any 71.24 + * questions. 71.25 + */ 71.26 + 71.27 +/** 71.28 + * Hash comment should result in error with -nse even with -scripting 71.29 + * 71.30 + * @option -nse 71.31 + * @option -scripting 71.32 + * @test/compile-error 71.33 + */ 71.34 + 71.35 +# this is a comment
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 72.2 +++ b/test/script/error/hash_comment_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 72.3 @@ -0,0 +1,3 @@ 72.4 +test/script/error/hash_comment_nse.js:32:0 Expected an operand but found error 72.5 +# this is a comment 72.6 +^
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/script/error/heredoc_nse.js Wed Jun 17 23:30:09 2015 -0700 73.3 @@ -0,0 +1,35 @@ 73.4 +/* 73.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 73.7 + * 73.8 + * This code is free software; you can redistribute it and/or modify it 73.9 + * under the terms of the GNU General Public License version 2 only, as 73.10 + * published by the Free Software Foundation. 73.11 + * 73.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 73.15 + * version 2 for more details (a copy is included in the LICENSE file that 73.16 + * accompanied this code). 73.17 + * 73.18 + * You should have received a copy of the GNU General Public License version 73.19 + * 2 along with this work; if not, write to the Free Software Foundation, 73.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 73.21 + * 73.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 73.23 + * or visit www.oracle.com if you need additional information or have any 73.24 + * questions. 73.25 + */ 73.26 + 73.27 +/** 73.28 + * Heredoc string should result in error with -nse even with -scripting 73.29 + * 73.30 + * @option -nse 73.31 + * @option -scripting 73.32 + * @test/compile-error 73.33 + */ 73.34 + 73.35 +var str = <<EOF 73.36 +This is a multiple line string 73.37 +inside a heredoc 73.38 +EOF;
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 74.2 +++ b/test/script/error/heredoc_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 74.3 @@ -0,0 +1,9 @@ 74.4 +test/script/error/heredoc_nse.js:32:10 Expected an operand but found << 74.5 +var str = <<EOF 74.6 + ^ 74.7 +test/script/error/heredoc_nse.js:33:5 Expected ; but found is 74.8 +This is a multiple line string 74.9 + ^ 74.10 +test/script/error/heredoc_nse.js:34:7 Expected ; but found a 74.11 +inside a heredoc 74.12 + ^
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/script/error/object_literal_in_new_nse.js Wed Jun 17 23:30:09 2015 -0700 75.3 @@ -0,0 +1,33 @@ 75.4 +/* 75.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. 75.11 + * 75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.15 + * version 2 for more details (a copy is included in the LICENSE file that 75.16 + * accompanied this code). 75.17 + * 75.18 + * You should have received a copy of the GNU General Public License version 75.19 + * 2 along with this work; if not, write to the Free Software Foundation, 75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.21 + * 75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 75.23 + * or visit www.oracle.com if you need additional information or have any 75.24 + * questions. 75.25 + */ 75.26 + 75.27 +/** 75.28 + * Object literal outside 'new' should result in error in -nse 75.29 + * 75.30 + * @option -nse 75.31 + * @test/compile-error 75.32 + */ 75.33 + 75.34 +var r = new java.lang.Runnable() { 75.35 + run: function() { print("hello"); } 75.36 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/script/error/object_literal_in_new_nse.js.EXPECTED Wed Jun 17 23:30:09 2015 -0700 76.3 @@ -0,0 +1,9 @@ 76.4 +test/script/error/object_literal_in_new_nse.js:31:33 Expected ; but found { 76.5 +var r = new java.lang.Runnable() { 76.6 + ^ 76.7 +test/script/error/object_literal_in_new_nse.js:32:15 Expected ident but found ( 76.8 + run: function() { print("hello"); } 76.9 + ^ 76.10 +test/script/error/object_literal_in_new_nse.js:32:36 Expected eof but found } 76.11 + run: function() { print("hello"); } 76.12 + ^
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/script/nosecurity/JDK-8080087.js Wed Jun 17 23:30:09 2015 -0700 77.3 @@ -0,0 +1,38 @@ 77.4 +/* 77.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 77.7 + * 77.8 + * This code is free software; you can redistribute it and/or modify it 77.9 + * under the terms of the GNU General Public License version 2 only, as 77.10 + * published by the Free Software Foundation. 77.11 + * 77.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 77.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 77.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 77.15 + * version 2 for more details (a copy is included in the LICENSE file that 77.16 + * accompanied this code). 77.17 + * 77.18 + * You should have received a copy of the GNU General Public License version 77.19 + * 2 along with this work; if not, write to the Free Software Foundation, 77.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 77.21 + * 77.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 77.23 + * or visit www.oracle.com if you need additional information or have any 77.24 + * questions. 77.25 + */ 77.26 + 77.27 +/** 77.28 + * JDK-8080087: Nashorn $ENV.PWD is originally undefined 77.29 + * 77.30 + * This is to ensure that $ENV.PWD is correctly set on Windows as well as on all 77.31 + * other platforms. 77.32 + * 77.33 + * @test 77.34 + * @option -scripting 77.35 + * @run 77.36 + */ 77.37 + 77.38 +if (typeof($ENV.PWD) === 'undefined') { 77.39 + fail('$ENV.PWD is undefined') 77.40 +} 77.41 +
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/test/src/jdk/nashorn/api/scripting/JSONCompatibleTest.java Wed Jun 17 23:30:09 2015 -0700 78.3 @@ -0,0 +1,117 @@ 78.4 +/* 78.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 78.7 + * 78.8 + * This code is free software; you can redistribute it and/or modify it 78.9 + * under the terms of the GNU General Public License version 2 only, as 78.10 + * published by the Free Software Foundation. Oracle designates this 78.11 + * particular file as subject to the "Classpath" exception as provided 78.12 + * by Oracle in the LICENSE file that accompanied this code. 78.13 + * 78.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 78.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 78.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 78.17 + * version 2 for more details (a copy is included in the LICENSE file that 78.18 + * accompanied this code). 78.19 + * 78.20 + * You should have received a copy of the GNU General Public License version 78.21 + * 2 along with this work; if not, write to the Free Software Foundation, 78.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 78.23 + * 78.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 78.25 + * or visit www.oracle.com if you need additional information or have any 78.26 + * questions. 78.27 + */ 78.28 + 78.29 +package jdk.nashorn.api.scripting; 78.30 + 78.31 +import static org.testng.Assert.assertEquals; 78.32 +import static org.testng.Assert.assertTrue; 78.33 + 78.34 +import java.util.Arrays; 78.35 +import java.util.List; 78.36 +import java.util.Map; 78.37 +import javax.script.ScriptEngine; 78.38 +import javax.script.ScriptException; 78.39 +import org.testng.Assert; 78.40 +import org.testng.annotations.Test; 78.41 + 78.42 +public class JSONCompatibleTest { 78.43 + 78.44 + /** 78.45 + * Wrap a top-level array as a list. 78.46 + */ 78.47 + @Test 78.48 + public void testWrapArray() throws ScriptException { 78.49 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 78.50 + final Object val = engine.eval("Java.asJSONCompatible([1, 2, 3])"); 78.51 + assertEquals(asList(val), Arrays.asList(1, 2, 3)); 78.52 + } 78.53 + 78.54 + /** 78.55 + * Wrap an embedded array as a list. 78.56 + */ 78.57 + @Test 78.58 + public void testWrapObjectWithArray() throws ScriptException { 78.59 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 78.60 + final Object val = engine.eval("Java.asJSONCompatible({x: [1, 2, 3]})"); 78.61 + assertEquals(asList(asMap(val).get("x")), Arrays.asList(1, 2, 3)); 78.62 + } 78.63 + 78.64 + /** 78.65 + * Check it all works transitively several more levels down. 78.66 + */ 78.67 + @Test 78.68 + public void testDeepWrapping() throws ScriptException { 78.69 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 78.70 + final Object val = engine.eval("Java.asJSONCompatible({x: [1, {y: [2, {z: [3]}]}, [4, 5]]})"); 78.71 + final Map<String, Object> root = asMap(val); 78.72 + final List<Object> x = asList(root.get("x")); 78.73 + assertEquals(x.get(0), 1); 78.74 + final Map<String, Object> x1 = asMap(x.get(1)); 78.75 + final List<Object> y = asList(x1.get("y")); 78.76 + assertEquals(y.get(0), 2); 78.77 + final Map<String, Object> y1 = asMap(y.get(1)); 78.78 + assertEquals(asList(y1.get("z")), Arrays.asList(3)); 78.79 + assertEquals(asList(x.get(2)), Arrays.asList(4, 5)); 78.80 + } 78.81 + 78.82 + /** 78.83 + * Ensure that the old behaviour (every object is a Map) is unchanged. 78.84 + */ 78.85 + @Test 78.86 + public void testNonWrapping() throws ScriptException { 78.87 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 78.88 + final Object val = engine.eval("({x: [1, {y: [2, {z: [3]}]}, [4, 5]]})"); 78.89 + final Map<String, Object> root = asMap(val); 78.90 + final Map<String, Object> x = asMap(root.get("x")); 78.91 + assertEquals(x.get("0"), 1); 78.92 + final Map<String, Object> x1 = asMap(x.get("1")); 78.93 + final Map<String, Object> y = asMap(x1.get("y")); 78.94 + assertEquals(y.get("0"), 2); 78.95 + final Map<String, Object> y1 = asMap(y.get("1")); 78.96 + final Map<String, Object> z = asMap(y1.get("z")); 78.97 + assertEquals(z.get("0"), 3); 78.98 + final Map<String, Object> x2 = asMap(x.get("2")); 78.99 + assertEquals(x2.get("0"), 4); 78.100 + assertEquals(x2.get("1"), 5); 78.101 + } 78.102 + 78.103 + @SuppressWarnings("unchecked") 78.104 + private static List<Object> asList(final Object obj) { 78.105 + assertJSObject(obj); 78.106 + Assert.assertTrue(obj instanceof List); 78.107 + return (List)obj; 78.108 + } 78.109 + 78.110 + @SuppressWarnings("unchecked") 78.111 + private static Map<String, Object> asMap(final Object obj) { 78.112 + assertJSObject(obj); 78.113 + Assert.assertTrue(obj instanceof Map); 78.114 + return (Map)obj; 78.115 + } 78.116 + 78.117 + private static void assertJSObject(final Object obj) { 78.118 + assertTrue(obj instanceof JSObject); 78.119 + } 78.120 +}
79.1 --- a/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java Mon Jun 15 11:41:52 2015 -0700 79.2 +++ b/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java Wed Jun 17 23:30:09 2015 -0700 79.3 @@ -31,10 +31,12 @@ 79.4 import javax.script.Bindings; 79.5 import javax.script.ScriptContext; 79.6 import javax.script.ScriptEngine; 79.7 +import javax.script.ScriptEngineFactory; 79.8 import javax.script.ScriptEngineManager; 79.9 import javax.script.ScriptException; 79.10 import javax.script.SimpleBindings; 79.11 import javax.script.SimpleScriptContext; 79.12 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; 79.13 import jdk.nashorn.api.scripting.ScriptObjectMirror; 79.14 import jdk.nashorn.api.scripting.URLReader; 79.15 import org.testng.Assert; 79.16 @@ -778,4 +780,44 @@ 79.17 throw new AssertionError("should have thrown NPE"); 79.18 } catch (NullPointerException npe5) {} 79.19 } 79.20 + 79.21 + public static class RecursiveEval { 79.22 + private final ScriptEngineFactory factory = new NashornScriptEngineFactory(); 79.23 + private final ScriptEngine engine = factory.getScriptEngine(); 79.24 + private final Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); 79.25 + 79.26 + public void program() throws ScriptException { 79.27 + ScriptContext sc = new SimpleScriptContext(); 79.28 + Bindings global = new SimpleBindings(); 79.29 + sc.setBindings(global, ScriptContext.GLOBAL_SCOPE); 79.30 + sc.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE); 79.31 + global.put("text", "programText"); 79.32 + String value = engine.eval("text", sc).toString(); 79.33 + Assert.assertEquals(value, "programText"); 79.34 + engine.put("program", this); 79.35 + engine.eval("program.method()"); 79.36 + // eval again from here! 79.37 + value = engine.eval("text", sc).toString(); 79.38 + Assert.assertEquals(value, "programText"); 79.39 + } 79.40 + 79.41 + public void method() throws ScriptException { 79.42 + // a context with a new global bindings, same engine bindings 79.43 + final ScriptContext sc = new SimpleScriptContext(); 79.44 + final Bindings global = new SimpleBindings(); 79.45 + sc.setBindings(global, ScriptContext.GLOBAL_SCOPE); 79.46 + sc.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE); 79.47 + global.put("text", "methodText"); 79.48 + String value = engine.eval("text", sc).toString(); 79.49 + Assert.assertEquals(value, "methodText"); 79.50 + } 79.51 + } 79.52 + 79.53 + // @bug 8081609: engine.eval call from a java method which 79.54 + // was called from a previous engine.eval results in wrong 79.55 + // ScriptContext being used. 79.56 + @Test 79.57 + public void recursiveEvalCallScriptContextTest() throws ScriptException { 79.58 + new RecursiveEval().program(); 79.59 + } 79.60 }
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 80.2 +++ b/test/src/jdk/nashorn/internal/runtime/test/AddAndRemoveOnListAdapterOutsideOfJavaScriptContextTest.java Wed Jun 17 23:30:09 2015 -0700 80.3 @@ -0,0 +1,102 @@ 80.4 +/* 80.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 80.7 + * 80.8 + * This code is free software; you can redistribute it and/or modify it 80.9 + * under the terms of the GNU General Public License version 2 only, as 80.10 + * published by the Free Software Foundation. Oracle designates this 80.11 + * particular file as subject to the "Classpath" exception as provided 80.12 + * by Oracle in the LICENSE file that accompanied this code. 80.13 + * 80.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 80.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 80.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 80.17 + * version 2 for more details (a copy is included in the LICENSE file that 80.18 + * accompanied this code). 80.19 + * 80.20 + * You should have received a copy of the GNU General Public License version 80.21 + * 2 along with this work; if not, write to the Free Software Foundation, 80.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 80.23 + * 80.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 80.25 + * or visit www.oracle.com if you need additional information or have any 80.26 + * questions. 80.27 + */ 80.28 + 80.29 +package jdk.nashorn.internal.runtime.test; 80.30 + 80.31 +import static org.testng.Assert.assertEquals; 80.32 + 80.33 +import java.util.Arrays; 80.34 +import java.util.Deque; 80.35 +import java.util.List; 80.36 +import javax.script.ScriptEngine; 80.37 +import javax.script.ScriptException; 80.38 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; 80.39 +import org.testng.annotations.Test; 80.40 + 80.41 +/** 80.42 + * @bug 8081204 80.43 + * @summary adding and removing elements to a ListAdapter outside of JS context should work. 80.44 + */ 80.45 +@SuppressWarnings("javadoc") 80.46 +public class AddAndRemoveOnListAdapterOutsideOfJavaScriptContextTest { 80.47 + 80.48 + @SuppressWarnings("unchecked") 80.49 + private static <T> T getListAdapter() throws ScriptException { 80.50 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 80.51 + return (T)engine.eval("Java.to([1, 2, 3, 4], 'java.util.List')"); 80.52 + } 80.53 + 80.54 + @Test 80.55 + public void testInvokePush() throws ScriptException { 80.56 + final Deque<Object> l = getListAdapter(); 80.57 + l.addLast(5); 80.58 + assertEquals(l.size(), 5); 80.59 + assertEquals(l.getLast(), 5); 80.60 + assertEquals(l.getFirst(), 1); 80.61 + } 80.62 + 80.63 + @Test 80.64 + public void testPop() throws ScriptException { 80.65 + final Deque<Object> l = getListAdapter(); 80.66 + assertEquals(l.removeLast(), 4); 80.67 + assertEquals(l.size(), 3); 80.68 + assertEquals(l.getLast(), 3); 80.69 + } 80.70 + 80.71 + @Test 80.72 + public void testUnshift() throws ScriptException { 80.73 + final Deque<Object> l = getListAdapter(); 80.74 + l.addFirst(0); 80.75 + assertEquals(l.getFirst(), 0); 80.76 + assertEquals(l.getLast(), 4); 80.77 + assertEquals(l.size(), 5); 80.78 + } 80.79 + 80.80 + @Test 80.81 + public void testShift() throws ScriptException { 80.82 + final Deque<Object> l = getListAdapter(); 80.83 + l.removeFirst(); 80.84 + assertEquals(l.getFirst(), 2); 80.85 + assertEquals(l.getLast(), 4); 80.86 + assertEquals(l.size(), 3); 80.87 + } 80.88 + 80.89 + @Test 80.90 + public void testSpliceAdd() throws ScriptException { 80.91 + final List<Object> l = getListAdapter(); 80.92 + assertEquals(l, Arrays.asList(1, 2, 3, 4)); 80.93 + l.add(2, "foo"); 80.94 + assertEquals(l, Arrays.asList(1, 2, "foo", 3, 4)); 80.95 + } 80.96 + 80.97 + 80.98 + @Test 80.99 + public void testSpliceRemove() throws ScriptException { 80.100 + final List<Object> l = getListAdapter(); 80.101 + assertEquals(l, Arrays.asList(1, 2, 3, 4)); 80.102 + l.remove(2); 80.103 + assertEquals(l, Arrays.asList(1, 2, 4)); 80.104 + } 80.105 +}
81.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Mon Jun 15 11:41:52 2015 -0700 81.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Wed Jun 17 23:30:09 2015 -0700 81.3 @@ -225,7 +225,7 @@ 81.4 boolean explicitOptimistic = false; 81.5 81.6 String allContent = new String(Files.readAllBytes(testFile)); 81.7 - Iterator<String> scanner = ScriptingFunctions.tokenizeCommandLine(allContent).iterator(); 81.8 + Iterator<String> scanner = ScriptingFunctions.tokenizeString(allContent).iterator(); 81.9 while (scanner.hasNext()) { 81.10 // TODO: Scan for /ref=file qualifiers, etc, to determine run 81.11 // behavior