Thu, 26 Jun 2014 08:46:39 -0700
Merge
.hgtags | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Wed Jun 18 13:32:19 2014 -0700 1.2 +++ b/.hgtags Thu Jun 26 08:46:39 2014 -0700 1.3 @@ -258,6 +258,7 @@ 1.4 bc23b19e08eb1575663044902b6442ceaafa924f jdk8u5-b11 1.5 18b007062905dac9304605955a4b84eaf2a08553 jdk8u5-b12 1.6 e4fb85d69d6b33c9561b932ec5515f44c53c1017 jdk8u5-b13 1.7 +53cc5fda790e0f90dca53fb459c70517d76680bc jdk8u5-b31 1.8 53cc5fda790e0f90dca53fb459c70517d76680bc jdk8u11-b01 1.9 4dda2b1e51aa7977f53c261f983230fe505bbc3e jdk8u11-b02 1.10 161f144c4e84037f655a2f6ebb0ba3057e8b18fa jdk8u11-b03 1.11 @@ -291,6 +292,7 @@ 1.12 046bf6509a1f3fcf8c9c8b5d09beec0400f704d1 jdk8u20-b17 1.13 847387339a561e50353c0805a54ec14eca256d2a jdk8u20-b18 1.14 b047df215de40cb8a87ff1e2bac0b57bb9e2e121 jdk8u20-b19 1.15 +ed3439dca4a73a2dd4a284f3457f0af216a3eb55 jdk8u20-b20 1.16 7001e9f95b443a75e432205a29974c05b88e0fdc jdk8u25-b00 1.17 a9f77bd14874d5f8fdf935704dd54a0451f2bc69 jdk8u25-b01 1.18 895e47783e2ee6823496a5ae84039a4f50311c7d jdk8u25-b02
2.1 --- a/make/build.xml Wed Jun 18 13:32:19 2014 -0700 2.2 +++ b/make/build.xml Thu Jun 26 08:46:39 2014 -0700 2.3 @@ -193,14 +193,16 @@ 2.4 </jar> 2.5 </target> 2.6 2.7 - <target name="javadoc" depends="prepare"> 2.8 - <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" windowtitle="${nashorn.product.name} ${nashorn.version}" additionalparam="-quiet" failonerror="true"> 2.9 + <target name="javadoc" depends="jar"> 2.10 + <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" 2.11 + extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}" 2.12 + additionalparam="-quiet" failonerror="true"> 2.13 <classpath> 2.14 <pathelement location="${build.classes.dir}"/> 2.15 </classpath> 2.16 <fileset dir="${src.dir}" includes="**/*.java"/> 2.17 <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/> 2.18 - <link href="http://docs.oracle.com/javase/7/docs/api/"/> 2.19 + <link href="http://docs.oracle.com/javase/8/docs/api/"/> 2.20 <!-- The following tags are used only in ASM sources - just ignore these --> 2.21 <tag name="label" description="label tag in ASM sources" enabled="false"/> 2.22 <tag name="linked" description="linked tag in ASM sources" enabled="false"/> 2.23 @@ -208,6 +210,19 @@ 2.24 </javadoc> 2.25 </target> 2.26 2.27 + <!-- generate javadoc only for nashorn extension api classes --> 2.28 + <target name="javadocapi" depends="jar"> 2.29 + <javadoc destdir="${dist.javadoc.dir}" use="yes" extdirs="${nashorn.ext.path}" 2.30 + windowtitle="${nashorn.product.name}" additionalparam="-quiet" failonerror="true"> 2.31 + <classpath> 2.32 + <pathelement location="${build.classes.dir}"/> 2.33 + </classpath> 2.34 + <fileset dir="${src.dir}" includes="jdk/nashorn/api/**/*.java"/> 2.35 + <link href="http://docs.oracle.com/javase/8/docs/api/"/> 2.36 + </javadoc> 2.37 + </target> 2.38 + 2.39 + 2.40 <!-- generate shell.html for shell tool documentation --> 2.41 <target name="shelldoc" depends="jar"> 2.42 <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true"> 2.43 @@ -336,35 +351,32 @@ 2.44 <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under test/lib directory."/> 2.45 </target> 2.46 2.47 - <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available"> 2.48 - <fileset id="test.classes" dir="${build.test.classes.dir}"> 2.49 - <include name="**/api/javaaccess/*Test.class"/> 2.50 - <include name="**/api/scripting/*Test.class"/> 2.51 - <include name="**/codegen/*Test.class"/> 2.52 - <include name="**/parser/*Test.class"/> 2.53 - <include name="**/runtime/*Test.class"/> 2.54 - <include name="**/runtime/regexp/*Test.class"/> 2.55 - <include name="**/runtime/regexp/joni/*Test.class"/> 2.56 - <include name="**/framework/*Test.class"/> 2.57 - </fileset> 2.58 + <!-- only to be invoked as dependency of "test" target --> 2.59 + <target name="-test-classes-all" depends="jar" unless="test.class"> 2.60 + <fileset id="test.classes" dir="${build.test.classes.dir}"> 2.61 + <include name="**/api/javaaccess/*Test.class"/> 2.62 + <include name="**/api/scripting/*Test.class"/> 2.63 + <include name="**/codegen/*Test.class"/> 2.64 + <include name="**/parser/*Test.class"/> 2.65 + <include name="**/runtime/*Test.class"/> 2.66 + <include name="**/runtime/regexp/*Test.class"/> 2.67 + <include name="**/runtime/regexp/joni/*Test.class"/> 2.68 + <include name="**/framework/*Test.class"/> 2.69 + </fileset> 2.70 + </target> 2.71 2.72 + <!-- only to be invoked as dependency of "test" target --> 2.73 + <target name="-test-classes-single" depends="jar" if="test.class"> 2.74 + <fileset id="test.classes" dir="${build.test.classes.dir}"> 2.75 + <include name="${test.class}*"/> 2.76 + </fileset> 2.77 + </target> 2.78 + 2.79 + <!-- only to be invoked as dependency of "test" target --> 2.80 + <target name="-test-nosecurity" unless="test.class"> 2.81 <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}"> 2.82 <include name="**/framework/ScriptTest.class"/> 2.83 </fileset> 2.84 - 2.85 - <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes" 2.86 - verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}"> 2.87 - <jvmarg line="${ext.class.path}"/> 2.88 - <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/> 2.89 - <propertyset> 2.90 - <propertyref prefix="test-sys-prop."/> 2.91 - <mapper from="test-sys-prop.*" to="*" type="glob"/> 2.92 - </propertyset> 2.93 - <sysproperty key="test.js.excludes.file" value="${exclude.list}"/> 2.94 - <classpath> 2.95 - <pathelement path="${run.test.classpath}"/> 2.96 - </classpath> 2.97 - </testng> 2.98 <testng outputdir="${build.nosecurity.test.results.dir}" classfilesetref="test.nosecurity.classes" 2.99 verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}"> 2.100 <jvmarg line="${ext.class.path}"/> 2.101 @@ -382,6 +394,28 @@ 2.102 </testng> 2.103 </target> 2.104 2.105 + <!-- only to be invoked as dependency of "test" target --> 2.106 + <target name="-test-security"> 2.107 + <delete dir="${build.dir}/nashorn_code_cache"/> 2.108 + <property name="debug.test.jvmargs" value=""/> 2.109 + <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes" 2.110 + verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}"> 2.111 + <jvmarg line="${ext.class.path}"/> 2.112 + <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/> 2.113 + <jvmarg line="${debug.test.jvmargs}"/> 2.114 + <propertyset> 2.115 + <propertyref prefix="test-sys-prop."/> 2.116 + <mapper from="test-sys-prop.*" to="*" type="glob"/> 2.117 + </propertyset> 2.118 + <sysproperty key="test.js.excludes.file" value="${exclude.list}"/> 2.119 + <classpath> 2.120 + <pathelement path="${run.test.classpath}"/> 2.121 + </classpath> 2.122 + </testng> 2.123 + </target> 2.124 + 2.125 + <target name="test" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file, -test-security, -test-nosecurity" if="testng.available"/> 2.126 + 2.127 <target name="test-basicparallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file"> 2.128 <!-- use just build.test.classes.dir to avoid referring to TestNG --> 2.129 <java classname="${parallel.test.runner}" dir="${basedir}" classpath="${build.test.classes.dir}" failonerror="true" fork="true">
3.1 --- a/make/nbproject/ide-file-targets.xml Wed Jun 18 13:32:19 2014 -0700 3.2 +++ b/make/nbproject/ide-file-targets.xml Thu Jun 26 08:46:39 2014 -0700 3.3 @@ -22,38 +22,14 @@ 3.4 questions. 3.5 --> 3.6 <project basedir=".." name="nashorn-IDE"> 3.7 - <property file="nbproject/nbjdk.properties"/> 3.8 - <property location="${netbeans.user}/build.properties" name="user.properties.file"/> 3.9 - <property file="${user.properties.file}"/> 3.10 - <import file="jdk.xml"/> 3.11 - <import file="${basedir}/build-init.xml"/> 3.12 - <!-- TODO: edit the following target according to your needs --> 3.13 - <!-- (more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle) --> 3.14 - <target depends="-jdk-init, init" name="debug-selected-file-in-src"> 3.15 - <fail unless="debug.class">Must set property 'debug.class'</fail> 3.16 - <ant antfile="build.xml" inheritall="false" target="jar"/> 3.17 + <target name="debug-selected-file-in-src"> 3.18 + <fail unless="test.class">Must set property 'debug.class'</fail> 3.19 <nbjpdastart addressproperty="jpda.address" name="nashorn" transport="dt_socket"> 3.20 <classpath path="${run.test.classpath}"/> 3.21 </nbjpdastart> 3.22 - <java classname="${debug.class}" fork="false"> 3.23 - <classpath path="${run.test.classpath}"/> 3.24 - <jvmarg line="${boot.class.path}"/> 3.25 - <jvmarg value="-Xdebug"/> 3.26 - <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/> 3.27 - <jvmarg line="${run.test.jvmargs}"/> 3.28 - <arg value="${debug.class}"/> 3.29 - </java> 3.30 - </target> 3.31 - <!-- TODO: edit the following target according to your needs --> 3.32 - <!-- (more info: http://www.netbeans.org/kb/articles/freeform-config.html#runsingle) --> 3.33 - <target depends="-jdk-init, init" name="run-selected-file-in-src"> 3.34 - <fail unless="run.class">Must set property 'run.class'</fail> 3.35 - <ant antfile="build.xml" inheritall="false" target="jar"/> 3.36 - <java classname="${run.class}" failonerror="true" fork="false"> 3.37 - <classpath path="${run.test.classpath}"/> 3.38 - <jvmarg line="${boot.class.path}"/> 3.39 - <jvmarg line="${run.test.jvmargs}"/> 3.40 - <arg value="${run.class}"/> 3.41 - </java> 3.42 + <ant antfile="build.xml" inheritall="false" target="test"> 3.43 + <property name="test.class" value="${test.class}"/> 3.44 + <property name="debug.test.jvmargs" value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/> 3.45 + </ant> 3.46 </target> 3.47 </project>
4.1 --- a/make/nbproject/project.xml Wed Jun 18 13:32:19 2014 -0700 4.2 +++ b/make/nbproject/project.xml Thu Jun 26 08:46:39 2014 -0700 4.3 @@ -98,27 +98,27 @@ 4.4 <script>nbproject/nbjdk.xml</script> 4.5 <target>debug-nb</target> 4.6 </action> 4.7 - <action name="debug.single"> 4.8 - <script>nbproject/ide-file-targets.xml</script> 4.9 - <target>debug-selected-file-in-src</target> 4.10 + <action name="run.single"> 4.11 + <script>build.xml</script> 4.12 + <target>test</target> 4.13 <context> 4.14 - <property>debug.class</property> 4.15 - <folder>test/src</folder> 4.16 + <property>test.class</property> 4.17 + <folder>../test/src</folder> 4.18 <pattern>\.java$</pattern> 4.19 - <format>java-name</format> 4.20 + <format>relative-path-noext</format> 4.21 <arity> 4.22 <one-file-only/> 4.23 </arity> 4.24 </context> 4.25 </action> 4.26 - <action name="run.single"> 4.27 + <action name="debug.single"> 4.28 <script>nbproject/ide-file-targets.xml</script> 4.29 - <target>run-selected-file-in-src</target> 4.30 + <target>debug-selected-file-in-src</target> 4.31 <context> 4.32 - <property>run.class</property> 4.33 - <folder>test/src</folder> 4.34 + <property>test.class</property> 4.35 + <folder>../test/src</folder> 4.36 <pattern>\.java$</pattern> 4.37 - <format>java-name</format> 4.38 + <format>relative-path-noext</format> 4.39 <arity> 4.40 <one-file-only/> 4.41 </arity>
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/samples/filebrowser.js Thu Jun 26 08:46:39 2014 -0700 5.3 @@ -0,0 +1,100 @@ 5.4 +#// Usage: jjs -fx filebrowser.js -- <start_dir> 5.5 + 5.6 +/* 5.7 + * Copyright (c) 2014, 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 +// Uses -fx and javafx TreeView to visualize directories 5.38 +if (!$OPTIONS._fx) { 5.39 + print("Usage: jjs -fx filebrowser.js -- <start_dir>"); 5.40 + exit(1); 5.41 +} 5.42 + 5.43 +// Java classes used 5.44 +var File = Java.type("java.io.File"); 5.45 +var Files = Java.type("java.nio.file.Files"); 5.46 + 5.47 +// check directory argument, if passed 5.48 +var dir = arguments.length > 0? new File(arguments[0]) : new File("."); 5.49 +if (! dir.isDirectory()) { 5.50 + print(dir + " is not a directory!"); 5.51 + exit(2); 5.52 +} 5.53 + 5.54 +// JavaFX classes used 5.55 +var FXCollections = Java.type("javafx.collections.FXCollections"); 5.56 +var Scene = Java.type("javafx.scene.Scene"); 5.57 +var TreeItem = Java.type("javafx.scene.control.TreeItem"); 5.58 +var TreeView = Java.type("javafx.scene.control.TreeView"); 5.59 + 5.60 +// create a subclass of JavaFX TreeItem class 5.61 +var LazyTreeItem = Java.extend(TreeItem); 5.62 + 5.63 +// lazily filling children of a directory LazyTreeItem 5.64 +function buildChildren(dir) { 5.65 + var children = FXCollections.observableArrayList(); 5.66 + var stream = Files.list(dir.toPath()); 5.67 + stream.forEach(function(path) { 5.68 + var file = path.toFile(); 5.69 + var item = file.isDirectory()? 5.70 + makeLazyTreeItem(file) : new TreeItem(file.name); 5.71 + children.add(item); 5.72 + }); 5.73 + stream.close(); 5.74 + return children; 5.75 +} 5.76 + 5.77 +// create an instance LazyTreeItem with override methods 5.78 +function makeLazyTreeItem(dir) { 5.79 + var item = new LazyTreeItem(dir.name) { 5.80 + expanded: false, 5.81 + isLeaf: function() false, 5.82 + getChildren: function() { 5.83 + if (! this.expanded) { 5.84 + // call super class (TreeItem) method 5.85 + Java.super(item).getChildren().setAll(buildChildren(dir)); 5.86 + this.expanded = true; 5.87 + } 5.88 + // call super class (TreeItem) method 5.89 + return Java.super(item).getChildren(); 5.90 + } 5.91 + } 5.92 + return item; 5.93 +} 5.94 + 5.95 +// JavaFX start method 5.96 +function start(stage) { 5.97 + stage.title = dir.absolutePath; 5.98 + var rootItem = makeLazyTreeItem(dir); 5.99 + rootItem.expanded = true; 5.100 + var tree = new TreeView(rootItem); 5.101 + stage.scene = new Scene(tree, 300, 450); 5.102 + stage.show(); 5.103 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/samples/word_histogram.js Thu Jun 26 08:46:39 2014 -0700 6.3 @@ -0,0 +1,53 @@ 6.4 +#nashorn word histogram of a file 6.5 + 6.6 +/* 6.7 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 6.8 + * 6.9 + * Redistribution and use in source and binary forms, with or without 6.10 + * modification, are permitted provided that the following conditions 6.11 + * are met: 6.12 + * 6.13 + * - Redistributions of source code must retain the above copyright 6.14 + * notice, this list of conditions and the following disclaimer. 6.15 + * 6.16 + * - Redistributions in binary form must reproduce the above copyright 6.17 + * notice, this list of conditions and the following disclaimer in the 6.18 + * documentation and/or other materials provided with the distribution. 6.19 + * 6.20 + * - Neither the name of Oracle nor the names of its 6.21 + * contributors may be used to endorse or promote products derived 6.22 + * from this software without specific prior written permission. 6.23 + * 6.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 6.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 6.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 6.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 6.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 6.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 6.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 6.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 6.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 6.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 6.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6.35 + */ 6.36 + 6.37 +/* 6.38 + * This example demonstrates how to print word histogram 6.39 + * of a given text file using regex, array and JSON 6.40 + * functions. 6.41 + */ 6.42 + 6.43 +if (arguments.length < 1) { 6.44 + print("Usage: jjs -scripting word_histogram.js -- <file>"); 6.45 + exit(1); 6.46 +} 6.47 + 6.48 +var obj = {}; 6.49 + 6.50 +readFully(arguments[0]). 6.51 + split(/[^\w+]/). 6.52 + forEach(function(x) 6.53 + (x in obj? obj[x]++ : obj[x] = 1)); 6.54 + 6.55 +print(JSON.stringify(obj)); 6.56 +
7.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Jun 18 13:32:19 2014 -0700 7.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Jun 26 08:46:39 2014 -0700 7.3 @@ -496,7 +496,7 @@ 7.4 public void setProto(final Object proto) { 7.5 inGlobal(new Callable<Void>() { 7.6 @Override public Void call() { 7.7 - sobj.setProtoCheck(unwrap(proto, global)); 7.8 + sobj.setPrototypeOf(unwrap(proto, global)); 7.9 return null; 7.10 } 7.11 }); 7.12 @@ -621,6 +621,7 @@ 7.13 /** 7.14 * Utilitity to convert this script object to the given type. 7.15 * 7.16 + * @param <T> destination type to convert to 7.17 * @param type destination type to convert to 7.18 * @return converted object 7.19 */
8.1 --- a/src/jdk/nashorn/api/scripting/package-info.java Wed Jun 18 13:32:19 2014 -0700 8.2 +++ b/src/jdk/nashorn/api/scripting/package-info.java Thu Jun 26 08:46:39 2014 -0700 8.3 @@ -32,7 +32,8 @@ 8.4 * ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("Nashorn"); 8.5 * </pre> 8.6 * <p>Nashorn script engines implement the optional {@link javax.script.Invocable} and {@link javax.script.Compilable} 8.7 - * interfaces, allowing for efficient pre-compilation and repeated execution of scripts. See 8.8 + * interfaces, allowing for efficient pre-compilation and repeated execution of scripts. In addition, 8.9 + * this package provides nashorn specific extension classes, interfaces and methods. See 8.10 * {@link jdk.nashorn.api.scripting.NashornScriptEngineFactory} for further details. 8.11 */ 8.12 package jdk.nashorn.api.scripting;
9.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Jun 18 13:32:19 2014 -0700 9.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Thu Jun 26 08:46:39 2014 -0700 9.3 @@ -1500,7 +1500,9 @@ 9.4 method.dup(); 9.5 if (protoNode != null) { 9.6 load(protoNode); 9.7 - method.invoke(ScriptObject.SET_PROTO_CHECK); 9.8 + // take care of { __proto__: 34 } or some such! 9.9 + method.convert(Type.OBJECT); 9.10 + method.invoke(ScriptObject.SET_PROTO_FROM_LITERAL); 9.11 } else { 9.12 globalObjectPrototype(); 9.13 method.invoke(ScriptObject.SET_PROTO);
10.1 --- a/src/jdk/nashorn/internal/ir/annotations/Reference.java Wed Jun 18 13:32:19 2014 -0700 10.2 +++ b/src/jdk/nashorn/internal/ir/annotations/Reference.java Thu Jun 26 08:46:39 2014 -0700 10.3 @@ -32,9 +32,7 @@ 10.4 * Reference node in AST, i.e. anything not a copy. Important for 10.5 * AST traversal and cloning. Cloning currently as a rule uses 10.6 * existingOrSame for references and otherwise existingOrCopy 10.7 - * <p> 10.8 */ 10.9 - 10.10 @Retention(value=RetentionPolicy.RUNTIME) 10.11 public @interface Reference { 10.12 // EMPTY
11.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Jun 18 13:32:19 2014 -0700 11.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Jun 26 08:46:39 2014 -0700 11.3 @@ -1908,8 +1908,8 @@ 11.4 11.5 // ES6 draft compliant __proto__ property of Object.prototype 11.6 // accessors on Object.prototype for "__proto__" 11.7 - final ScriptFunction getProto = ScriptFunctionImpl.makeFunction("getProto", ScriptObject.GETPROTO); 11.8 - final ScriptFunction setProto = ScriptFunctionImpl.makeFunction("setProto", ScriptObject.SETPROTOCHECK); 11.9 + final ScriptFunction getProto = ScriptFunctionImpl.makeFunction("getProto", NativeObject.GET__PROTO__); 11.10 + final ScriptFunction setProto = ScriptFunctionImpl.makeFunction("setProto", NativeObject.SET__PROTO__); 11.11 ObjectPrototype.addOwnProperty("__proto__", Attribute.NOT_ENUMERABLE, getProto, setProto); 11.12 11.13
12.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Wed Jun 18 13:32:19 2014 -0700 12.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Thu Jun 26 08:46:39 2014 -0700 12.3 @@ -327,7 +327,12 @@ 12.4 final Object exception = ECMAException.getException(sobj); 12.5 if (exception instanceof Throwable) { 12.6 Object value = getScriptStackString(sobj, (Throwable)exception); 12.7 - sobj.put(STACK, value, false); 12.8 + if (sobj.hasOwnProperty(STACK)) { 12.9 + sobj.put(STACK, value, false); 12.10 + } else { 12.11 + sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); 12.12 + } 12.13 + 12.14 return value; 12.15 } 12.16 12.17 @@ -346,7 +351,12 @@ 12.18 public static Object setStack(final Object self, final Object value) { 12.19 Global.checkObject(self); 12.20 final ScriptObject sobj = (ScriptObject)self; 12.21 - sobj.set(STACK, value, false); 12.22 + if (sobj.hasOwnProperty(STACK)) { 12.23 + sobj.put(STACK, value, false); 12.24 + } else { 12.25 + sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); 12.26 + } 12.27 + 12.28 return value; 12.29 } 12.30
13.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Wed Jun 18 13:32:19 2014 -0700 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Thu Jun 26 08:46:39 2014 -0700 13.3 @@ -25,6 +25,7 @@ 13.4 13.5 package jdk.nashorn.internal.objects; 13.6 13.7 +import static jdk.nashorn.internal.lookup.Lookup.MH; 13.8 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 13.9 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 13.10 13.11 @@ -74,6 +75,9 @@ 13.12 */ 13.13 @ScriptClass("Object") 13.14 public final class NativeObject { 13.15 + public static final MethodHandle GET__PROTO__ = findOwnMH("get__proto__", ScriptObject.class, Object.class); 13.16 + public static final MethodHandle SET__PROTO__ = findOwnMH("set__proto__", Object.class, Object.class, Object.class); 13.17 + 13.18 private static final Object TO_STRING = new Object(); 13.19 13.20 private static InvokeByName getTO_STRING() { 13.21 @@ -86,6 +90,35 @@ 13.22 }); 13.23 } 13.24 13.25 + @SuppressWarnings("unused") 13.26 + private static ScriptObject get__proto__(final Object self) { 13.27 + // See ES6 draft spec: B.2.2.1.1 get Object.prototype.__proto__ 13.28 + // Step 1 Let O be the result of calling ToObject passing the this. 13.29 + final Object obj = Global.toObject(self); 13.30 + Global.checkObject(obj); 13.31 + final ScriptObject sobj = (ScriptObject)obj; 13.32 + return sobj.getProto(); 13.33 + } 13.34 + 13.35 + @SuppressWarnings("unused") 13.36 + private static Object set__proto__(final Object self, final Object proto) { 13.37 + // See ES6 draft spec: B.2.2.1.2 set Object.prototype.__proto__ 13.38 + // Step 1 13.39 + Global.checkObjectCoercible(self); 13.40 + // Step 4 13.41 + if (! (self instanceof ScriptObject)) { 13.42 + return UNDEFINED; 13.43 + } 13.44 + 13.45 + final ScriptObject sobj = (ScriptObject)self; 13.46 + // __proto__ assignment ignores non-nulls and non-objects 13.47 + // step 3: If Type(proto) is neither Object nor Null, then return undefined. 13.48 + if (proto == null || proto instanceof ScriptObject) { 13.49 + sobj.setPrototypeOf(proto); 13.50 + } 13.51 + return UNDEFINED; 13.52 + } 13.53 + 13.54 private static final MethodType MIRROR_GETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class); 13.55 private static final MethodType MIRROR_SETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class, Object.class); 13.56 13.57 @@ -160,7 +193,7 @@ 13.58 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 13.59 public static Object setPrototypeOf(final Object self, final Object obj, final Object proto) { 13.60 if (obj instanceof ScriptObject) { 13.61 - ((ScriptObject)obj).setProtoCheck(proto); 13.62 + ((ScriptObject)obj).setPrototypeOf(proto); 13.63 return obj; 13.64 } else if (obj instanceof ScriptObjectMirror) { 13.65 ((ScriptObjectMirror)obj).setProto(proto); 13.66 @@ -777,4 +810,8 @@ 13.67 return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation, 13.68 methodType), false, source); 13.69 } 13.70 + 13.71 + private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 13.72 + return MH.findStatic(MethodHandles.lookup(), NativeObject.class, name, MH.type(rtype, types)); 13.73 + } 13.74 }
14.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Jun 18 13:32:19 2014 -0700 14.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Thu Jun 26 08:46:39 2014 -0700 14.3 @@ -731,6 +731,12 @@ 14.4 if (nextChar == '$') { 14.5 // Skip past $ 14.6 cursor++; 14.7 + if (cursor == replacement.length()) { 14.8 + // nothing after "$" 14.9 + sb.append('$'); 14.10 + break; 14.11 + } 14.12 + 14.13 nextChar = replacement.charAt(cursor); 14.14 final int firstDigit = nextChar - '0'; 14.15
15.1 --- a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Wed Jun 18 13:32:19 2014 -0700 15.2 +++ b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java Thu Jun 26 08:46:39 2014 -0700 15.3 @@ -25,12 +25,20 @@ 15.4 15.5 package jdk.nashorn.internal.runtime; 15.6 15.7 +import static jdk.nashorn.internal.codegen.CompilerConstants.SOURCE; 15.8 + 15.9 +import java.lang.invoke.MethodHandle; 15.10 +import java.lang.reflect.Field; 15.11 +import java.net.URL; 15.12 import java.util.HashSet; 15.13 import java.util.Set; 15.14 +import jdk.nashorn.internal.scripts.JS; 15.15 15.16 /** 15.17 * This class provides support for external debuggers. Its primary purpose is 15.18 * is to simplify the debugger tasks and provide better performance. 15.19 + * Even though the methods are not public, there are still part of the 15.20 + * external debugger interface. 15.21 */ 15.22 final class DebuggerSupport { 15.23 /** 15.24 @@ -46,6 +54,11 @@ 15.25 */ 15.26 @SuppressWarnings("unused") 15.27 DebuggerValueDesc forceLoad = new DebuggerValueDesc(null, false, null, null); 15.28 + 15.29 + // Hook to force the loading of the SourceInfo class 15.30 + @SuppressWarnings("unused") 15.31 + final 15.32 + SourceInfo srcInfo = new SourceInfo(null, 0, null, null); 15.33 } 15.34 15.35 /** This class is used to send a bulk description of a value. */ 15.36 @@ -70,6 +83,54 @@ 15.37 } 15.38 } 15.39 15.40 + static class SourceInfo { 15.41 + final String name; 15.42 + final URL url; 15.43 + final int hash; 15.44 + final char[] content; 15.45 + 15.46 + SourceInfo(final String name, final int hash, final URL url, final char[] content) { 15.47 + this.name = name; 15.48 + this.hash = hash; 15.49 + this.url = url; 15.50 + this.content = content; 15.51 + } 15.52 + } 15.53 + 15.54 + /** 15.55 + * Hook that is called just before invoking method handle 15.56 + * from ScriptFunctionData via invoke, constructor method calls. 15.57 + * 15.58 + * @param mh script class method about to be invoked. 15.59 + */ 15.60 + static void notifyInvoke(final MethodHandle mh) { 15.61 + // Do nothing here. This is placeholder method on which a 15.62 + // debugger can place a breakpoint so that it can access the 15.63 + // (script class) method handle that is about to be invoked. 15.64 + // See ScriptFunctionData.invoke and ScriptFunctionData.construct. 15.65 + } 15.66 + 15.67 + /** 15.68 + * Return the script source info for the given script class. 15.69 + * 15.70 + * @param clazz compiled script class 15.71 + * @return SourceInfo 15.72 + */ 15.73 + static SourceInfo getSourceInfo(final Class<?> clazz) { 15.74 + if (JS.class.isAssignableFrom(clazz)) { 15.75 + try { 15.76 + final Field sourceField = clazz.getDeclaredField(SOURCE.symbolName()); 15.77 + sourceField.setAccessible(true); 15.78 + final Source src = (Source) sourceField.get(null); 15.79 + return src.getSourceInfo(); 15.80 + } catch (final IllegalAccessException | NoSuchFieldException ignored) { 15.81 + return null; 15.82 + } 15.83 + } 15.84 + 15.85 + return null; 15.86 + } 15.87 + 15.88 /** 15.89 * Return the current context global. 15.90 * @return context global. 15.91 @@ -84,7 +145,7 @@ 15.92 * @param self Receiver to use. 15.93 * @param string String to evaluate. 15.94 * @param returnException true if exceptions are to be returned. 15.95 - * @return Result of eval as string, or, an exception or null depending on returnException. 15.96 + * @return Result of eval, or, an exception or null depending on returnException. 15.97 */ 15.98 static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) { 15.99 final ScriptObject global = Context.getGlobal(); 15.100 @@ -235,7 +296,7 @@ 15.101 * @param value Arbitrary value to be displayed by the debugger. 15.102 * @return A string representation of the value or an array of DebuggerValueDesc. 15.103 */ 15.104 - private static String valueAsString(final Object value) { 15.105 + static String valueAsString(final Object value) { 15.106 final JSType type = JSType.of(value); 15.107 15.108 switch (type) {
16.1 --- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Wed Jun 18 13:32:19 2014 -0700 16.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Thu Jun 26 08:46:39 2014 -0700 16.3 @@ -459,5 +459,4 @@ 16.4 private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 16.5 return MH.findStatic(MethodHandles.lookup(), GlobalFunctions.class, name, MH.type(rtype, types)); 16.6 } 16.7 - 16.8 }
17.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Jun 18 13:32:19 2014 -0700 17.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Thu Jun 26 08:46:39 2014 -0700 17.3 @@ -519,6 +519,8 @@ 17.4 final Object selfObj = convertThisObject(self); 17.5 final Object[] args = arguments == null ? ScriptRuntime.EMPTY_ARRAY : arguments; 17.6 17.7 + DebuggerSupport.notifyInvoke(mh); 17.8 + 17.9 if (isVarArg(mh)) { 17.10 if (needsCallee(mh)) { 17.11 return mh.invokeExact(fn, selfObj, args); 17.12 @@ -572,6 +574,8 @@ 17.13 final MethodHandle mh = getGenericConstructor(); 17.14 final Object[] args = arguments == null ? ScriptRuntime.EMPTY_ARRAY : arguments; 17.15 17.16 + DebuggerSupport.notifyInvoke(mh); 17.17 + 17.18 if (isVarArg(mh)) { 17.19 if (needsCallee(mh)) { 17.20 return mh.invokeExact(fn, args);
18.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Jun 18 13:32:19 2014 -0700 18.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Jun 26 08:46:39 2014 -0700 18.3 @@ -132,9 +132,7 @@ 18.4 18.5 /** Method handle to retrive prototype of this object */ 18.6 public static final MethodHandle GETPROTO = findOwnMH("getProto", ScriptObject.class); 18.7 - /** Method handle to set prototype of this object */ 18.8 - public static final MethodHandle SETPROTOCHECK = findOwnMH("setProtoCheck", void.class, Object.class); 18.9 - static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class, boolean.class); 18.10 + static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class); 18.11 static final MethodHandle GLOBALFILTER = findOwnMH("globalFilter", Object.class, Object.class); 18.12 18.13 static final MethodHandle SETFIELD = findOwnMH("setField", void.class, CallSiteDescriptor.class, PropertyMap.class, PropertyMap.class, MethodHandle.class, Object.class, Object.class); 18.14 @@ -160,7 +158,7 @@ 18.15 public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setInitialProto", void.class, ScriptObject.class); 18.16 18.17 /** Method handle for setting the proto of a ScriptObject after checking argument */ 18.18 - public static final Call SET_PROTO_CHECK = virtualCallNoLookup(ScriptObject.class, "setProtoCheck", void.class, Object.class); 18.19 + public static final Call SET_PROTO_FROM_LITERAL = virtualCallNoLookup(ScriptObject.class, "setProtoFromLiteral", void.class, Object.class); 18.20 18.21 /** Method handle for setting the user accessors of a ScriptObject */ 18.22 public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 18.23 @@ -1127,14 +1125,21 @@ 18.24 18.25 /** 18.26 * Set the __proto__ of an object with checks. 18.27 + * This is the built-in operation [[SetPrototypeOf]] 18.28 + * See ES6 draft spec: 9.1.2 [[SetPrototypeOf]] (V) 18.29 + * 18.30 * @param newProto Prototype to set. 18.31 */ 18.32 - public final void setProtoCheck(final Object newProto) { 18.33 - if (!isExtensible()) { 18.34 - throw typeError("__proto__.set.non.extensible", ScriptRuntime.safeToString(this)); 18.35 - } 18.36 - 18.37 + public final void setPrototypeOf(final Object newProto) { 18.38 if (newProto == null || newProto instanceof ScriptObject) { 18.39 + if (!isExtensible()) { 18.40 + // okay to set same proto again - even if non-extensible 18.41 + if (newProto == getProto()) { 18.42 + return; 18.43 + } 18.44 + throw typeError("__proto__.set.non.extensible", ScriptRuntime.safeToString(this)); 18.45 + } 18.46 + 18.47 // check for circularity 18.48 ScriptObject p = (ScriptObject)newProto; 18.49 while (p != null) { 18.50 @@ -1145,14 +1150,27 @@ 18.51 } 18.52 setProto((ScriptObject)newProto); 18.53 } else { 18.54 - final Global global = Context.getGlobal(); 18.55 - final Object newProtoObject = JSType.toScriptObject(global, newProto); 18.56 - 18.57 - if (newProtoObject instanceof ScriptObject) { 18.58 - setProto((ScriptObject)newProtoObject); 18.59 - } else { 18.60 - throw typeError(global, "cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); 18.61 - } 18.62 + throw typeError("cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); 18.63 + } 18.64 + } 18.65 + 18.66 + /** 18.67 + * Set the __proto__ of an object from an object literal. 18.68 + * See ES6 draft spec: B.3.1 __proto__ Property Names in 18.69 + * Object Initializers. Step 6 handling of "__proto__". 18.70 + * 18.71 + * @param newProto Prototype to set. 18.72 + */ 18.73 + public final void setProtoFromLiteral(final Object newProto) { 18.74 + if (newProto == null || newProto instanceof ScriptObject) { 18.75 + setPrototypeOf(newProto); 18.76 + } else { 18.77 + // Some non-object, non-null. Then, we need to set 18.78 + // Object.prototype as the new __proto__ 18.79 + // 18.80 + // var obj = { __proto__ : 34 }; 18.81 + // print(obj.__proto__ === Object.prototype); // => true 18.82 + setPrototypeOf(Global.objectPrototype()); 18.83 } 18.84 } 18.85 18.86 @@ -1727,7 +1745,7 @@ 18.87 protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { 18.88 final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); 18.89 if (request.isCallSiteUnstable() || hasWithScope()) { 18.90 - return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator), isScope() && NashornCallSiteDescriptor.isScope(desc)); 18.91 + return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator)); 18.92 } 18.93 18.94 final FindProperty find = findProperty(name, true); 18.95 @@ -1770,22 +1788,19 @@ 18.96 } 18.97 18.98 private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, 18.99 - final boolean isMethod, final boolean isScope) { 18.100 - final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod, isScope); 18.101 + final boolean isMethod) { 18.102 + final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod); 18.103 final MethodHandle guard = getScriptObjectGuard(desc.getMethodType()); 18.104 return new GuardedInvocation(invoker, guard); 18.105 } 18.106 18.107 @SuppressWarnings("unused") 18.108 - private Object megamorphicGet(final String key, final boolean isMethod, final boolean isScope) { 18.109 + private Object megamorphicGet(final String key, final boolean isMethod) { 18.110 final FindProperty find = findProperty(key, true); 18.111 18.112 if (find != null) { 18.113 return find.getObjectValue(); 18.114 } 18.115 - if (isScope) { 18.116 - throw referenceError("not.defined", key); 18.117 - } 18.118 18.119 return isMethod ? getNoSuchMethod(key) : invokeNoSuchProperty(key); 18.120 }
19.1 --- a/src/jdk/nashorn/internal/runtime/Source.java Wed Jun 18 13:32:19 2014 -0700 19.2 +++ b/src/jdk/nashorn/internal/runtime/Source.java Thu Jun 26 08:46:39 2014 -0700 19.3 @@ -124,6 +124,11 @@ 19.4 } 19.5 } 19.6 19.7 + /* package-private */ 19.8 + DebuggerSupport.SourceInfo getSourceInfo() { 19.9 + return new DebuggerSupport.SourceInfo(getName(), data.hashCode(), data.url(), data.array()); 19.10 + } 19.11 + 19.12 // Wrapper to manage lazy loading 19.13 private static interface Data { 19.14
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/script/basic/JDK-8044520.js Thu Jun 26 08:46:39 2014 -0700 20.3 @@ -0,0 +1,145 @@ 20.4 +/* 20.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/** 20.28 + * JDK-8044520: Nashorn cannot execute node.js's express module 20.29 + * 20.30 + * @test 20.31 + * @run 20.32 + */ 20.33 + 20.34 +function checkNullProto() { 20.35 + var obj = {}; 20.36 + obj.__proto__ = null; 20.37 + var proto = Object.getPrototypeOf(obj); 20.38 + if (typeof proto != 'object' || proto !== null) { 20.39 + fail("__proto__ can't be set to null!"); 20.40 + } 20.41 +} 20.42 + 20.43 +checkNullProto(); 20.44 + 20.45 +function checkSetProto(proto) { 20.46 + var obj = {}; 20.47 + obj.__proto__ = proto; 20.48 + if (Object.getPrototypeOf(obj) !== Object.prototype) { 20.49 + fail("obj.__proto__ set not ignored for " + proto); 20.50 + } 20.51 +} 20.52 + 20.53 +checkSetProto(undefined); 20.54 +checkSetProto(42); 20.55 +checkSetProto(false); 20.56 +checkSetProto("hello"); 20.57 + 20.58 +function checkLiteralSetProto(proto) { 20.59 + var obj = { __proto__: proto }; 20.60 + if (obj.__proto__ !== Object.prototype) { 20.61 + fail("object literal _proto__ set not ignored for " + proto); 20.62 + } 20.63 +} 20.64 + 20.65 +checkLiteralSetProto(undefined); 20.66 +checkLiteralSetProto(34); 20.67 +checkLiteralSetProto(true); 20.68 +checkLiteralSetProto("world"); 20.69 + 20.70 +function checkNullProtoFromLiteral() { 20.71 + var obj = { __proto__: null }; 20.72 + var proto = Object.getPrototypeOf(obj); 20.73 + if (typeof proto != 'object' || proto !== null) { 20.74 + fail("__proto__ can't be set to null!"); 20.75 + } 20.76 +} 20.77 + 20.78 +checkNullProtoFromLiteral(); 20.79 + 20.80 +function checkSetPrototypeOf(proto) { 20.81 + try { 20.82 + Object.setPrototypeOf({}, proto); 20.83 + fail("should have thrown error for " + proto); 20.84 + } catch (e) { 20.85 + if (! (e instanceof TypeError)) { 20.86 + fail("should have thrown TypeError, got " + e); 20.87 + } 20.88 + } 20.89 +} 20.90 + 20.91 +checkSetPrototypeOf(undefined); 20.92 +checkSetPrototypeOf(43); 20.93 +checkSetPrototypeOf(false); 20.94 +checkSetPrototypeOf("nashorn"); 20.95 + 20.96 +function checkNullSetPrototypeOf() { 20.97 + var obj = { }; 20.98 + Object.setPrototypeOf(obj, null); 20.99 + var proto = Object.getPrototypeOf(obj); 20.100 + if (typeof proto != 'object' || proto !== null) { 20.101 + fail("__proto__ can't be set to null!"); 20.102 + } 20.103 +} 20.104 + 20.105 +checkNullSetPrototypeOf(); 20.106 + 20.107 +var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); 20.108 + 20.109 +function checkProtoGetterOnPrimitive(value) { 20.110 + // call __proto__ getter on primitive - check ToObject 20.111 + // is called on 'this' value as per draft spec 20.112 + if (desc.get.call(value) !== Object(value).__proto__) { 20.113 + fail("can't call __proto__ getter on " + value); 20.114 + } 20.115 +} 20.116 + 20.117 +checkProtoGetterOnPrimitive(32); 20.118 +checkProtoGetterOnPrimitive(false); 20.119 +checkProtoGetterOnPrimitive("great!"); 20.120 + 20.121 +function checkProtoSetterOnNonObjectThis(self) { 20.122 + try { 20.123 + desc.set.call(self); 20.124 + fail("should have thrown TypeError"); 20.125 + } catch (e) { 20.126 + if (! (e instanceof TypeError)) { 20.127 + fail("should throw TypeError on non-object self, got " +e); 20.128 + } 20.129 + } 20.130 +} 20.131 + 20.132 +checkProtoSetterOnNonObjectThis(undefined); 20.133 +checkProtoSetterOnNonObjectThis(null); 20.134 + 20.135 +function checkProtoSetterReturnValue(obj, p) { 20.136 + if (typeof desc.set.call(obj, p) != "undefined") { 20.137 + fail("__proto__ setter does not return undefined: " + obj + " " + p); 20.138 + } 20.139 +} 20.140 + 20.141 +// try non-object 'this'. setter is expected to return undefined. 20.142 +checkProtoSetterReturnValue(23); 20.143 +checkProtoSetterReturnValue(false); 20.144 +checkProtoSetterReturnValue("foo"); 20.145 + 20.146 +// set proper __proto__. Still return value is undefined. 20.147 +checkProtoSetterReturnValue({}, {}); 20.148 +checkProtoSetterReturnValue({}, null);
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/script/basic/JDK-8044612.js Thu Jun 26 08:46:39 2014 -0700 21.3 @@ -0,0 +1,37 @@ 21.4 +/* 21.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +/** 21.28 + * JDK-8044612: StringIndexOutOfBoundException in NativeRegExp.appendReplacement 21.29 + * 21.30 + * @test 21.31 + * @run 21.32 + */ 21.33 + 21.34 +if ("hello".replace("h", "$") != "$ello") { 21.35 + fail("String.prototype.replace failed to handle '$' as replacement"); 21.36 +} 21.37 + 21.38 +if ("hello".replace("o", "$x") != "hell$x") { 21.39 + fail("String.prototype.replace failed to handle '$x' as replacement"); 21.40 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/script/basic/JDK-8044695.js Thu Jun 26 08:46:39 2014 -0700 22.3 @@ -0,0 +1,37 @@ 22.4 +/* 22.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +/** 22.28 + * JDK-8044695: __stack__ becomes visible in Error properties 22.29 + * 22.30 + * @test 22.31 + * @run 22.32 + */ 22.33 + 22.34 +var e = new Error(); 22.35 +// access stack to force __stack__ 22.36 +e.stack; 22.37 +var jsonStr = JSON.stringify(e); 22.38 +if (jsonStr != "{}") { 22.39 + fail("JSON string is not {}, it is " + jsonStr); 22.40 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/script/basic/JDK-8044750.js Thu Jun 26 08:46:39 2014 -0700 23.3 @@ -0,0 +1,53 @@ 23.4 +/* 23.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 + * 23.8 + * This code is free software; you can redistribute it and/or modify it 23.9 + * under the terms of the GNU General Public License version 2 only, as 23.10 + * published by the Free Software Foundation. 23.11 + * 23.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 23.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.15 + * version 2 for more details (a copy is included in the LICENSE file that 23.16 + * accompanied this code). 23.17 + * 23.18 + * You should have received a copy of the GNU General Public License version 23.19 + * 2 along with this work; if not, write to the Free Software Foundation, 23.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.21 + * 23.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.23 + * or visit www.oracle.com if you need additional information or have any 23.24 + * questions. 23.25 + */ 23.26 + 23.27 +/** 23.28 + * JDK-8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook 23.29 + * 23.30 + * @test 23.31 + * @run 23.32 + */ 23.33 + 23.34 +__noSuchProperty__ = function(name) { 23.35 + return 1; 23.36 +} 23.37 + 23.38 +function func(obj) { 23.39 + with(obj) { 23.40 + // this "foo" getter site becomes megamorphic 23.41 + // due to different 'with' scope objects. 23.42 + foo; 23.43 + } 23.44 +} 23.45 + 23.46 +for (var i = 0; i < 20; i++) { 23.47 + var obj = {}; 23.48 + obj.foo = i; 23.49 + obj[i] = i; 23.50 + func(obj); 23.51 +} 23.52 + 23.53 +// pass a 'with' scope object that does not have 'foo'. 23.54 +// callsite inside func should see __noSuchProperty__ 23.55 +// hook on global scope object. 23.56 +func({});
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/script/nosecurity/JDK-8044798.js Thu Jun 26 08:46:39 2014 -0700 24.3 @@ -0,0 +1,159 @@ 24.4 +/* 24.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.7 + * 24.8 + * This code is free software; you can redistribute it and/or modify it 24.9 + * under the terms of the GNU General Public License version 2 only, as 24.10 + * published by the Free Software Foundation. 24.11 + * 24.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 24.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.15 + * version 2 for more details (a copy is included in the LICENSE file that 24.16 + * accompanied this code). 24.17 + * 24.18 + * You should have received a copy of the GNU General Public License version 24.19 + * 2 along with this work; if not, write to the Free Software Foundation, 24.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.21 + * 24.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.23 + * or visit www.oracle.com if you need additional information or have any 24.24 + * questions. 24.25 + */ 24.26 + 24.27 +/** 24.28 + * JDK-8044798: API for debugging Nashorn 24.29 + * 24.30 + * @test 24.31 + * @run 24.32 + */ 24.33 + 24.34 +// basic API exercise checks 24.35 + 24.36 +var Arrays = Java.type("java.util.Arrays"); 24.37 +var CharArray = Java.type("char[]"); 24.38 +var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport"); 24.39 +var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc"); 24.40 + 24.41 +var valueDescFields = DebuggerValueDesc.class.declaredFields; 24.42 +Arrays.sort(valueDescFields, function(f1, f2) f1.name.compareTo(f2.name)); 24.43 +var keyField; 24.44 +for each (var f in valueDescFields) { 24.45 + if (f.name == "key") { 24.46 + keyField = f; 24.47 + } 24.48 + f.accessible = true; 24.49 +} 24.50 + 24.51 +var debuggerSupportMethods = DebuggerSupport.class.declaredMethods; 24.52 + 24.53 +// methods of DebuggerSupport that we use 24.54 +var evalMethod, valueInfoMethod, valueInfosMethod; 24.55 +var getSourceInfoMethod, valueAsStringMethod; 24.56 + 24.57 +for each (var m in debuggerSupportMethods) { 24.58 + m.accessible = true; 24.59 + switch (m.name) { 24.60 + case "eval": 24.61 + evalMethod = m; 24.62 + break; 24.63 + case "valueInfo": 24.64 + if (m.parameterCount == 3) { 24.65 + valueInfoMethod = m; 24.66 + } 24.67 + break; 24.68 + case "valueInfos": 24.69 + valueInfosMethod = m; 24.70 + break; 24.71 + case "valueAsString": 24.72 + valueAsStringMethod = m; 24.73 + break; 24.74 + case "getSourceInfo": 24.75 + getSourceInfoMethod = m; 24.76 + break; 24.77 + } 24.78 +} 24.79 + 24.80 +// eval 24.81 +var value = evalMethod.invoke(null, null, null, "33 + 55", false); 24.82 +print(value); 24.83 + 24.84 +// valueInfo 24.85 +var info = valueInfoMethod.invoke(null, "apply", Function, true); 24.86 +for each (var f in valueDescFields) { 24.87 + print(f.name, "=", f.get(info)); 24.88 +} 24.89 + 24.90 +// valueInfo - user defined object 24.91 +var info = valueInfoMethod.invoke(null, "foo", { foo: 343 }, true); 24.92 +for each (var f in valueDescFields) { 24.93 + print(f.name, "=", f.get(info)); 24.94 +} 24.95 + 24.96 +// valueInfos 24.97 +var infos = valueInfosMethod.invoke(null, Object, true); 24.98 +Arrays.sort(infos, function (i1, i2) keyField.get(i1).compareTo(keyField.get(i2))); 24.99 + 24.100 +for each (var info in infos) { 24.101 + for each (var f in valueDescFields) { 24.102 + print(f.name, "=", f.get(info)); 24.103 + } 24.104 +} 24.105 + 24.106 +// valueInfos - user defined object 24.107 +var infos = valueInfosMethod.invoke(null, { foo: 34, bar: "hello" }, true); 24.108 +Arrays.sort(infos, function (i1, i2) keyField.get(i1).compareTo(keyField.get(i2))); 24.109 + 24.110 +for each (var info in infos) { 24.111 + for each (var f in valueDescFields) { 24.112 + print(f.name, "=", f.get(info)); 24.113 + } 24.114 +} 24.115 + 24.116 +// valueAsString 24.117 +function printValue(value) { 24.118 + print(valueAsStringMethod.invoke(null, value)); 24.119 +} 24.120 + 24.121 +printValue(undefined); 24.122 +printValue(null); 24.123 +printValue("hello"); 24.124 +printValue(Math.PI); 24.125 +printValue(this); 24.126 + 24.127 +// The below are not part of DebuggerSupport. But we need these to 24.128 +// test DebuggerSupport.getSourceInfo etc. which need compiled script class 24.129 + 24.130 +var Source = Java.type("jdk.nashorn.internal.runtime.Source"); 24.131 +var Context = Java.type("jdk.nashorn.internal.runtime.Context"); 24.132 +var sourceCls = Source.class; 24.133 +var errorMgrCls = Java.type("jdk.nashorn.internal.runtime.ErrorManager").class; 24.134 +var booleanCls = Java.type("java.lang.Boolean").TYPE; 24.135 + 24.136 +// private compile method of Context class 24.137 +var compileMethod = Context.class.getDeclaredMethod("compile", 24.138 + sourceCls, errorMgrCls, booleanCls); 24.139 +compileMethod.accessible = true; 24.140 + 24.141 +var scriptCls = compileMethod.invoke(Context.context, 24.142 + Source.sourceFor("test", "print('hello')"), 24.143 + new Context.ThrowErrorManager(), false); 24.144 + 24.145 +var SCRIPT_CLASS_NAME_PREFIX = "jdk.nashorn.internal.scripts.Script$"; 24.146 +print("script class name pattern satisfied? " + 24.147 + scriptCls.name.startsWith(SCRIPT_CLASS_NAME_PREFIX)); 24.148 + 24.149 +var srcInfo = getSourceInfoMethod.invoke(null, scriptCls); 24.150 +var srcInfoFields = srcInfo.class.declaredFields; 24.151 +Arrays.sort(srcInfoFields, function(f1, f2) f1.name.compareTo(f2.name)); 24.152 + 24.153 +print("Source info"); 24.154 +for each (var f in srcInfoFields) { 24.155 + f.accessible = true; 24.156 + var fieldValue = f.get(srcInfo); 24.157 + if (fieldValue instanceof CharArray) { 24.158 + fieldValue = new java.lang.String(fieldValue); 24.159 + } 24.160 + 24.161 + print(f.name, "=", fieldValue); 24.162 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/script/nosecurity/JDK-8044798.js.EXPECTED Thu Jun 26 08:46:39 2014 -0700 25.3 @@ -0,0 +1,104 @@ 25.4 +88 25.5 +expandable = false 25.6 +key = apply 25.7 +valueAsObject = function Function() { [native code] } 25.8 +valueAsString = function Function() { [native code] } 25.9 +expandable = true 25.10 +key = foo 25.11 +valueAsObject = [object Object] 25.12 +valueAsString = {foo: 343} 25.13 +expandable = false 25.14 +key = bindProperties 25.15 +valueAsObject = function bindProperties() { [native code] } 25.16 +valueAsString = function bindProperties() { [native code] } 25.17 +expandable = false 25.18 +key = create 25.19 +valueAsObject = function create() { [native code] } 25.20 +valueAsString = function create() { [native code] } 25.21 +expandable = false 25.22 +key = defineProperties 25.23 +valueAsObject = function defineProperties() { [native code] } 25.24 +valueAsString = function defineProperties() { [native code] } 25.25 +expandable = false 25.26 +key = defineProperty 25.27 +valueAsObject = function defineProperty() { [native code] } 25.28 +valueAsString = function defineProperty() { [native code] } 25.29 +expandable = false 25.30 +key = freeze 25.31 +valueAsObject = function freeze() { [native code] } 25.32 +valueAsString = function freeze() { [native code] } 25.33 +expandable = false 25.34 +key = getOwnPropertyDescriptor 25.35 +valueAsObject = function getOwnPropertyDescriptor() { [native code] } 25.36 +valueAsString = function getOwnPropertyDescriptor() { [native code] } 25.37 +expandable = false 25.38 +key = getOwnPropertyNames 25.39 +valueAsObject = function getOwnPropertyNames() { [native code] } 25.40 +valueAsString = function getOwnPropertyNames() { [native code] } 25.41 +expandable = false 25.42 +key = getPrototypeOf 25.43 +valueAsObject = function getPrototypeOf() { [native code] } 25.44 +valueAsString = function getPrototypeOf() { [native code] } 25.45 +expandable = false 25.46 +key = isExtensible 25.47 +valueAsObject = function isExtensible() { [native code] } 25.48 +valueAsString = function isExtensible() { [native code] } 25.49 +expandable = false 25.50 +key = isFrozen 25.51 +valueAsObject = function isFrozen() { [native code] } 25.52 +valueAsString = function isFrozen() { [native code] } 25.53 +expandable = false 25.54 +key = isSealed 25.55 +valueAsObject = function isSealed() { [native code] } 25.56 +valueAsString = function isSealed() { [native code] } 25.57 +expandable = false 25.58 +key = keys 25.59 +valueAsObject = function keys() { [native code] } 25.60 +valueAsString = function keys() { [native code] } 25.61 +expandable = false 25.62 +key = length 25.63 +valueAsObject = 1 25.64 +valueAsString = 1 25.65 +expandable = false 25.66 +key = name 25.67 +valueAsObject = Object 25.68 +valueAsString = "Object" 25.69 +expandable = false 25.70 +key = preventExtensions 25.71 +valueAsObject = function preventExtensions() { [native code] } 25.72 +valueAsString = function preventExtensions() { [native code] } 25.73 +expandable = false 25.74 +key = prototype 25.75 +valueAsObject = [object Object] 25.76 +valueAsString = {toString: function toString() { [native code] }, toLocaleString: function toLocaleString() { [native code] }, valueOf: function valueOf() { [native code] }, hasOwnProperty: function hasOwnProperty() { [native code] }, isPrototypeOf: function isPrototypeOf() { [native code] }, propertyIsEnumerable: function propertyIsEnumerable() { [native code] }, constructor: function Object() { [native code] }, __proto__: null} 25.77 +expandable = false 25.78 +key = seal 25.79 +valueAsObject = function seal() { [native code] } 25.80 +valueAsString = function seal() { [native code] } 25.81 +expandable = false 25.82 +key = setIndexedPropertiesToExternalArrayData 25.83 +valueAsObject = function setIndexedPropertiesToExternalArrayData() { [native code] } 25.84 +valueAsString = function setIndexedPropertiesToExternalArrayData() { [native code] } 25.85 +expandable = false 25.86 +key = setPrototypeOf 25.87 +valueAsObject = function setPrototypeOf() { [native code] } 25.88 +valueAsString = function setPrototypeOf() { [native code] } 25.89 +expandable = false 25.90 +key = bar 25.91 +valueAsObject = hello 25.92 +valueAsString = "hello" 25.93 +expandable = false 25.94 +key = foo 25.95 +valueAsObject = 34 25.96 +valueAsString = 34 25.97 +undefined 25.98 +null 25.99 +"hello" 25.100 +3.141592653589793 25.101 +[object global] 25.102 +script class name pattern satisfied? true 25.103 +Source info 25.104 +content = print('hello') 25.105 +hash = 1655359881 25.106 +name = test 25.107 +url = null
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/script/nosecurity/debuggersupportapi.js Thu Jun 26 08:46:39 2014 -0700 26.3 @@ -0,0 +1,94 @@ 26.4 +/* 26.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 + * or visit www.oracle.com if you need additional information or have any 26.24 + * questions. 26.25 + */ 26.26 + 26.27 +/** 26.28 + * JDK-8044798: API for debugging Nashorn 26.29 + * 26.30 + * @test 26.31 + * @run 26.32 + */ 26.33 + 26.34 +// Basic API class, method, field existence checks. 26.35 + 26.36 +// The following classes and the associated methods and fields are used as 26.37 +// private debugger interface. Though private/implementation defined, nashorn 26.38 +// code should not be changed to remove these classes, fields and methods. 26.39 +// The test takes signatures of debugger interface and stores in .EXPECTED file. 26.40 +// If any incompatible change is made to nashorn to break any of these, this 26.41 +// test will fail. 26.42 + 26.43 +var Arrays = Java.type("java.util.Arrays"); 26.44 +var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport"); 26.45 + 26.46 +print(DebuggerSupport.class); 26.47 +print(); 26.48 +var methods = DebuggerSupport.class.declaredMethods; 26.49 +Arrays.sort(methods, function(m1, m2) m1.name.compareTo(m2.name)); 26.50 +for each (var mth in methods) { 26.51 + switch (mth.name) { 26.52 + case "eval": 26.53 + case "notifyInvoke": 26.54 + case "getSourceInfo": 26.55 + case "valueAsString": 26.56 + case "valueInfos": 26.57 + print(mth); 26.58 + break; 26.59 + case "valueInfo": 26.60 + if (mth.parameterCount == 3) { 26.61 + print(mth); 26.62 + } 26.63 + break; 26.64 + } 26.65 +} 26.66 +print(); 26.67 + 26.68 +var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc"); 26.69 +print(DebuggerValueDesc.class); 26.70 +print(); 26.71 +var fields = DebuggerValueDesc.class.declaredFields; 26.72 +Arrays.sort(fields, function(f1, f2) f1.name.compareTo(f2.name)); 26.73 +for each (var fld in fields) { 26.74 + switch (fld.name) { 26.75 + case "key": 26.76 + case "expandable": 26.77 + case "valueAsObject": 26.78 + case "valueAsString": 26.79 + print(fld); 26.80 + } 26.81 +} 26.82 +print(); 26.83 + 26.84 +var SourceInfo = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.SourceInfo"); 26.85 +print(SourceInfo.class); 26.86 +print(); 26.87 +var fields = SourceInfo.class.declaredFields; 26.88 +Arrays.sort(fields, function(f1, f2) f1.name.compareTo(f2.name)); 26.89 +for each (var fld in fields) { 26.90 + switch (fld.name) { 26.91 + case "name": 26.92 + case "hash": 26.93 + case "url": 26.94 + case "content": 26.95 + print(fld); 26.96 + } 26.97 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/script/nosecurity/debuggersupportapi.js.EXPECTED Thu Jun 26 08:46:39 2014 -0700 27.3 @@ -0,0 +1,22 @@ 27.4 +class jdk.nashorn.internal.runtime.DebuggerSupport 27.5 + 27.6 +static java.lang.Object jdk.nashorn.internal.runtime.DebuggerSupport.eval(jdk.nashorn.internal.runtime.ScriptObject,java.lang.Object,java.lang.String,boolean) 27.7 +static jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo jdk.nashorn.internal.runtime.DebuggerSupport.getSourceInfo(java.lang.Class) 27.8 +static void jdk.nashorn.internal.runtime.DebuggerSupport.notifyInvoke(java.lang.invoke.MethodHandle) 27.9 +static java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport.valueAsString(java.lang.Object) 27.10 +static jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc jdk.nashorn.internal.runtime.DebuggerSupport.valueInfo(java.lang.String,java.lang.Object,boolean) 27.11 +static jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc[] jdk.nashorn.internal.runtime.DebuggerSupport.valueInfos(java.lang.Object,boolean) 27.12 + 27.13 +class jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc 27.14 + 27.15 +final boolean jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.expandable 27.16 +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.key 27.17 +final java.lang.Object jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.valueAsObject 27.18 +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.valueAsString 27.19 + 27.20 +class jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo 27.21 + 27.22 +final char[] jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.content 27.23 +final int jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.hash 27.24 +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.name 27.25 +final java.net.URL jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.url
28.1 --- a/test/src/jdk/nashorn/api/scripting/ScopeTest.java Wed Jun 18 13:32:19 2014 -0700 28.2 +++ b/test/src/jdk/nashorn/api/scripting/ScopeTest.java Thu Jun 26 08:46:39 2014 -0700 28.3 @@ -510,6 +510,23 @@ 28.4 assertEquals(e.eval("x", newCtxt), 2); 28.5 } 28.6 28.7 + // @bug 8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook 28.8 + @Test 28.9 + public static void testMegamorphicGetInGlobal() throws Exception { 28.10 + final ScriptEngineManager m = new ScriptEngineManager(); 28.11 + final ScriptEngine engine = m.getEngineByName("nashorn"); 28.12 + final String script = "foo"; 28.13 + // "foo" is megamorphic because of different global scopes. 28.14 + // Make sure ScriptContext variable search works even after 28.15 + // it becomes megamorphic. 28.16 + for (int index = 0; index < 25; index++) { 28.17 + final Bindings bindings = new SimpleBindings(); 28.18 + bindings.put("foo", index); 28.19 + final Number value = (Number)engine.eval(script, bindings); 28.20 + assertEquals(index, value.intValue()); 28.21 + } 28.22 + } 28.23 + 28.24 /** 28.25 * Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals. 28.26 */