Thu, 28 May 2015 16:48:12 -0700
Merge
src/jdk/nashorn/internal/runtime/JSObjectListAdapter.java | file | annotate | diff | comparison | revisions |
1.1 --- a/make/build.xml Wed May 27 13:20:58 2015 -0700 1.2 +++ b/make/build.xml Thu May 28 16:48:12 2015 -0700 1.3 @@ -210,7 +210,7 @@ 1.4 </target> 1.5 1.6 <target name="javadoc" depends="jar"> 1.7 - <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" 1.8 + <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${src.dir}/overview.html" 1.9 extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}" 1.10 additionalparam="-quiet" failonerror="true"> 1.11 <classpath> 1.12 @@ -460,7 +460,7 @@ 1.13 </testng> 1.14 </target> 1.15 1.16 - <target name="test" depends="test-pessimistic, test-optimistic"/> 1.17 + <target name="test" depends="javadoc, test-pessimistic, test-optimistic"/> 1.18 1.19 <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"> 1.20 <echo message="Running test suite in OPTIMISTIC mode..."/>
2.1 --- a/samples/browser_dom.js Wed May 27 13:20:58 2015 -0700 2.2 +++ b/samples/browser_dom.js Thu May 28 16:48:12 2015 -0700 2.3 @@ -40,7 +40,6 @@ 2.4 var ChangeListener = Java.type("javafx.beans.value.ChangeListener"); 2.5 var Scene = Java.type("javafx.scene.Scene"); 2.6 var WebView = Java.type("javafx.scene.web.WebView"); 2.7 -var EventListener = Java.type("org.w3c.dom.events.EventListener"); 2.8 2.9 // JavaFX start method 2.10 function start(stage) {
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/samples/console.js Thu May 28 16:48:12 2015 -0700 3.3 @@ -0,0 +1,134 @@ 3.4 +/* 3.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3.6 + * 3.7 + * Redistribution and use in source and binary forms, with or without 3.8 + * modification, are permitted provided that the following conditions 3.9 + * are met: 3.10 + * 3.11 + * - Redistributions of source code must retain the above copyright 3.12 + * notice, this list of conditions and the following disclaimer. 3.13 + * 3.14 + * - Redistributions in binary form must reproduce the above copyright 3.15 + * notice, this list of conditions and the following disclaimer in the 3.16 + * documentation and/or other materials provided with the distribution. 3.17 + * 3.18 + * - Neither the name of Oracle nor the names of its 3.19 + * contributors may be used to endorse or promote products derived 3.20 + * from this software without specific prior written permission. 3.21 + * 3.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 3.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 3.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 3.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 3.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 3.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 3.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 3.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 3.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3.33 + */ 3.34 + 3.35 +/** 3.36 + * Simple Web Console-like support for Nashorn. In addition to 3.37 + * Web console object methods, this console add methods of 3.38 + * java.io.Console as well. Note:not all web console methods are 3.39 + * implemented but useful subset is implemented. 3.40 + * 3.41 + * See also: https://developer.mozilla.org/en/docs/Web/API/console 3.42 + */ 3.43 + 3.44 + 3.45 +if (typeof console == 'undefined') { 3.46 + 3.47 +(function() { 3.48 + var LocalDateTime = Java.type("java.time.LocalDateTime"); 3.49 + var System = Java.type("java.lang.System"); 3.50 + var jconsole = System.console(); 3.51 + 3.52 + // add a new global variable called "console" 3.53 + this.console = { 3.54 + }; 3.55 + 3.56 + function addConsoleMethods() { 3.57 + // expose methods of java.io.Console as an extension 3.58 + var placeholder = "-*-"; 3.59 + // put a placeholder for each name from java.lang.Object 3.60 + var objMethods = Object.bindProperties({}, new java.lang.Object()); 3.61 + for (var m in objMethods) { 3.62 + console[m] = placeholder; 3.63 + } 3.64 + 3.65 + // bind only the methods of java.io.Console 3.66 + // This bind will skip java.lang.Object methods as console 3.67 + // has properties of same name. 3.68 + Object.bindProperties(console, jconsole); 3.69 + 3.70 + // Now, delete java.lang.Object methods 3.71 + for (var m in console) { 3.72 + if (console[m] == placeholder) { 3.73 + delete console[m]; 3.74 + } 3.75 + } 3.76 + } 3.77 + 3.78 + addConsoleMethods(); 3.79 + 3.80 + function consoleLog(type, msg) { 3.81 + // print type of message, then time. 3.82 + jconsole.format("%s [%s] ", type, LocalDateTime.now().toString()); 3.83 + if (typeof msg == 'string') { 3.84 + jconsole.format(msg + "\n", Array.prototype.slice.call(arguments, 2)); 3.85 + } else { 3.86 + // simple space separated values and newline at the end 3.87 + var arr = Array.prototype.slice.call(arguments, 1); 3.88 + jconsole.format("%s\n", arr.join(" ")); 3.89 + } 3.90 + } 3.91 + 3.92 + console.toString = function() "[object Console]"; 3.93 + 3.94 + // web console functions 3.95 + 3.96 + console.assert = function(expr) { 3.97 + if (! expr) { 3.98 + arguments[0] = "Assertion Failed:"; 3.99 + consoleLog.apply(console, arguments); 3.100 + // now, stack trace at the end 3.101 + jconsole.format("%s\n", new Error().stack); 3.102 + } 3.103 + }; 3.104 + 3.105 + // dummy clear to avoid error! 3.106 + console.clear = function() {}; 3.107 + 3.108 + var counter = { 3.109 + get: function(label) { 3.110 + if (! this[label]) { 3.111 + return this[label] = 1; 3.112 + } else { 3.113 + return ++this[label]; 3.114 + } 3.115 + } 3.116 + }; 3.117 + 3.118 + // counter 3.119 + console.count = function(label) { 3.120 + label = label? String(label) : "<no label>"; 3.121 + jconsole.format("%s: %d\n",label, counter.get(label).intValue()); 3.122 + } 3.123 + 3.124 + // logging 3.125 + console.error = consoleLog.bind(jconsole, "ERROR"); 3.126 + console.info = consoleLog.bind(jconsole, "INFO"); 3.127 + console.log = console.info; 3.128 + console.debug = console.log; 3.129 + console.warn = consoleLog.bind(jconsole, "WARNING"); 3.130 + 3.131 + // print stack trace 3.132 + console.trace = function() { 3.133 + jconsole.format("%s\n", new Error().stack); 3.134 + }; 3.135 +})(); 3.136 + 3.137 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/samples/consoleuse.js Thu May 28 16:48:12 2015 -0700 4.3 @@ -0,0 +1,55 @@ 4.4 +/* 4.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4.6 + * 4.7 + * Redistribution and use in source and binary forms, with or without 4.8 + * modification, are permitted provided that the following conditions 4.9 + * are met: 4.10 + * 4.11 + * - Redistributions of source code must retain the above copyright 4.12 + * notice, this list of conditions and the following disclaimer. 4.13 + * 4.14 + * - Redistributions in binary form must reproduce the above copyright 4.15 + * notice, this list of conditions and the following disclaimer in the 4.16 + * documentation and/or other materials provided with the distribution. 4.17 + * 4.18 + * - Neither the name of Oracle nor the names of its 4.19 + * contributors may be used to endorse or promote products derived 4.20 + * from this software without specific prior written permission. 4.21 + * 4.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 4.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 4.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 4.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 4.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 4.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 4.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 4.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 4.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 4.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4.33 + */ 4.34 + 4.35 +load(__DIR__ + "console.js"); 4.36 + 4.37 +console.log("consoleuse.js started!"); 4.38 + 4.39 +function func() { 4.40 + console.count("func"); 4.41 +} 4.42 + 4.43 + 4.44 +func(); 4.45 +func(); 4.46 +func(); 4.47 +func(); 4.48 + 4.49 +// java.io.Console method 4.50 +console.readPassword("passworld please: "); 4.51 +console.error("Big error: %s!", "you revealed your password!"); 4.52 +console.warn("You've done this %d times", 345); 4.53 +console.assert(arguments.length != 0, "no arguments!"); 4.54 + 4.55 +// java.io.Console methods 4.56 +var str = console.readLine("enter something: "); 4.57 +console.printf("you entered: %s\n", str); 4.58 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/samples/time_color.fx Thu May 28 16:48:12 2015 -0700 5.3 @@ -0,0 +1,89 @@ 5.4 +#// Usage: jjs -fx time_color.js [-- true/false] 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 +// A simple javafx program that changes background color 5.38 +// of scene based on current time value (once per sec). 5.39 +// inspired by http://whatcolourisit.scn9a.org/ 5.40 + 5.41 +if (!$OPTIONS._fx) { 5.42 + print("Usage: jjs -fx time_color.js"); 5.43 + print(" jjs -fx time_color.js -- true"); 5.44 + exit(1); 5.45 +} 5.46 + 5.47 +// JavaFX classes used 5.48 +var Color = Java.type("javafx.scene.paint.Color"); 5.49 +var Group = Java.type("javafx.scene.Group"); 5.50 +var Label = Java.type("javafx.scene.control.Label"); 5.51 +var Platform = Java.type("javafx.application.Platform"); 5.52 +var Scene = Java.type("javafx.scene.Scene"); 5.53 +var Timer = Java.type("java.util.Timer"); 5.54 + 5.55 +// execute function periodically once per given time in millisec 5.56 +function setInterval(func, ms) { 5.57 + // New timer, run as daemon so the application can quit 5.58 + var timer = new Timer("setInterval", true); 5.59 + timer.schedule(function() Platform.runLater(func), ms, ms); 5.60 + return timer; 5.61 +} 5.62 + 5.63 +// do you want to flip hour/min/sec for RGB? 5.64 +var flip = arguments.length > 0? "true".equals(arguments[0]) : false; 5.65 + 5.66 +// JavaFX start method 5.67 +function start(stage) { 5.68 + start.title = "Time Color"; 5.69 + var root = new Group(); 5.70 + var label = new Label("time"); 5.71 + label.textFill = Color.WHITE; 5.72 + root.children.add(label); 5.73 + stage.scene = new Scene(root, 700, 500); 5.74 + 5.75 + setInterval(function() { 5.76 + var d = new Date(); 5.77 + var hours = d.getHours(); 5.78 + var mins = d.getMinutes(); 5.79 + var secs = d.getSeconds(); 5.80 + 5.81 + if (hours < 10) hours = "0" + hours; 5.82 + if (mins < 10) mins = "0" + mins; 5.83 + if (secs < 10) secs = "0" + secs; 5.84 + 5.85 + var hex = flip? 5.86 + "#" + secs + mins + hours : "#" + hours + mins + secs; 5.87 + label.text = "Color: " + hex; 5.88 + stage.scene.fill = Color.web(hex); 5.89 + }, 1000); 5.90 + 5.91 + stage.show(); 5.92 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/samples/undefined_call.js Thu May 28 16:48:12 2015 -0700 6.3 @@ -0,0 +1,48 @@ 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 +// Nashorn extension: __noSuchMethod__ 6.36 +// See also: https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-__noSuchMethod__ 6.37 + 6.38 +Object.prototype.__noSuchMethod__ = function(name) { 6.39 + print(name + " function is not defined in " + this); 6.40 + 6.41 + // Nashorn extension: stack property 6.42 + // gives stack trace as a string 6.43 + print(new Error().stack); 6.44 +} 6.45 + 6.46 +function func(obj) { 6.47 + obj.foo(); 6.48 +} 6.49 + 6.50 +func({}); 6.51 +func(this);
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/samples/unzip.js Thu May 28 16:48:12 2015 -0700 7.3 @@ -0,0 +1,79 @@ 7.4 +/* 7.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 7.6 + * 7.7 + * Redistribution and use in source and binary forms, with or without 7.8 + * modification, are permitted provided that the following conditions 7.9 + * are met: 7.10 + * 7.11 + * - Redistributions of source code must retain the above copyright 7.12 + * notice, this list of conditions and the following disclaimer. 7.13 + * 7.14 + * - Redistributions in binary form must reproduce the above copyright 7.15 + * notice, this list of conditions and the following disclaimer in the 7.16 + * documentation and/or other materials provided with the distribution. 7.17 + * 7.18 + * - Neither the name of Oracle nor the names of its 7.19 + * contributors may be used to endorse or promote products derived 7.20 + * from this software without specific prior written permission. 7.21 + * 7.22 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 7.23 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 7.24 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 7.25 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 7.26 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 7.27 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 7.28 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 7.29 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 7.30 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 7.31 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 7.32 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 7.33 + */ 7.34 + 7.35 +/* 7.36 + * Simple unzip tool using #nashorn and #java 7.37 + * zip fs file system interface. 7.38 + */ 7.39 + 7.40 +if (arguments.length == 0) { 7.41 + print("Usage: jjs zipfs.js -- <.zip/.jar file> [out dir]"); 7.42 + exit(1); 7.43 +} 7.44 + 7.45 +var File = Java.type("java.io.File"); 7.46 +// output directory where zip is extracted 7.47 +var outDir = arguments[1]; 7.48 +if (!outDir) { 7.49 + outDir = "."; 7.50 +} else { 7.51 + if (! new File(outDir).isDirectory()) { 7.52 + print(outDir + " directory does not exist!"); 7.53 + exit(1); 7.54 + } 7.55 +} 7.56 + 7.57 +var Files = Java.type("java.nio.file.Files"); 7.58 +var FileSystems = Java.type("java.nio.file.FileSystems"); 7.59 +var Paths = Java.type("java.nio.file.Paths"); 7.60 + 7.61 +var zipfile = Paths.get(arguments[0]) 7.62 +var fs = FileSystems.newFileSystem(zipfile, null); 7.63 +var root = fs.rootDirectories[0]; 7.64 + 7.65 +// walk root and handle each Path 7.66 +Files.walk(root).forEach( 7.67 + function(p) { 7.68 + var outPath = outDir + 7.69 + p.toString().replace('/', File.separatorChar); 7.70 + print(outPath); 7.71 + if (Files.isDirectory(p)) { 7.72 + // create directories as needed 7.73 + new File(outPath).mkdirs(); 7.74 + } else { 7.75 + // copy a 'file' resource 7.76 + Files.copy(p, new File(outPath).toPath()); 7.77 + } 7.78 + } 7.79 +); 7.80 + 7.81 +// done 7.82 +fs.close();
8.1 --- a/src/jdk/nashorn/internal/codegen/AssignSymbols.java Wed May 27 13:20:58 2015 -0700 8.2 +++ b/src/jdk/nashorn/internal/codegen/AssignSymbols.java Thu May 28 16:48:12 2015 -0700 8.3 @@ -84,6 +84,7 @@ 8.4 import jdk.nashorn.internal.ir.VarNode; 8.5 import jdk.nashorn.internal.ir.WithNode; 8.6 import jdk.nashorn.internal.ir.visitor.NodeVisitor; 8.7 +import jdk.nashorn.internal.parser.TokenType; 8.8 import jdk.nashorn.internal.runtime.Context; 8.9 import jdk.nashorn.internal.runtime.ECMAErrors; 8.10 import jdk.nashorn.internal.runtime.ErrorManager; 8.11 @@ -714,12 +715,10 @@ 8.12 8.13 @Override 8.14 public Node leaveBinaryNode(final BinaryNode binaryNode) { 8.15 - switch (binaryNode.tokenType()) { 8.16 - case ASSIGN: 8.17 + if (binaryNode.isTokenType(TokenType.ASSIGN)) { 8.18 return leaveASSIGN(binaryNode); 8.19 - default: 8.20 - return super.leaveBinaryNode(binaryNode); 8.21 } 8.22 + return super.leaveBinaryNode(binaryNode); 8.23 } 8.24 8.25 private Node leaveASSIGN(final BinaryNode binaryNode) {
9.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed May 27 13:20:58 2015 -0700 9.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Thu May 28 16:48:12 2015 -0700 9.3 @@ -3798,7 +3798,6 @@ 9.4 emitBranch(binaryNode, onTrue, true); 9.5 if (isCurrentDiscard) { 9.6 method.label(onTrue); 9.7 - method.pop(); 9.8 } else { 9.9 method.load(false); 9.10 method._goto(skip);
10.1 --- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Wed May 27 13:20:58 2015 -0700 10.2 +++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Thu May 28 16:48:12 2015 -0700 10.3 @@ -459,7 +459,7 @@ 10.4 // NOTE: regardless of operator's lexical associativity, lhs is always evaluated first. 10.5 final Expression lhs = binaryNode.lhs(); 10.6 final LvarType lhsType; 10.7 - if (!(lhs instanceof IdentNode && binaryNode.tokenType() == TokenType.ASSIGN)) { 10.8 + if (!(lhs instanceof IdentNode && binaryNode.isTokenType(TokenType.ASSIGN))) { 10.9 lhsType = visitExpression(lhs); 10.10 } else { 10.11 // Can't visit IdentNode on LHS of a simple assignment, as visits imply use, and this is def.
11.1 --- a/src/jdk/nashorn/internal/codegen/Lower.java Wed May 27 13:20:58 2015 -0700 11.2 +++ b/src/jdk/nashorn/internal/codegen/Lower.java Thu May 28 16:48:12 2015 -0700 11.3 @@ -200,7 +200,7 @@ 11.4 final String name = getConstantPropertyName(indexNode.getIndex()); 11.5 if (name != null) { 11.6 // If index node is a constant property name convert index node to access node. 11.7 - assert Token.descType(indexNode.getToken()) == TokenType.LBRACKET; 11.8 + assert indexNode.isIndex(); 11.9 return new AccessNode(indexNode.getToken(), indexNode.getFinish(), indexNode.getBase(), name); 11.10 } 11.11 return super.leaveIndexNode(indexNode);
12.1 --- a/src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java Wed May 27 13:20:58 2015 -0700 12.2 +++ b/src/jdk/nashorn/internal/codegen/OptimisticTypesPersistence.java Thu May 28 16:48:12 2015 -0700 12.3 @@ -61,7 +61,7 @@ 12.4 import jdk.nashorn.internal.runtime.options.Options; 12.5 12.6 /** 12.7 - * Static utility that encapsulates persistence of type information for functions compiled with optimistic 12.8 + * <p>Static utility that encapsulates persistence of type information for functions compiled with optimistic 12.9 * typing. With this feature enabled, when a JavaScript function is recompiled because it gets deoptimized, 12.10 * the type information for deoptimization is stored in a cache file. If the same function is compiled in a 12.11 * subsequent JVM invocation, the type information is used for initial compilation, thus allowing the system 12.12 @@ -77,6 +77,7 @@ 12.13 * {@code nashorn.typeInfo.cleanupDelaySeconds} system property. You can also specify the word 12.14 * {@code unlimited} as the value for {@code nashorn.typeInfo.maxFiles} in which case the type info cache is 12.15 * allowed to grow without limits. 12.16 + * </p> 12.17 */ 12.18 public final class OptimisticTypesPersistence { 12.19 // Default is 0, for disabling the feature when not specified. A reasonable default when enabled is
13.1 --- a/src/jdk/nashorn/internal/ir/AccessNode.java Wed May 27 13:20:58 2015 -0700 13.2 +++ b/src/jdk/nashorn/internal/ir/AccessNode.java Thu May 28 16:48:12 2015 -0700 13.3 @@ -28,8 +28,6 @@ 13.4 import jdk.nashorn.internal.codegen.types.Type; 13.5 import jdk.nashorn.internal.ir.annotations.Immutable; 13.6 import jdk.nashorn.internal.ir.visitor.NodeVisitor; 13.7 -import jdk.nashorn.internal.parser.Token; 13.8 -import jdk.nashorn.internal.parser.TokenType; 13.9 13.10 /** 13.11 * IR representation of a property access (period operator.) 13.12 @@ -103,14 +101,6 @@ 13.13 return property; 13.14 } 13.15 13.16 - /** 13.17 - * Return true if this node represents an index operation normally represented as {@link IndexNode}. 13.18 - * @return true if an index access. 13.19 - */ 13.20 - public boolean isIndex() { 13.21 - return Token.descType(getToken()) == TokenType.LBRACKET; 13.22 - } 13.23 - 13.24 private AccessNode setBase(final Expression base) { 13.25 if (this.base == base) { 13.26 return this;
14.1 --- a/src/jdk/nashorn/internal/ir/BaseNode.java Wed May 27 13:20:58 2015 -0700 14.2 +++ b/src/jdk/nashorn/internal/ir/BaseNode.java Thu May 28 16:48:12 2015 -0700 14.3 @@ -29,6 +29,7 @@ 14.4 14.5 import jdk.nashorn.internal.codegen.types.Type; 14.6 import jdk.nashorn.internal.ir.annotations.Immutable; 14.7 +import jdk.nashorn.internal.parser.TokenType; 14.8 14.9 /** 14.10 * IR base for accessing/indexing nodes. 14.11 @@ -122,6 +123,14 @@ 14.12 } 14.13 14.14 /** 14.15 + * Return true if this node represents an index operation normally represented as {@link IndexNode}. 14.16 + * @return true if an index access. 14.17 + */ 14.18 + public boolean isIndex() { 14.19 + return isTokenType(TokenType.LBRACKET); 14.20 + } 14.21 + 14.22 + /** 14.23 * Mark this node as being the callee operand of a {@link CallNode}. 14.24 * @return a base node identical to this one in all aspects except with its function flag set. 14.25 */
15.1 --- a/src/jdk/nashorn/internal/ir/BinaryNode.java Wed May 27 13:20:58 2015 -0700 15.2 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Thu May 28 16:48:12 2015 -0700 15.3 @@ -312,7 +312,7 @@ 15.4 15.5 @Override 15.6 public boolean isSelfModifying() { 15.7 - return isAssignment() && tokenType() != TokenType.ASSIGN; 15.8 + return isAssignment() && !isTokenType(TokenType.ASSIGN); 15.9 } 15.10 15.11 @Override 15.12 @@ -529,7 +529,7 @@ 15.13 final TokenType tokenType = tokenType(); 15.14 if(tokenType == TokenType.ADD || tokenType == TokenType.ASSIGN_ADD) { 15.15 return OPTIMISTIC_UNDECIDED_TYPE; 15.16 - } else if (CAN_OVERFLOW.contains(tokenType())) { 15.17 + } else if (CAN_OVERFLOW.contains(tokenType)) { 15.18 return Type.INT; 15.19 } 15.20 return getMostPessimisticType();
16.1 --- a/src/jdk/nashorn/internal/ir/LexicalContext.java Wed May 27 13:20:58 2015 -0700 16.2 +++ b/src/jdk/nashorn/internal/ir/LexicalContext.java Thu May 28 16:48:12 2015 -0700 16.3 @@ -204,7 +204,7 @@ 16.4 /** 16.5 * Explicitly apply flags to the topmost element on the stack. This is only valid to use from a 16.6 * {@code NodeVisitor.leaveXxx()} method and only on the node being exited at the time. It is not mandatory to use, 16.7 - * as {@link #pop(LexicalContextNode)} will apply the flags automatically, but this method can be used to apply them 16.8 + * as {@link #pop(Node)} will apply the flags automatically, but this method can be used to apply them 16.9 * during the {@code leaveXxx()} method in case its logic depends on the value of the flags. 16.10 * @param node the node to apply the flags to. Must be the topmost node on the stack. 16.11 * @return the passed in node, or a modified node (if any flags were modified)
17.1 --- a/src/jdk/nashorn/internal/ir/Node.java Wed May 27 13:20:58 2015 -0700 17.2 +++ b/src/jdk/nashorn/internal/ir/Node.java Thu May 28 16:48:12 2015 -0700 17.3 @@ -220,26 +220,28 @@ 17.4 } 17.5 17.6 /** 17.7 - * Return token tokenType from a token descriptor. 17.8 + * Returns this node's token's type. If you want to check for the node having a specific token type, 17.9 + * consider using {@link #isTokenType(TokenType)} instead. 17.10 * 17.11 - * @return Type of token. 17.12 + * @return type of token. 17.13 */ 17.14 public TokenType tokenType() { 17.15 return Token.descType(token); 17.16 } 17.17 17.18 /** 17.19 - * Test token tokenType. 17.20 + * Tests if this node has the specific token type. 17.21 * 17.22 - * @param type a type to check this token against 17.23 + * @param type a token type to check this node's token type against 17.24 * @return true if token types match. 17.25 */ 17.26 public boolean isTokenType(final TokenType type) { 17.27 - return Token.descType(token) == type; 17.28 + return tokenType() == type; 17.29 } 17.30 17.31 /** 17.32 - * Get the token for this location 17.33 + * Get the token for this node. If you want to retrieve the token's type, consider using 17.34 + * {@link #tokenType()} or {@link #isTokenType(TokenType)} instead. 17.35 * @return the token 17.36 */ 17.37 public long getToken() {
18.1 --- a/src/jdk/nashorn/internal/ir/TryNode.java Wed May 27 13:20:58 2015 -0700 18.2 +++ b/src/jdk/nashorn/internal/ir/TryNode.java Thu May 28 16:48:12 2015 -0700 18.3 @@ -57,7 +57,7 @@ 18.4 * block was not terminal; the original jump/return is simply ignored if the finally block itself 18.5 * terminates). The reason for this somewhat strange arrangement is that we didn't want to create a 18.6 * separate class for the (label, BlockStatement pair) but rather reused the already available LabelNode. 18.7 - * However, if we simply used List<LabelNode> without wrapping the label nodes in an additional Block, 18.8 + * However, if we simply used List<LabelNode> without wrapping the label nodes in an additional Block, 18.9 * that would've thrown off visitors relying on BlockLexicalContext -- same reason why we never use 18.10 * Statement as the type of bodies of e.g. IfNode, WhileNode etc. but rather blockify them even when they're 18.11 * single statements.
19.1 --- a/src/jdk/nashorn/internal/ir/VarNode.java Wed May 27 13:20:58 2015 -0700 19.2 +++ b/src/jdk/nashorn/internal/ir/VarNode.java Thu May 28 16:48:12 2015 -0700 19.3 @@ -27,7 +27,6 @@ 19.4 19.5 import jdk.nashorn.internal.ir.annotations.Immutable; 19.6 import jdk.nashorn.internal.ir.visitor.NodeVisitor; 19.7 -import jdk.nashorn.internal.parser.Token; 19.8 19.9 /** 19.10 * Node represents a var/let declaration. 19.11 @@ -182,7 +181,7 @@ 19.12 19.13 @Override 19.14 public void toString(final StringBuilder sb, final boolean printType) { 19.15 - sb.append(Token.descType(getToken()).getName()).append(' '); 19.16 + sb.append(tokenType().getName()).append(' '); 19.17 name.toString(sb, printType); 19.18 19.19 if (init != null) {
20.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed May 27 13:20:58 2015 -0700 20.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu May 28 16:48:12 2015 -0700 20.3 @@ -220,7 +220,12 @@ 20.4 @Property(name = "Number", attributes = Attribute.NOT_ENUMERABLE) 20.5 public volatile Object number; 20.6 20.7 - /** ECMA 15.1.4.7 Date constructor */ 20.8 + /** 20.9 + * Getter for ECMA 15.1.4.7 Date property 20.10 + * 20.11 + * @param self self reference 20.12 + * @return Date property value 20.13 + */ 20.14 @Getter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) 20.15 public static Object getDate(final Object self) { 20.16 final Global global = Global.instanceFrom(self); 20.17 @@ -230,6 +235,12 @@ 20.18 return global.date; 20.19 } 20.20 20.21 + /** 20.22 + * Setter for ECMA 15.1.4.7 Date property 20.23 + * 20.24 + * @param self self reference 20.25 + * @param value value for the Date property 20.26 + */ 20.27 @Setter(name = "Date", attributes = Attribute.NOT_ENUMERABLE) 20.28 public static void setDate(final Object self, final Object value) { 20.29 final Global global = Global.instanceFrom(self); 20.30 @@ -238,7 +249,12 @@ 20.31 20.32 private volatile Object date = LAZY_SENTINEL; 20.33 20.34 - /** ECMA 15.1.4.8 RegExp constructor */ 20.35 + /** 20.36 + * Getter for ECMA 15.1.4.8 RegExp property 20.37 + * 20.38 + * @param self self reference 20.39 + * @return RegExp property value 20.40 + */ 20.41 @Getter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) 20.42 public static Object getRegExp(final Object self) { 20.43 final Global global = Global.instanceFrom(self); 20.44 @@ -248,6 +264,12 @@ 20.45 return global.regexp; 20.46 } 20.47 20.48 + /** 20.49 + * Setter for ECMA 15.1.4.8 RegExp property 20.50 + * 20.51 + * @param self self reference 20.52 + * @param value value for the RegExp property 20.53 + */ 20.54 @Setter(name = "RegExp", attributes = Attribute.NOT_ENUMERABLE) 20.55 public static void setRegExp(final Object self, final Object value) { 20.56 final Global global = Global.instanceFrom(self); 20.57 @@ -256,7 +278,11 @@ 20.58 20.59 private volatile Object regexp = LAZY_SENTINEL; 20.60 20.61 - /** ECMA 15.12 - The JSON object */ 20.62 + /** 20.63 + * Getter for ECMA 15.12 - The JSON property 20.64 + * @param self self reference 20.65 + * @return the value of JSON property 20.66 + */ 20.67 @Getter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) 20.68 public static Object getJSON(final Object self) { 20.69 final Global global = Global.instanceFrom(self); 20.70 @@ -266,6 +292,11 @@ 20.71 return global.json; 20.72 } 20.73 20.74 + /** 20.75 + * Setter for ECMA 15.12 - The JSON property 20.76 + * @param self self reference 20.77 + * @param value value for the JSON property 20.78 + */ 20.79 @Setter(name = "JSON", attributes = Attribute.NOT_ENUMERABLE) 20.80 public static void setJSON(final Object self, final Object value) { 20.81 final Global global = Global.instanceFrom(self); 20.82 @@ -274,7 +305,11 @@ 20.83 20.84 private volatile Object json = LAZY_SENTINEL; 20.85 20.86 - /** Nashorn extension: global.JSAdapter */ 20.87 + /** 20.88 + * Getter for Nashorn extension: global.JSAdapter 20.89 + * @param self self reference 20.90 + * @return value of the JSAdapter property 20.91 + */ 20.92 @Getter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) 20.93 public static Object getJSAdapter(final Object self) { 20.94 final Global global = Global.instanceFrom(self); 20.95 @@ -284,6 +319,11 @@ 20.96 return global.jsadapter; 20.97 } 20.98 20.99 + /** 20.100 + * Setter for Nashorn extension: global.JSAdapter 20.101 + * @param self self reference 20.102 + * @param value value for the JSAdapter property 20.103 + */ 20.104 @Setter(name = "JSAdapter", attributes = Attribute.NOT_ENUMERABLE) 20.105 public static void setJSAdapter(final Object self, final Object value) { 20.106 final Global global = Global.instanceFrom(self); 20.107 @@ -300,7 +340,11 @@ 20.108 @Property(name = "Error", attributes = Attribute.NOT_ENUMERABLE) 20.109 public volatile Object error; 20.110 20.111 - /** EvalError object */ 20.112 + /** 20.113 + * Getter for the EvalError property 20.114 + * @param self self reference 20.115 + * @return the value of EvalError property 20.116 + */ 20.117 @Getter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) 20.118 public static Object getEvalError(final Object self) { 20.119 final Global global = Global.instanceFrom(self); 20.120 @@ -310,6 +354,11 @@ 20.121 return global.evalError; 20.122 } 20.123 20.124 + /** 20.125 + * Setter for the EvalError property 20.126 + * @param self self reference 20.127 + * @param value value of the EvalError property 20.128 + */ 20.129 @Setter(name = "EvalError", attributes = Attribute.NOT_ENUMERABLE) 20.130 public static void setEvalError(final Object self, final Object value) { 20.131 final Global global = Global.instanceFrom(self); 20.132 @@ -318,7 +367,11 @@ 20.133 20.134 private volatile Object evalError = LAZY_SENTINEL; 20.135 20.136 - /** RangeError object */ 20.137 + /** 20.138 + * Getter for the RangeError property. 20.139 + * @param self self reference 20.140 + * @return the value of RangeError property 20.141 + */ 20.142 @Getter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) 20.143 public static Object getRangeError(final Object self) { 20.144 final Global global = Global.instanceFrom(self); 20.145 @@ -328,6 +381,12 @@ 20.146 return global.rangeError; 20.147 } 20.148 20.149 + 20.150 + /** 20.151 + * Setter for the RangeError property. 20.152 + * @param self self reference 20.153 + * @param value value for the RangeError property 20.154 + */ 20.155 @Setter(name = "RangeError", attributes = Attribute.NOT_ENUMERABLE) 20.156 public static void setRangeError(final Object self, final Object value) { 20.157 final Global global = Global.instanceFrom(self); 20.158 @@ -348,7 +407,11 @@ 20.159 @Property(name = "TypeError", attributes = Attribute.NOT_ENUMERABLE) 20.160 public volatile Object typeError; 20.161 20.162 - /** URIError object */ 20.163 + /** 20.164 + * Getter for the URIError property. 20.165 + * @param self self reference 20.166 + * @return the value of URIError property 20.167 + */ 20.168 @Getter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) 20.169 public static Object getURIError(final Object self) { 20.170 final Global global = Global.instanceFrom(self); 20.171 @@ -358,6 +421,11 @@ 20.172 return global.uriError; 20.173 } 20.174 20.175 + /** 20.176 + * Setter for the URIError property. 20.177 + * @param self self reference 20.178 + * @param value value for the URIError property 20.179 + */ 20.180 @Setter(name = "URIError", attributes = Attribute.NOT_ENUMERABLE) 20.181 public static void setURIError(final Object self, final Object value) { 20.182 final Global global = Global.instanceFrom(self); 20.183 @@ -366,7 +434,11 @@ 20.184 20.185 private volatile Object uriError = LAZY_SENTINEL; 20.186 20.187 - /** ArrayBuffer object */ 20.188 + /** 20.189 + * Getter for the ArrayBuffer property. 20.190 + * @param self self reference 20.191 + * @return the value of the ArrayBuffer property 20.192 + */ 20.193 @Getter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 20.194 public static Object getArrayBuffer(final Object self) { 20.195 final Global global = Global.instanceFrom(self); 20.196 @@ -376,6 +448,11 @@ 20.197 return global.arrayBuffer; 20.198 } 20.199 20.200 + /** 20.201 + * Setter for the ArrayBuffer property. 20.202 + * @param self self reference 20.203 + * @param value value of the ArrayBuffer property 20.204 + */ 20.205 @Setter(name = "ArrayBuffer", attributes = Attribute.NOT_ENUMERABLE) 20.206 public static void setArrayBuffer(final Object self, final Object value) { 20.207 final Global global = Global.instanceFrom(self); 20.208 @@ -384,7 +461,11 @@ 20.209 20.210 private volatile Object arrayBuffer; 20.211 20.212 - /** DataView object */ 20.213 + /** 20.214 + * Getter for the DataView property. 20.215 + * @param self self reference 20.216 + * @return the value of the DataView property 20.217 + */ 20.218 @Getter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 20.219 public static Object getDataView(final Object self) { 20.220 final Global global = Global.instanceFrom(self); 20.221 @@ -394,6 +475,12 @@ 20.222 return global.dataView; 20.223 } 20.224 20.225 + 20.226 + /** 20.227 + * Setter for the DataView property. 20.228 + * @param self self reference 20.229 + * @param value value of the DataView property 20.230 + */ 20.231 @Setter(name = "DataView", attributes = Attribute.NOT_ENUMERABLE) 20.232 public static void setDataView(final Object self, final Object value) { 20.233 final Global global = Global.instanceFrom(self); 20.234 @@ -402,7 +489,11 @@ 20.235 20.236 private volatile Object dataView; 20.237 20.238 - /** TypedArray (int8) */ 20.239 + /** 20.240 + * Getter for the Int8Array property. 20.241 + * @param self self reference 20.242 + * @return the value of the Int8Array property. 20.243 + */ 20.244 @Getter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 20.245 public static Object getInt8Array(final Object self) { 20.246 final Global global = Global.instanceFrom(self); 20.247 @@ -412,6 +503,11 @@ 20.248 return global.int8Array; 20.249 } 20.250 20.251 + /** 20.252 + * Setter for the Int8Array property. 20.253 + * @param self self reference 20.254 + * @param value value of the Int8Array property 20.255 + */ 20.256 @Setter(name = "Int8Array", attributes = Attribute.NOT_ENUMERABLE) 20.257 public static void setInt8Array(final Object self, final Object value) { 20.258 final Global global = Global.instanceFrom(self); 20.259 @@ -420,7 +516,11 @@ 20.260 20.261 private volatile Object int8Array; 20.262 20.263 - /** TypedArray (uint8) */ 20.264 + /** 20.265 + * Getter for the Uin8Array property. 20.266 + * @param self self reference 20.267 + * @return the value of the Uint8Array property 20.268 + */ 20.269 @Getter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) 20.270 public static Object getUint8Array(final Object self) { 20.271 final Global global = Global.instanceFrom(self); 20.272 @@ -430,6 +530,11 @@ 20.273 return global.uint8Array; 20.274 } 20.275 20.276 + /** 20.277 + * Setter for the Uin8Array property. 20.278 + * @param self self reference 20.279 + * @param value value of the Uin8Array property 20.280 + */ 20.281 @Setter(name = "Uint8Array", attributes = Attribute.NOT_ENUMERABLE) 20.282 public static void setUint8Array(final Object self, final Object value) { 20.283 final Global global = Global.instanceFrom(self); 20.284 @@ -438,7 +543,11 @@ 20.285 20.286 private volatile Object uint8Array; 20.287 20.288 - /** TypedArray (uint8) - Clamped */ 20.289 + /** 20.290 + * Getter for the Uint8ClampedArray property. 20.291 + * @param self self reference 20.292 + * @return the value of the Uint8ClampedArray property 20.293 + */ 20.294 @Getter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) 20.295 public static Object getUint8ClampedArray(final Object self) { 20.296 final Global global = Global.instanceFrom(self); 20.297 @@ -448,6 +557,11 @@ 20.298 return global.uint8ClampedArray; 20.299 } 20.300 20.301 + /** 20.302 + * Setter for the Uint8ClampedArray property. 20.303 + * @param self self reference 20.304 + * @param value value of the Uint8ClampedArray property 20.305 + */ 20.306 @Setter(name = "Uint8ClampedArray", attributes = Attribute.NOT_ENUMERABLE) 20.307 public static void setUint8ClampedArray(final Object self, final Object value) { 20.308 final Global global = Global.instanceFrom(self); 20.309 @@ -456,7 +570,11 @@ 20.310 20.311 private volatile Object uint8ClampedArray; 20.312 20.313 - /** TypedArray (int16) */ 20.314 + /** 20.315 + * Getter for the Int16Array property. 20.316 + * @param self self reference 20.317 + * @return the value of the Int16Array property 20.318 + */ 20.319 @Getter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) 20.320 public static Object getInt16Array(final Object self) { 20.321 final Global global = Global.instanceFrom(self); 20.322 @@ -466,6 +584,11 @@ 20.323 return global.int16Array; 20.324 } 20.325 20.326 + /** 20.327 + * Setter for the Int16Array property. 20.328 + * @param self self reference 20.329 + * @param value value of the Int16Array property 20.330 + */ 20.331 @Setter(name = "Int16Array", attributes = Attribute.NOT_ENUMERABLE) 20.332 public static void setInt16Array(final Object self, final Object value) { 20.333 final Global global = Global.instanceFrom(self); 20.334 @@ -474,7 +597,11 @@ 20.335 20.336 private volatile Object int16Array; 20.337 20.338 - /** TypedArray (uint16) */ 20.339 + /** 20.340 + * Getter for the Uint16Array property. 20.341 + * @param self self reference 20.342 + * @return the value of the Uint16Array property 20.343 + */ 20.344 @Getter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) 20.345 public static Object getUint16Array(final Object self) { 20.346 final Global global = Global.instanceFrom(self); 20.347 @@ -484,6 +611,11 @@ 20.348 return global.uint16Array; 20.349 } 20.350 20.351 + /** 20.352 + * Setter for the Uint16Array property. 20.353 + * @param self self reference 20.354 + * @param value value of the Uint16Array property 20.355 + */ 20.356 @Setter(name = "Uint16Array", attributes = Attribute.NOT_ENUMERABLE) 20.357 public static void setUint16Array(final Object self, final Object value) { 20.358 final Global global = Global.instanceFrom(self); 20.359 @@ -492,7 +624,12 @@ 20.360 20.361 private volatile Object uint16Array; 20.362 20.363 - /** TypedArray (int32) */ 20.364 + /** 20.365 + * Getter for the Int32Array property. 20.366 + * 20.367 + * @param self self reference 20.368 + * @return the value of the Int32Array property 20.369 + */ 20.370 @Getter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) 20.371 public static Object getInt32Array(final Object self) { 20.372 final Global global = Global.instanceFrom(self); 20.373 @@ -502,6 +639,13 @@ 20.374 return global.int32Array; 20.375 } 20.376 20.377 + 20.378 + /** 20.379 + * Setter for the Int32Array property. 20.380 + * 20.381 + * @param self self reference 20.382 + * @param value value of the Int32Array property 20.383 + */ 20.384 @Setter(name = "Int32Array", attributes = Attribute.NOT_ENUMERABLE) 20.385 public static void setInt32Array(final Object self, final Object value) { 20.386 final Global global = Global.instanceFrom(self); 20.387 @@ -510,7 +654,12 @@ 20.388 20.389 private volatile Object int32Array; 20.390 20.391 - /** TypedArray (uint32) */ 20.392 + /** 20.393 + * Getter of the Uint32Array property. 20.394 + * 20.395 + * @param self self reference 20.396 + * @return the value of the Uint32Array property 20.397 + */ 20.398 @Getter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) 20.399 public static Object getUint32Array(final Object self) { 20.400 final Global global = Global.instanceFrom(self); 20.401 @@ -520,6 +669,13 @@ 20.402 return global.uint32Array; 20.403 } 20.404 20.405 + 20.406 + /** 20.407 + * Setter of the Uint32Array property. 20.408 + * 20.409 + * @param self self reference 20.410 + * @param value value of the Uint32Array property 20.411 + */ 20.412 @Setter(name = "Uint32Array", attributes = Attribute.NOT_ENUMERABLE) 20.413 public static void setUint32Array(final Object self, final Object value) { 20.414 final Global global = Global.instanceFrom(self); 20.415 @@ -528,7 +684,12 @@ 20.416 20.417 private volatile Object uint32Array; 20.418 20.419 - /** TypedArray (float32) */ 20.420 + /** 20.421 + * Getter for the Float32Array property. 20.422 + * 20.423 + * @param self self reference 20.424 + * @return the value of the Float32Array property 20.425 + */ 20.426 @Getter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) 20.427 public static Object getFloat32Array(final Object self) { 20.428 final Global global = Global.instanceFrom(self); 20.429 @@ -538,6 +699,12 @@ 20.430 return global.float32Array; 20.431 } 20.432 20.433 + /** 20.434 + * Setter for the Float32Array property. 20.435 + * 20.436 + * @param self self reference 20.437 + * @param value value of the Float32Array property 20.438 + */ 20.439 @Setter(name = "Float32Array", attributes = Attribute.NOT_ENUMERABLE) 20.440 public static void setFloat32Array(final Object self, final Object value) { 20.441 final Global global = Global.instanceFrom(self); 20.442 @@ -546,7 +713,12 @@ 20.443 20.444 private volatile Object float32Array; 20.445 20.446 - /** TypedArray (float64) */ 20.447 + /** 20.448 + * Getter for the Float64Array property. 20.449 + * 20.450 + * @param self self reference 20.451 + * @return the value of the Float64Array property 20.452 + */ 20.453 @Getter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) 20.454 public static Object getFloat64Array(final Object self) { 20.455 final Global global = Global.instanceFrom(self); 20.456 @@ -556,6 +728,12 @@ 20.457 return global.float64Array; 20.458 } 20.459 20.460 + /** 20.461 + * Setter for the Float64Array property. 20.462 + * 20.463 + * @param self self reference 20.464 + * @param value value of the Float64Array property 20.465 + */ 20.466 @Setter(name = "Float64Array", attributes = Attribute.NOT_ENUMERABLE) 20.467 public static void setFloat64Array(final Object self, final Object value) { 20.468 final Global global = Global.instanceFrom(self); 20.469 @@ -592,7 +770,12 @@ 20.470 @Property(attributes = Attribute.NOT_ENUMERABLE) 20.471 public volatile Object org; 20.472 20.473 - /** Nashorn extension: Java access - global.javaImporter */ 20.474 + /** 20.475 + * Getter for the Nashorn extension: Java access - global.javaImporter. 20.476 + * 20.477 + * @param self self reference 20.478 + * @return the value of the JavaImporter property 20.479 + */ 20.480 @Getter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) 20.481 public static Object getJavaImporter(final Object self) { 20.482 final Global global = Global.instanceFrom(self); 20.483 @@ -602,6 +785,12 @@ 20.484 return global.javaImporter; 20.485 } 20.486 20.487 + /** 20.488 + * Setter for the Nashorn extension: Java access - global.javaImporter. 20.489 + * 20.490 + * @param self self reference 20.491 + * @param value value of the JavaImporter property 20.492 + */ 20.493 @Setter(name = "JavaImporter", attributes = Attribute.NOT_ENUMERABLE) 20.494 public static void setJavaImporter(final Object self, final Object value) { 20.495 final Global global = Global.instanceFrom(self); 20.496 @@ -610,7 +799,12 @@ 20.497 20.498 private volatile Object javaImporter; 20.499 20.500 - /** Nashorn extension: global.Java Object constructor. */ 20.501 + /** 20.502 + * Getter for the Nashorn extension: global.Java property. 20.503 + * 20.504 + * @param self self reference 20.505 + * @return the value of the Java property 20.506 + */ 20.507 @Getter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) 20.508 public static Object getJavaApi(final Object self) { 20.509 final Global global = Global.instanceFrom(self); 20.510 @@ -620,6 +814,12 @@ 20.511 return global.javaApi; 20.512 } 20.513 20.514 + /** 20.515 + * Setter for the Nashorn extension: global.Java property. 20.516 + * 20.517 + * @param self self reference 20.518 + * @param value value of the Java property 20.519 + */ 20.520 @Setter(name = "Java", attributes = Attribute.NOT_ENUMERABLE) 20.521 public static void setJavaApi(final Object self, final Object value) { 20.522 final Global global = Global.instanceFrom(self); 20.523 @@ -2140,13 +2340,13 @@ 20.524 @Override 20.525 public void addBoundProperties(final ScriptObject source, final jdk.nashorn.internal.runtime.Property[] properties) { 20.526 PropertyMap ownMap = getMap(); 20.527 - LexicalScope lexicalScope = null; 20.528 + LexicalScope lexScope = null; 20.529 PropertyMap lexicalMap = null; 20.530 boolean hasLexicalDefinitions = false; 20.531 20.532 if (context.getEnv()._es6) { 20.533 - lexicalScope = (LexicalScope) getLexicalScope(); 20.534 - lexicalMap = lexicalScope.getMap(); 20.535 + lexScope = (LexicalScope) getLexicalScope(); 20.536 + lexicalMap = lexScope.getMap(); 20.537 20.538 for (final jdk.nashorn.internal.runtime.Property property : properties) { 20.539 if (property.isLexicalBinding()) { 20.540 @@ -2166,8 +2366,8 @@ 20.541 20.542 for (final jdk.nashorn.internal.runtime.Property property : properties) { 20.543 if (property.isLexicalBinding()) { 20.544 - assert lexicalScope != null; 20.545 - lexicalMap = lexicalScope.addBoundProperty(lexicalMap, source, property); 20.546 + assert lexScope != null; 20.547 + lexicalMap = lexScope.addBoundProperty(lexicalMap, source, property); 20.548 20.549 if (ownMap.findProperty(property.getKey()) != null) { 20.550 // If property exists in the global object invalidate any global constant call sites. 20.551 @@ -2181,7 +2381,8 @@ 20.552 setMap(ownMap); 20.553 20.554 if (hasLexicalDefinitions) { 20.555 - lexicalScope.setMap(lexicalMap); 20.556 + assert lexScope != null; 20.557 + lexScope.setMap(lexicalMap); 20.558 invalidateLexicalSwitchPoint(); 20.559 } 20.560 }
21.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java Wed May 27 13:20:58 2015 -0700 21.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java Thu May 28 16:48:12 2015 -0700 21.3 @@ -33,10 +33,10 @@ 21.4 import java.util.Collection; 21.5 import java.util.Deque; 21.6 import java.util.List; 21.7 +import java.util.Queue; 21.8 import jdk.internal.dynalink.beans.StaticClass; 21.9 import jdk.internal.dynalink.support.TypeUtilities; 21.10 import jdk.nashorn.api.scripting.JSObject; 21.11 -import jdk.nashorn.api.scripting.ScriptUtils; 21.12 import jdk.nashorn.internal.objects.annotations.Attribute; 21.13 import jdk.nashorn.internal.objects.annotations.Function; 21.14 import jdk.nashorn.internal.objects.annotations.ScriptClass; 21.15 @@ -339,7 +339,8 @@ 21.16 21.17 /** 21.18 * Given a script object and a Java type, converts the script object into the desired Java type. Currently it 21.19 - * performs shallow creation of Java arrays, as well as wrapping of objects in Lists and Dequeues. Example: 21.20 + * performs shallow creation of Java arrays, as well as wrapping of objects in Lists, Dequeues, Queues, 21.21 + * and Collections. Example: 21.22 * <pre> 21.23 * var anArray = [1, "13", false] 21.24 * var javaIntArray = Java.to(anArray, "int[]") 21.25 @@ -353,9 +354,10 @@ 21.26 * object to create. Can not be null. If undefined, a "default" conversion is presumed (allowing the argument to be 21.27 * omitted). 21.28 * @return a Java object whose value corresponds to the original script object's value. Specifically, for array 21.29 - * target types, returns a Java array of the same type with contents converted to the array's component type. Does 21.30 - * not recursively convert for multidimensional arrays. For {@link List} or {@link Deque}, returns a live wrapper 21.31 - * around the object, see {@link ListAdapter} for details. Returns null if obj is null. 21.32 + * target types, returns a Java array of the same type with contents converted to the array's component type. 21.33 + * Converts recursively when the target type is multidimensional array. For {@link List}, {@link Deque}, 21.34 + * {@link Queue}, or {@link Collection}, returns a live wrapper around the object, see {@link ListAdapter} for 21.35 + * details. Returns null if obj is null. 21.36 * @throws ClassNotFoundException if the class described by objType is not found 21.37 */ 21.38 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 21.39 @@ -385,7 +387,7 @@ 21.40 return JSType.toJavaArray(obj, targetClass.getComponentType()); 21.41 } 21.42 21.43 - if(targetClass == List.class || targetClass == Deque.class) { 21.44 + if (targetClass == List.class || targetClass == Deque.class || targetClass == Queue.class || targetClass == Collection.class) { 21.45 return ListAdapter.create(obj); 21.46 } 21.47
22.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Wed May 27 13:20:58 2015 -0700 22.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Thu May 28 16:48:12 2015 -0700 22.3 @@ -765,7 +765,7 @@ 22.4 continue; 22.5 } 22.6 properties.add(AccessorProperty.create(methodName, Property.NOT_WRITABLE, getBoundBeanMethodGetter(source, 22.7 - method), null)); 22.8 + method), Lookup.EMPTY_SETTER)); 22.9 } 22.10 for(final String propertyName: propertyNames) { 22.11 MethodHandle getter;
23.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Wed May 27 13:20:58 2015 -0700 23.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Thu May 28 16:48:12 2015 -0700 23.3 @@ -607,7 +607,7 @@ 23.4 * @return whether the ident can be used as L-value 23.5 */ 23.6 private static boolean checkIdentLValue(final IdentNode ident) { 23.7 - return Token.descType(ident.getToken()).getKind() != TokenKind.KEYWORD; 23.8 + return ident.tokenType().getKind() != TokenKind.KEYWORD; 23.9 } 23.10 23.11 /**
24.1 --- a/src/jdk/nashorn/internal/runtime/CodeInstaller.java Wed May 27 13:20:58 2015 -0700 24.2 +++ b/src/jdk/nashorn/internal/runtime/CodeInstaller.java Thu May 28 16:48:12 2015 -0700 24.3 @@ -86,7 +86,7 @@ 24.4 * @param source the script source 24.5 * @param mainClassName the main class name 24.6 * @param classBytes map of class names to class bytes 24.7 - * @param initializers compilation id -> FunctionInitializer map 24.8 + * @param initializers compilation id -> FunctionInitializer map 24.9 * @param constants constants array 24.10 * @param compilationId compilation id 24.11 */
25.1 --- a/src/jdk/nashorn/internal/runtime/JSObjectListAdapter.java Wed May 27 13:20:58 2015 -0700 25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 25.3 @@ -1,56 +0,0 @@ 25.4 -/* 25.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 25.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 - * 25.8 - * This code is free software; you can redistribute it and/or modify it 25.9 - * under the terms of the GNU General Public License version 2 only, as 25.10 - * published by the Free Software Foundation. Oracle designates this 25.11 - * particular file as subject to the "Classpath" exception as provided 25.12 - * by Oracle in the LICENSE file that accompanied this code. 25.13 - * 25.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 25.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.17 - * version 2 for more details (a copy is included in the LICENSE file that 25.18 - * accompanied this code). 25.19 - * 25.20 - * You should have received a copy of the GNU General Public License version 25.21 - * 2 along with this work; if not, write to the Free Software Foundation, 25.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.23 - * 25.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.25 - * or visit www.oracle.com if you need additional information or have any 25.26 - * questions. 25.27 - */ 25.28 - 25.29 -package jdk.nashorn.internal.runtime; 25.30 - 25.31 -import jdk.nashorn.api.scripting.JSObject; 25.32 - 25.33 -/** 25.34 - * A ListAdapter that can wraps a JSObject. 25.35 - */ 25.36 -public final class JSObjectListAdapter extends ListAdapter { 25.37 - /** 25.38 - * Creates a new list wrapper for the specified JSObject. 25.39 - * @param obj JSOcript the object to wrap 25.40 - */ 25.41 - public JSObjectListAdapter(final JSObject obj) { 25.42 - super(obj); 25.43 - } 25.44 - 25.45 - @Override 25.46 - public int size() { 25.47 - return JSType.toInt32(((JSObject)obj).getMember("length")); 25.48 - } 25.49 - 25.50 - @Override 25.51 - protected Object getAt(final int index) { 25.52 - return ((JSObject)obj).getSlot(index); 25.53 - } 25.54 - 25.55 - @Override 25.56 - protected void setAt(final int index, final Object element) { 25.57 - ((JSObject)obj).setSlot(index, element); 25.58 - } 25.59 -}
26.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Wed May 27 13:20:58 2015 -0700 26.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Thu May 28 16:48:12 2015 -0700 26.3 @@ -34,7 +34,6 @@ 26.4 import java.lang.reflect.Array; 26.5 import java.util.Arrays; 26.6 import java.util.Collections; 26.7 -import java.util.Deque; 26.8 import java.util.List; 26.9 import jdk.internal.dynalink.beans.StaticClass; 26.10 import jdk.nashorn.api.scripting.AbstractJSObject; 26.11 @@ -181,10 +180,10 @@ 26.12 /** Div exact wrapper for potentially integer division that turns into float point */ 26.13 public static final Call DIV_EXACT_LONG = staticCall(JSTYPE_LOOKUP, JSType.class, "divExact", long.class, long.class, long.class, int.class); 26.14 26.15 - /** Div zero wrapper for long division that handles (0/0) >>> 0 == 0 */ 26.16 + /** Div zero wrapper for long division that handles (0/0) >>> 0 == 0 */ 26.17 public static final Call DIV_ZERO_LONG = staticCall(JSTYPE_LOOKUP, JSType.class, "divZero", long.class, long.class, long.class); 26.18 26.19 - /** Mod zero wrapper for long division that handles (0%0) >>> 0 == 0 */ 26.20 + /** Mod zero wrapper for long division that handles (0%0) >>> 0 == 0 */ 26.21 public static final Call REM_ZERO_LONG = staticCall(JSTYPE_LOOKUP, JSType.class, "remZero", long.class, long.class, long.class); 26.22 26.23 /** Mod exact wrapper for potentially integer remainders that turns into float point */ 26.24 @@ -202,12 +201,6 @@ 26.25 /** Method handle to convert a JS Object to a Java array. */ 26.26 public static final Call TO_JAVA_ARRAY = staticCall(JSTYPE_LOOKUP, JSType.class, "toJavaArray", Object.class, Object.class, Class.class); 26.27 26.28 - /** Method handle to convert a JS Object to a Java List. */ 26.29 - public static final Call TO_JAVA_LIST = staticCall(JSTYPE_LOOKUP, JSType.class, "toJavaList", List.class, Object.class); 26.30 - 26.31 - /** Method handle to convert a JS Object to a Java deque. */ 26.32 - public static final Call TO_JAVA_DEQUE = staticCall(JSTYPE_LOOKUP, JSType.class, "toJavaDeque", Deque.class, Object.class); 26.33 - 26.34 /** Method handle for void returns. */ 26.35 public static final Call VOID_RETURN = staticCall(JSTYPE_LOOKUP, JSType.class, "voidReturn", void.class); 26.36 26.37 @@ -1352,24 +1345,6 @@ 26.38 } 26.39 26.40 /** 26.41 - * Converts a JavaScript object to a Java List. See {@link ListAdapter} for details. 26.42 - * @param obj the object to convert. Can be any array-like object. 26.43 - * @return a List that is live-backed by the JavaScript object. 26.44 - */ 26.45 - public static List<?> toJavaList(final Object obj) { 26.46 - return ListAdapter.create(obj); 26.47 - } 26.48 - 26.49 - /** 26.50 - * Converts a JavaScript object to a Java Deque. See {@link ListAdapter} for details. 26.51 - * @param obj the object to convert. Can be any array-like object. 26.52 - * @return a Deque that is live-backed by the JavaScript object. 26.53 - */ 26.54 - public static Deque<?> toJavaDeque(final Object obj) { 26.55 - return ListAdapter.create(obj); 26.56 - } 26.57 - 26.58 - /** 26.59 * Check if an object is null or undefined 26.60 * 26.61 * @param obj object to check
27.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Wed May 27 13:20:58 2015 -0700 27.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Thu May 28 16:48:12 2015 -0700 27.3 @@ -25,17 +25,18 @@ 27.4 27.5 package jdk.nashorn.internal.runtime; 27.6 27.7 +import java.lang.invoke.MethodHandle; 27.8 import java.util.AbstractList; 27.9 import java.util.Deque; 27.10 import java.util.Iterator; 27.11 import java.util.ListIterator; 27.12 import java.util.NoSuchElementException; 27.13 +import java.util.Objects; 27.14 import java.util.RandomAccess; 27.15 import java.util.concurrent.Callable; 27.16 import jdk.nashorn.api.scripting.JSObject; 27.17 import jdk.nashorn.api.scripting.ScriptObjectMirror; 27.18 import jdk.nashorn.internal.runtime.linker.Bootstrap; 27.19 -import jdk.nashorn.internal.runtime.linker.InvokeByName; 27.20 27.21 /** 27.22 * An adapter that can wrap any ECMAScript Array-like object (that adheres to the array rules for the property 27.23 @@ -50,81 +51,56 @@ 27.24 * operations respectively, while {@link #addLast(Object)} and {@link #removeLast()} will translate to {@code push} and 27.25 * {@code pop}. 27.26 */ 27.27 -public abstract class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 27.28 - // These add to the back and front of the list 27.29 - private static final Object PUSH = new Object(); 27.30 - private static InvokeByName getPUSH() { 27.31 - return Context.getGlobal().getInvokeByName(PUSH, 27.32 - new Callable<InvokeByName>() { 27.33 - @Override 27.34 - public InvokeByName call() { 27.35 - return new InvokeByName("push", Object.class, void.class, Object.class); 27.36 - } 27.37 - }); 27.38 +public final class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 27.39 + // Invoker creator for methods that add to the start or end of the list: PUSH and UNSHIFT. Takes fn, this, and value, returns void. 27.40 + private static final Callable<MethodHandle> ADD_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, Object.class); 27.41 + 27.42 + // PUSH adds to the end of the list 27.43 + private static final Object PUSH = new Object(); 27.44 + private static MethodHandle getPushInvoker() { 27.45 + return getDynamicInvoker(PUSH, ADD_INVOKER_CREATOR); 27.46 } 27.47 27.48 + // UNSHIFT adds to the start of the list 27.49 private static final Object UNSHIFT = new Object(); 27.50 - private static InvokeByName getUNSHIFT() { 27.51 - return Context.getGlobal().getInvokeByName(UNSHIFT, 27.52 - new Callable<InvokeByName>() { 27.53 - @Override 27.54 - public InvokeByName call() { 27.55 - return new InvokeByName("unshift", Object.class, void.class, Object.class); 27.56 - } 27.57 - }); 27.58 + private static MethodHandle getUnshiftInvoker() { 27.59 + return getDynamicInvoker(UNSHIFT, ADD_INVOKER_CREATOR); 27.60 } 27.61 27.62 - // These remove from the back and front of the list 27.63 + // Invoker creator for methods that remove from the tail or head of the list: POP and SHIFT. Takes fn, this, returns Object. 27.64 + private static final Callable<MethodHandle> REMOVE_INVOKER_CREATOR = invokerCreator(Object.class, Object.class, JSObject.class); 27.65 + 27.66 + // POP removes from the to the end of the list 27.67 private static final Object POP = new Object(); 27.68 - private static InvokeByName getPOP() { 27.69 - return Context.getGlobal().getInvokeByName(POP, 27.70 - new Callable<InvokeByName>() { 27.71 - @Override 27.72 - public InvokeByName call() { 27.73 - return new InvokeByName("pop", Object.class, Object.class); 27.74 - } 27.75 - }); 27.76 + private static MethodHandle getPopInvoker() { 27.77 + return getDynamicInvoker(POP, REMOVE_INVOKER_CREATOR); 27.78 } 27.79 27.80 + // SHIFT removes from the to the start of the list 27.81 private static final Object SHIFT = new Object(); 27.82 - private static InvokeByName getSHIFT() { 27.83 - return Context.getGlobal().getInvokeByName(SHIFT, 27.84 - new Callable<InvokeByName>() { 27.85 - @Override 27.86 - public InvokeByName call() { 27.87 - return new InvokeByName("shift", Object.class, Object.class); 27.88 - } 27.89 - }); 27.90 + private static MethodHandle getShiftInvoker() { 27.91 + return getDynamicInvoker(SHIFT, REMOVE_INVOKER_CREATOR); 27.92 } 27.93 27.94 - // These insert and remove in the middle of the list 27.95 + // SPLICE can be used to add a value in the middle of the list. 27.96 private static final Object SPLICE_ADD = new Object(); 27.97 - private static InvokeByName getSPLICE_ADD() { 27.98 - return Context.getGlobal().getInvokeByName(SPLICE_ADD, 27.99 - new Callable<InvokeByName>() { 27.100 - @Override 27.101 - public InvokeByName call() { 27.102 - return new InvokeByName("splice", Object.class, void.class, int.class, int.class, Object.class); 27.103 - } 27.104 - }); 27.105 + private static final Callable<MethodHandle> SPLICE_ADD_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, int.class, int.class, Object.class); 27.106 + private static MethodHandle getSpliceAddInvoker() { 27.107 + return getDynamicInvoker(SPLICE_ADD, SPLICE_ADD_INVOKER_CREATOR); 27.108 } 27.109 27.110 + // SPLICE can also be used to remove values from the middle of the list. 27.111 private static final Object SPLICE_REMOVE = new Object(); 27.112 - private static InvokeByName getSPLICE_REMOVE() { 27.113 - return Context.getGlobal().getInvokeByName(SPLICE_REMOVE, 27.114 - new Callable<InvokeByName>() { 27.115 - @Override 27.116 - public InvokeByName call() { 27.117 - return new InvokeByName("splice", Object.class, void.class, int.class, int.class); 27.118 - } 27.119 - }); 27.120 + private static final Callable<MethodHandle> SPLICE_REMOVE_INVOKER_CREATOR = invokerCreator(void.class, Object.class, JSObject.class, int.class, int.class); 27.121 + private static MethodHandle getSpliceRemoveInvoker() { 27.122 + return getDynamicInvoker(SPLICE_REMOVE, SPLICE_REMOVE_INVOKER_CREATOR); 27.123 } 27.124 27.125 /** wrapped object */ 27.126 - protected final Object obj; 27.127 + protected final JSObject obj; 27.128 27.129 // allow subclasses only in this package 27.130 - ListAdapter(final Object obj) { 27.131 + ListAdapter(final JSObject obj) { 27.132 this.obj = obj; 27.133 } 27.134 27.135 @@ -135,14 +111,16 @@ 27.136 * @return A ListAdapter wrapper object 27.137 */ 27.138 public static ListAdapter create(final Object obj) { 27.139 + return new ListAdapter(getJSObject(obj)); 27.140 + } 27.141 + 27.142 + private static JSObject getJSObject(final Object obj) { 27.143 if (obj instanceof ScriptObject) { 27.144 - final Object mirror = ScriptObjectMirror.wrap(obj, Context.getGlobal()); 27.145 - return new JSObjectListAdapter((JSObject)mirror); 27.146 + return (JSObject)ScriptObjectMirror.wrap(obj, Context.getGlobal()); 27.147 } else if (obj instanceof JSObject) { 27.148 - return new JSObjectListAdapter((JSObject)obj); 27.149 - } else { 27.150 - throw new IllegalArgumentException("ScriptObject or JSObject expected"); 27.151 + return (JSObject)obj; 27.152 } 27.153 + throw new IllegalArgumentException("ScriptObject or JSObject expected"); 27.154 } 27.155 27.156 @Override 27.157 @@ -151,28 +129,18 @@ 27.158 return getAt(index); 27.159 } 27.160 27.161 - /** 27.162 - * Get object at an index 27.163 - * @param index index in list 27.164 - * @return object 27.165 - */ 27.166 - protected abstract Object getAt(final int index); 27.167 + private Object getAt(final int index) { 27.168 + return obj.getSlot(index); 27.169 + } 27.170 27.171 @Override 27.172 public Object set(final int index, final Object element) { 27.173 checkRange(index); 27.174 final Object prevValue = getAt(index); 27.175 - setAt(index, element); 27.176 + obj.setSlot(index, element); 27.177 return prevValue; 27.178 } 27.179 27.180 - /** 27.181 - * Set object at an index 27.182 - * @param index index in list 27.183 - * @param element element 27.184 - */ 27.185 - protected abstract void setAt(final int index, final Object element); 27.186 - 27.187 private void checkRange(final int index) { 27.188 if(index < 0 || index >= size()) { 27.189 throw invalidIndex(index); 27.190 @@ -180,6 +148,11 @@ 27.191 } 27.192 27.193 @Override 27.194 + public int size() { 27.195 + return JSType.toInt32(obj.getMember("length")); 27.196 + } 27.197 + 27.198 + @Override 27.199 public final void push(final Object e) { 27.200 addFirst(e); 27.201 } 27.202 @@ -193,10 +166,7 @@ 27.203 @Override 27.204 public final void addFirst(final Object e) { 27.205 try { 27.206 - final InvokeByName unshiftInvoker = getUNSHIFT(); 27.207 - final Object fn = unshiftInvoker.getGetter().invokeExact(obj); 27.208 - checkFunction(fn, unshiftInvoker); 27.209 - unshiftInvoker.getInvoker().invokeExact(fn, obj, e); 27.210 + getUnshiftInvoker().invokeExact(getFunction("unshift"), obj, e); 27.211 } catch(RuntimeException | Error ex) { 27.212 throw ex; 27.213 } catch(final Throwable t) { 27.214 @@ -207,10 +177,7 @@ 27.215 @Override 27.216 public final void addLast(final Object e) { 27.217 try { 27.218 - final InvokeByName pushInvoker = getPUSH(); 27.219 - final Object fn = pushInvoker.getGetter().invokeExact(obj); 27.220 - checkFunction(fn, pushInvoker); 27.221 - pushInvoker.getInvoker().invokeExact(fn, obj, e); 27.222 + getPushInvoker().invokeExact(getFunction("push"), obj, e); 27.223 } catch(RuntimeException | Error ex) { 27.224 throw ex; 27.225 } catch(final Throwable t) { 27.226 @@ -228,10 +195,7 @@ 27.227 } else { 27.228 final int size = size(); 27.229 if(index < size) { 27.230 - final InvokeByName spliceAddInvoker = getSPLICE_ADD(); 27.231 - final Object fn = spliceAddInvoker.getGetter().invokeExact(obj); 27.232 - checkFunction(fn, spliceAddInvoker); 27.233 - spliceAddInvoker.getInvoker().invokeExact(fn, obj, index, 0, e); 27.234 + getSpliceAddInvoker().invokeExact(obj.getMember("splice"), obj, index, 0, e); 27.235 } else if(index == size) { 27.236 addLast(e); 27.237 } else { 27.238 @@ -244,10 +208,12 @@ 27.239 throw new RuntimeException(t); 27.240 } 27.241 } 27.242 - private static void checkFunction(final Object fn, final InvokeByName invoke) { 27.243 + private Object getFunction(final String name) { 27.244 + final Object fn = obj.getMember(name); 27.245 if(!(Bootstrap.isCallable(fn))) { 27.246 - throw new UnsupportedOperationException("The script object doesn't have a function named " + invoke.getName()); 27.247 + throw new UnsupportedOperationException("The script object doesn't have a function named " + name); 27.248 } 27.249 + return fn; 27.250 } 27.251 27.252 private static IndexOutOfBoundsException invalidIndex(final int index) { 27.253 @@ -321,10 +287,7 @@ 27.254 27.255 private Object invokeShift() { 27.256 try { 27.257 - final InvokeByName shiftInvoker = getSHIFT(); 27.258 - final Object fn = shiftInvoker.getGetter().invokeExact(obj); 27.259 - checkFunction(fn, shiftInvoker); 27.260 - return shiftInvoker.getInvoker().invokeExact(fn, obj); 27.261 + return getShiftInvoker().invokeExact(getFunction("shift"), obj); 27.262 } catch(RuntimeException | Error ex) { 27.263 throw ex; 27.264 } catch(final Throwable t) { 27.265 @@ -334,10 +297,7 @@ 27.266 27.267 private Object invokePop() { 27.268 try { 27.269 - final InvokeByName popInvoker = getPOP(); 27.270 - final Object fn = popInvoker.getGetter().invokeExact(obj); 27.271 - checkFunction(fn, popInvoker); 27.272 - return popInvoker.getInvoker().invokeExact(fn, obj); 27.273 + return getPopInvoker().invokeExact(getFunction("pop"), obj); 27.274 } catch(RuntimeException | Error ex) { 27.275 throw ex; 27.276 } catch(final Throwable t) { 27.277 @@ -352,10 +312,7 @@ 27.278 27.279 private void invokeSpliceRemove(final int fromIndex, final int count) { 27.280 try { 27.281 - final InvokeByName spliceRemoveInvoker = getSPLICE_REMOVE(); 27.282 - final Object fn = spliceRemoveInvoker.getGetter().invokeExact(obj); 27.283 - checkFunction(fn, spliceRemoveInvoker); 27.284 - spliceRemoveInvoker.getInvoker().invokeExact(fn, obj, fromIndex, count); 27.285 + getSpliceRemoveInvoker().invokeExact(getFunction("splice"), obj, fromIndex, count); 27.286 } catch(RuntimeException | Error ex) { 27.287 throw ex; 27.288 } catch(final Throwable t) { 27.289 @@ -443,12 +400,24 @@ 27.290 27.291 private static boolean removeOccurrence(final Object o, final Iterator<Object> it) { 27.292 while(it.hasNext()) { 27.293 - final Object e = it.next(); 27.294 - if(o == null ? e == null : o.equals(e)) { 27.295 + if(Objects.equals(o, it.next())) { 27.296 it.remove(); 27.297 return true; 27.298 } 27.299 } 27.300 return false; 27.301 } 27.302 + 27.303 + private static Callable<MethodHandle> invokerCreator(final Class<?> rtype, final Class<?>... ptypes) { 27.304 + return new Callable<MethodHandle>() { 27.305 + @Override 27.306 + public MethodHandle call() { 27.307 + return Bootstrap.createDynamicInvoker("dyn:call", rtype, ptypes); 27.308 + } 27.309 + }; 27.310 + } 27.311 + 27.312 + private static MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 27.313 + return Context.getGlobal().getDynamicInvoker(key, creator); 27.314 + } 27.315 }
28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed May 27 13:20:58 2015 -0700 28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Thu May 28 16:48:12 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 @@ -34,10 +34,13 @@ 28.11 import java.io.IOException; 28.12 import java.io.InputStreamReader; 28.13 import java.io.OutputStreamWriter; 28.14 +import java.io.StreamTokenizer; 28.15 +import java.io.StringReader; 28.16 import java.lang.invoke.MethodHandle; 28.17 import java.lang.invoke.MethodHandles; 28.18 +import java.util.ArrayList; 28.19 +import java.util.List; 28.20 import java.util.Map; 28.21 -import java.util.StringTokenizer; 28.22 28.23 /** 28.24 * Global functions supported only in scripting mode. 28.25 @@ -133,15 +136,8 @@ 28.26 // Current global is need to fetch additional inputs and for additional results. 28.27 final ScriptObject global = Context.getGlobal(); 28.28 28.29 - // Break exec string into tokens. 28.30 - final StringTokenizer tokenizer = new StringTokenizer(JSType.toString(string)); 28.31 - final String[] cmdArray = new String[tokenizer.countTokens()]; 28.32 - for (int i = 0; tokenizer.hasMoreTokens(); i++) { 28.33 - cmdArray[i] = tokenizer.nextToken(); 28.34 - } 28.35 - 28.36 // Set up initial process. 28.37 - final ProcessBuilder processBuilder = new ProcessBuilder(cmdArray); 28.38 + final ProcessBuilder processBuilder = new ProcessBuilder(tokenizeCommandLine(JSType.toString(string))); 28.39 28.40 // Current ENV property state. 28.41 final Object env = global.get(ENV_NAME); 28.42 @@ -239,4 +235,43 @@ 28.43 private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 28.44 return MH.findStatic(MethodHandles.lookup(), ScriptingFunctions.class, name, MH.type(rtype, types)); 28.45 } 28.46 + 28.47 + /** 28.48 + * Break an exec string into tokens, honoring quoted arguments and escaped 28.49 + * spaces. 28.50 + * 28.51 + * @param execString a {@link String} with the command line to execute. 28.52 + * @return a {@link List} of {@link String}s representing the tokens that 28.53 + * constitute the command line. 28.54 + * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it. 28.55 + */ 28.56 + public static List<String> tokenizeCommandLine(final String execString) throws IOException { 28.57 + final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(execString)); 28.58 + tokenizer.resetSyntax(); 28.59 + tokenizer.wordChars(0, 255); 28.60 + tokenizer.whitespaceChars(0, ' '); 28.61 + tokenizer.commentChar('#'); 28.62 + tokenizer.quoteChar('"'); 28.63 + tokenizer.quoteChar('\''); 28.64 + final List<String> cmdList = new ArrayList<>(); 28.65 + final StringBuilder toAppend = new StringBuilder(); 28.66 + while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) { 28.67 + final String s = tokenizer.sval; 28.68 + // The tokenizer understands about honoring quoted strings and recognizes 28.69 + // them as one token that possibly contains multiple space-separated words. 28.70 + // It does not recognize quoted spaces, though, and will split after the 28.71 + // escaping \ character. This is handled here. 28.72 + if (s.endsWith("\\")) { 28.73 + // omit trailing \, append space instead 28.74 + toAppend.append(s.substring(0, s.length() - 1)).append(' '); 28.75 + } else { 28.76 + cmdList.add(toAppend.append(s).toString()); 28.77 + toAppend.setLength(0); 28.78 + } 28.79 + } 28.80 + if (toAppend.length() != 0) { 28.81 + cmdList.add(toAppend.toString()); 28.82 + } 28.83 + return cmdList; 28.84 + } 28.85 }
29.1 --- a/src/jdk/nashorn/internal/runtime/StoredScript.java Wed May 27 13:20:58 2015 -0700 29.2 +++ b/src/jdk/nashorn/internal/runtime/StoredScript.java Thu May 28 16:48:12 2015 -0700 29.3 @@ -58,7 +58,7 @@ 29.4 * @param compilationId compilation id 29.5 * @param mainClassName main class name 29.6 * @param classBytes map of class names to class bytes 29.7 - * @param initializers initializer map, id -> FunctionInitializer 29.8 + * @param initializers initializer map, id -> FunctionInitializer 29.9 * @param constants constants array 29.10 */ 29.11 public StoredScript(final int compilationId, final String mainClassName, final Map<String, byte[]> classBytes, final Map<Integer, FunctionInitializer> initializers, final Object[] constants) {
30.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Wed May 27 13:20:58 2015 -0700 30.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayData.java Thu May 28 16:48:12 2015 -0700 30.3 @@ -276,7 +276,7 @@ 30.4 /** 30.5 * Align an array size up to the nearest array chunk size 30.6 * @param size size required 30.7 - * @return size given, always >= size 30.8 + * @return size given, always >= size 30.9 */ 30.10 protected final static int alignUp(final int size) { 30.11 return size + CHUNK_SIZE - 1 & ~(CHUNK_SIZE - 1);
31.1 --- a/src/jdk/nashorn/internal/runtime/arrays/IntArrayData.java Wed May 27 13:20:58 2015 -0700 31.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/IntArrayData.java Thu May 28 16:48:12 2015 -0700 31.3 @@ -182,14 +182,13 @@ 31.4 31.5 @Override 31.6 public ArrayData convert(final Class<?> type) { 31.7 - if (type == Integer.class) { 31.8 + if (type == Integer.class || type == Byte.class || type == Short.class) { 31.9 return this; 31.10 } else if (type == Long.class) { 31.11 return convertToLong(); 31.12 - } else if (type == Double.class) { 31.13 + } else if (type == Double.class || type == Float.class) { 31.14 return convertToDouble(); 31.15 } else { 31.16 - assert type == null || (!Number.class.isAssignableFrom(type) && !type.isPrimitive()); 31.17 return convertToObject(); 31.18 } 31.19 }
32.1 --- a/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Wed May 27 13:20:58 2015 -0700 32.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Thu May 28 16:48:12 2015 -0700 32.3 @@ -120,11 +120,11 @@ 32.4 32.5 @Override 32.6 public ContinuousArrayData convert(final Class<?> type) { 32.7 - if (type == Integer.class || type == Long.class) { 32.8 + if (type == Integer.class || type == Long.class || type == Byte.class || type == Short.class) { 32.9 return this; 32.10 } 32.11 final int len = (int)length(); 32.12 - if (type == Double.class) { 32.13 + if (type == Double.class || type == Float.class) { 32.14 return new NumberArrayData(toDoubleArray(), len); 32.15 } 32.16 return new ObjectArrayData(toObjectArray(false), len); 32.17 @@ -171,7 +171,8 @@ 32.18 32.19 @Override 32.20 public ArrayData set(final int index, final Object value, final boolean strict) { 32.21 - if (value instanceof Long || value instanceof Integer) { 32.22 + if (value instanceof Long || value instanceof Integer || 32.23 + value instanceof Byte || value instanceof Short) { 32.24 return set(index, ((Number)value).longValue(), strict); 32.25 } else if (value == ScriptRuntime.UNDEFINED) { 32.26 return new UndefinedArrayFilter(this).set(index, value, strict);
33.1 --- a/src/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Wed May 27 13:20:58 2015 -0700 33.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Thu May 28 16:48:12 2015 -0700 33.3 @@ -29,6 +29,7 @@ 33.4 import static jdk.nashorn.internal.lookup.Lookup.MH; 33.5 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 33.6 33.7 +import jdk.internal.dynalink.support.TypeUtilities; 33.8 import java.lang.invoke.MethodHandle; 33.9 import java.lang.invoke.MethodHandles; 33.10 import java.util.Arrays; 33.11 @@ -104,9 +105,14 @@ 33.12 return super.asArrayOfType(componentType); 33.13 } 33.14 33.15 + private static boolean canWiden(final Class<?> type) { 33.16 + return TypeUtilities.isWrapperType(type) && 33.17 + type != Boolean.class && type != Character.class; 33.18 + } 33.19 + 33.20 @Override 33.21 public ContinuousArrayData convert(final Class<?> type) { 33.22 - if (type != Double.class && type != Integer.class && type != Long.class) { 33.23 + if (! canWiden(type)) { 33.24 final int len = (int)length(); 33.25 return new ObjectArrayData(toObjectArray(false), len); 33.26 } 33.27 @@ -154,7 +160,7 @@ 33.28 33.29 @Override 33.30 public ArrayData set(final int index, final Object value, final boolean strict) { 33.31 - if (value instanceof Double || value instanceof Integer || value instanceof Long) { 33.32 + if (value instanceof Double || (value != null && canWiden(value.getClass()))) { 33.33 return set(index, ((Number)value).doubleValue(), strict); 33.34 } else if (value == UNDEFINED) { 33.35 return new UndefinedArrayFilter(this).set(index, value, strict);
34.1 --- a/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java Wed May 27 13:20:58 2015 -0700 34.2 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java Thu May 28 16:48:12 2015 -0700 34.3 @@ -29,13 +29,15 @@ 34.4 34.5 import java.lang.invoke.MethodHandle; 34.6 import java.lang.invoke.MethodHandles; 34.7 -import java.lang.invoke.MethodHandles.Lookup; 34.8 +import java.lang.invoke.MethodType; 34.9 import java.lang.reflect.Modifier; 34.10 import java.security.AccessController; 34.11 import java.security.PrivilegedAction; 34.12 +import java.util.Collection; 34.13 import java.util.Deque; 34.14 import java.util.List; 34.15 import java.util.Map; 34.16 +import java.util.Queue; 34.17 import javax.script.Bindings; 34.18 import jdk.internal.dynalink.CallSiteDescriptor; 34.19 import jdk.internal.dynalink.linker.ConversionComparator; 34.20 @@ -47,11 +49,13 @@ 34.21 import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; 34.22 import jdk.internal.dynalink.support.Guards; 34.23 import jdk.internal.dynalink.support.LinkerServicesImpl; 34.24 +import jdk.internal.dynalink.support.Lookup; 34.25 import jdk.nashorn.api.scripting.JSObject; 34.26 import jdk.nashorn.api.scripting.ScriptObjectMirror; 34.27 import jdk.nashorn.api.scripting.ScriptUtils; 34.28 import jdk.nashorn.internal.objects.NativeArray; 34.29 import jdk.nashorn.internal.runtime.JSType; 34.30 +import jdk.nashorn.internal.runtime.ListAdapter; 34.31 import jdk.nashorn.internal.runtime.ScriptFunction; 34.32 import jdk.nashorn.internal.runtime.ScriptObject; 34.33 import jdk.nashorn.internal.runtime.Undefined; 34.34 @@ -167,7 +171,7 @@ 34.35 return null; 34.36 } 34.37 34.38 - private static Lookup getCurrentLookup() { 34.39 + private static java.lang.invoke.MethodHandles.Lookup getCurrentLookup() { 34.40 final LinkRequest currentRequest = AccessController.doPrivileged(new PrivilegedAction<LinkRequest>() { 34.41 @Override 34.42 public LinkRequest run() { 34.43 @@ -179,12 +183,12 @@ 34.44 34.45 /** 34.46 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or 34.47 - * Deque type. 34.48 + * Queue or Deque or Collection type. 34.49 * @param sourceType the source type (presumably NativeArray a superclass of it) 34.50 - * @param targetType the target type (presumably an array type, or List or Deque) 34.51 + * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection) 34.52 * @return a guarded invocation that converts from the source type to the target type. null is returned if 34.53 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array 34.54 - * type, List, or Deque. 34.55 + * type, List, Queue, Deque, or Collection. 34.56 */ 34.57 private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) { 34.58 final boolean isSourceTypeNativeArray = sourceType == NativeArray.class; 34.59 @@ -195,12 +199,14 @@ 34.60 final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null; 34.61 if(targetType.isArray()) { 34.62 return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard); 34.63 - } 34.64 - if(targetType == List.class) { 34.65 - return new GuardedInvocation(JSType.TO_JAVA_LIST.methodHandle(), guard); 34.66 - } 34.67 - if(targetType == Deque.class) { 34.68 - return new GuardedInvocation(JSType.TO_JAVA_DEQUE.methodHandle(), guard); 34.69 + } else if(targetType == List.class) { 34.70 + return new GuardedInvocation(TO_LIST, guard); 34.71 + } else if(targetType == Deque.class) { 34.72 + return new GuardedInvocation(TO_DEQUE, guard); 34.73 + } else if(targetType == Queue.class) { 34.74 + return new GuardedInvocation(TO_QUEUE, guard); 34.75 + } else if(targetType == Collection.class) { 34.76 + return new GuardedInvocation(TO_COLLECTION, guard); 34.77 } 34.78 } 34.79 return null; 34.80 @@ -216,10 +222,11 @@ 34.81 // Could've also used (targetType.isAssignableFrom(ScriptObjectMirror.class) && targetType != Object.class) but 34.82 // it's probably better to explicitly spell out the supported target types 34.83 if (targetType == Map.class || targetType == Bindings.class || targetType == JSObject.class || targetType == ScriptObjectMirror.class) { 34.84 - if(ScriptObject.class.isAssignableFrom(sourceType)) { 34.85 + if (ScriptObject.class.isAssignableFrom(sourceType)) { 34.86 return new GuardedInvocation(CREATE_MIRROR); 34.87 + } else if (sourceType.isAssignableFrom(ScriptObject.class) || sourceType.isInterface()) { 34.88 + return new GuardedInvocation(CREATE_MIRROR, IS_SCRIPT_OBJECT); 34.89 } 34.90 - return new GuardedInvocation(CREATE_MIRROR, IS_SCRIPT_OBJECT); 34.91 } 34.92 return null; 34.93 } 34.94 @@ -285,6 +292,23 @@ 34.95 private static final MethodHandle IS_NASHORN_OR_UNDEFINED_TYPE = findOwnMH("isNashornTypeOrUndefined", Boolean.TYPE, Object.class); 34.96 private static final MethodHandle CREATE_MIRROR = findOwnMH("createMirror", Object.class, Object.class); 34.97 34.98 + private static final MethodHandle TO_COLLECTION; 34.99 + private static final MethodHandle TO_DEQUE; 34.100 + private static final MethodHandle TO_LIST; 34.101 + private static final MethodHandle TO_QUEUE; 34.102 + static { 34.103 + final MethodHandle listAdapterCreate = new Lookup(MethodHandles.lookup()).findStatic( 34.104 + ListAdapter.class, "create", MethodType.methodType(ListAdapter.class, Object.class)); 34.105 + TO_COLLECTION = asReturning(listAdapterCreate, Collection.class); 34.106 + TO_DEQUE = asReturning(listAdapterCreate, Deque.class); 34.107 + TO_LIST = asReturning(listAdapterCreate, List.class); 34.108 + TO_QUEUE = asReturning(listAdapterCreate, Queue.class); 34.109 + } 34.110 + 34.111 + private static MethodHandle asReturning(final MethodHandle mh, final Class<?> nrtype) { 34.112 + return mh.asType(mh.type().changeReturnType(nrtype)); 34.113 + } 34.114 + 34.115 @SuppressWarnings("unused") 34.116 private static boolean isNashornTypeOrUndefined(final Object obj) { 34.117 return obj instanceof ScriptObject || obj instanceof Undefined;
35.1 --- a/src/jdk/nashorn/internal/runtime/options/Options.java Wed May 27 13:20:58 2015 -0700 35.2 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Thu May 28 16:48:12 2015 -0700 35.3 @@ -424,9 +424,17 @@ 35.4 public void process(final String[] args) { 35.5 final LinkedList<String> argList = new LinkedList<>(); 35.6 addSystemProperties(NASHORN_ARGS_PREPEND_PROPERTY, argList); 35.7 + processArgList(argList); 35.8 + assert argList.isEmpty(); 35.9 Collections.addAll(argList, args); 35.10 + processArgList(argList); 35.11 + assert argList.isEmpty(); 35.12 addSystemProperties(NASHORN_ARGS_PROPERTY, argList); 35.13 + processArgList(argList); 35.14 + assert argList.isEmpty(); 35.15 + } 35.16 35.17 + private void processArgList(final LinkedList<String> argList) { 35.18 while (!argList.isEmpty()) { 35.19 final String arg = argList.remove(0); 35.20
36.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Wed May 27 13:20:58 2015 -0700 36.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Thu May 28 16:48:12 2015 -0700 36.3 @@ -121,7 +121,7 @@ 36.4 type.error.cannot.get.default.number=Cannot get default number value 36.5 type.error.cant.apply.with.to.null=Cannot apply "with" to null 36.6 type.error.cant.apply.with.to.undefined=Cannot apply "with" to undefined 36.7 -type.error.cant.apply.with.to.non.scriptobject=Cannot apply "with" to non script object 36.8 +type.error.cant.apply.with.to.non.scriptobject=Cannot apply "with" to non script object. Consider using "with(Object.bindProperties('{'}, nonScriptObject))". 36.9 type.error.in.with.non.object=Right hand side of "in" cannot be non-Object, found {0} 36.10 type.error.prototype.not.an.object="prototype" of {0} is not an Object, it is {1} 36.11 type.error.cant.load.script=Cannot load script from {0}
37.1 --- a/test/script/basic/8024180/with_java_object.js.EXPECTED Wed May 27 13:20:58 2015 -0700 37.2 +++ b/test/script/basic/8024180/with_java_object.js.EXPECTED Thu May 28 16:48:12 2015 -0700 37.3 @@ -1,1 +1,1 @@ 37.4 -TypeError: Cannot apply "with" to non script object 37.5 +TypeError: Cannot apply "with" to non script object. Consider using "with(Object.bindProperties({}, nonScriptObject))".
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/script/basic/JDK-8007456.js Thu May 28 16:48:12 2015 -0700 38.3 @@ -0,0 +1,35 @@ 38.4 +/* 38.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/** 38.28 + * JDK-8007456: Nashorn test framework argument does not handle quoted strings 38.29 + * 38.30 + * @test 38.31 + * @argument "hello world" 38.32 + * @argument "This has spaces" 38.33 + * @run 38.34 + */ 38.35 + 38.36 +print(arguments.length); 38.37 +print(arguments[0]); 38.38 +print(arguments[1]);
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/script/basic/JDK-8007456.js.EXPECTED Thu May 28 16:48:12 2015 -0700 39.3 @@ -0,0 +1,3 @@ 39.4 +2 39.5 +hello world 39.6 +This has spaces
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/script/basic/JDK-8071928.js Thu May 28 16:48:12 2015 -0700 40.3 @@ -0,0 +1,57 @@ 40.4 +/* 40.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/** 40.28 + * JDK-8071928: Instance properties with getters returning wrong values 40.29 + * 40.30 + * @test 40.31 + * @run 40.32 + */ 40.33 + 40.34 + 40.35 +var types = {}; 40.36 + 40.37 +function Type() {} 40.38 + 40.39 +Type.prototype.getName = function() { 40.40 + return this._name; 40.41 +}; 40.42 + 40.43 +function defineType(init) { 40.44 + return Object.create(Type.prototype, { 40.45 + _name: { get: function() { return init.name; } } 40.46 + }); 40.47 +} 40.48 + 40.49 +types.A = defineType({ name: 'A' }); 40.50 +types.B = defineType({ name: 'B' }); 40.51 +types.C = defineType({ name: 'C' }); 40.52 +types.D = defineType({ name: 'D' }); 40.53 + 40.54 +var keys = Object.keys(types); 40.55 +for (var i = 0; i < keys.length; i++) { 40.56 + var t = types[keys[i]]; 40.57 + if (t.getName() != keys[i]) { 40.58 + throw 'wrong name for ' + keys[i] + ': ' + t.getName(); 40.59 + } 40.60 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/test/script/basic/JDK-8073846.js Thu May 28 16:48:12 2015 -0700 41.3 @@ -0,0 +1,54 @@ 41.4 +/* 41.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41.7 + * 41.8 + * This code is free software; you can redistribute it and/or modify it 41.9 + * under the terms of the GNU General Public License version 2 only, as 41.10 + * published by the Free Software Foundation. 41.11 + * 41.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 41.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 41.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 41.15 + * version 2 for more details (a copy is included in the LICENSE file that 41.16 + * accompanied this code). 41.17 + * 41.18 + * You should have received a copy of the GNU General Public License version 41.19 + * 2 along with this work; if not, write to the Free Software Foundation, 41.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 41.21 + * 41.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 41.23 + * or visit www.oracle.com if you need additional information or have any 41.24 + * questions. 41.25 + */ 41.26 + 41.27 +/** 41.28 + * JDK-8073846: Javascript for-in loop returned extra keys 41.29 + * 41.30 + * @test 41.31 + * @run 41.32 + */ 41.33 + 41.34 +var obj = {}; 41.35 + 41.36 +var list = [ 41.37 + '2100000', 41.38 + '420000', 41.39 + '430000' 41.40 +]; 41.41 + 41.42 +for (var i = 0; i < list.length; i++) { 41.43 + if (obj[list[i]]) print("duplicate: " + list[i]); 41.44 + obj[list[i]] = 'obj' + list[i] 41.45 +} 41.46 + 41.47 +var count = 0; 41.48 +for (var a in obj) { 41.49 + count++; 41.50 + if ('obj' + a !== obj[a]) { 41.51 + throw 'wrong key or value: ' + a + ', ' + obj[a]; 41.52 + } 41.53 +} 41.54 + 41.55 +if (count !== 3) { 41.56 + throw 'wrong entry count: ' + count; 41.57 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/script/basic/JDK-8079145.js Thu May 28 16:48:12 2015 -0700 42.3 @@ -0,0 +1,89 @@ 42.4 +/* 42.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42.7 + * 42.8 + * This code is free software; you can redistribute it and/or modify it 42.9 + * under the terms of the GNU General Public License version 2 only, as 42.10 + * published by the Free Software Foundation. 42.11 + * 42.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 42.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 42.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 42.15 + * version 2 for more details (a copy is included in the LICENSE file that 42.16 + * accompanied this code). 42.17 + * 42.18 + * You should have received a copy of the GNU General Public License version 42.19 + * 2 along with this work; if not, write to the Free Software Foundation, 42.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 42.21 + * 42.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 42.23 + * or visit www.oracle.com if you need additional information or have any 42.24 + * questions. 42.25 + */ 42.26 + 42.27 +/** 42.28 + * JDK-8079145: jdk.nashorn.internal.runtime.arrays.IntArrayData.convert assertion 42.29 + * 42.30 + * @test 42.31 + * @fork 42.32 + * @option -Dnashorn.debug=true 42.33 + * @run 42.34 + */ 42.35 + 42.36 +var Byte = java.lang.Byte; 42.37 +var Short = java.lang.Short; 42.38 +var Integer = java.lang.Integer; 42.39 +var Long = java.lang.Long; 42.40 +var Float = java.lang.Float; 42.41 +var Double = java.lang.Double; 42.42 +var Character = java.lang.Character; 42.43 + 42.44 +function checkWiden(arr, value, name) { 42.45 + switch (typeof value) { 42.46 + case 'object': 42.47 + case 'undefined': 42.48 + print(name + ": check widen for " + value); 42.49 + break; 42.50 + default: 42.51 + print(name + ": check widen for " + value + 42.52 + " [" + Debug.getClass(value) + "]"); 42.53 + } 42.54 + 42.55 + arr[0] = value; 42.56 +} 42.57 + 42.58 +function checkIntWiden(value) { 42.59 + checkWiden([34], value, "int array"); 42.60 +} 42.61 + 42.62 +function checkLongWiden(value) { 42.63 + checkWiden([Integer.MAX_VALUE + 1], value, "long array"); 42.64 +} 42.65 + 42.66 +function checkNumberWiden(value) { 42.67 + checkWiden([Math.PI], value, "number array"); 42.68 +} 42.69 + 42.70 +function checkObjectWiden(value) { 42.71 + checkWiden([null], value, "object array"); 42.72 +} 42.73 + 42.74 +var values = [{}, null, undefined, false, true, new Byte(34), 42.75 + new Integer(344454), new Long(454545), new Long(Integer.MAX_VALUE + 1), 42.76 + new Float(34.3), new Double(Math.PI), new Character('s')]; 42.77 + 42.78 +for each (var v in values) { 42.79 + checkIntWiden(v); 42.80 +} 42.81 + 42.82 +for each (var v in values) { 42.83 + checkLongWiden(v); 42.84 +} 42.85 + 42.86 +for each (var v in values) { 42.87 + checkNumberWiden(v); 42.88 +} 42.89 + 42.90 +for each (var v in values) { 42.91 + checkObjectWiden(v); 42.92 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/script/basic/JDK-8079145.js.EXPECTED Thu May 28 16:48:12 2015 -0700 43.3 @@ -0,0 +1,48 @@ 43.4 +int array: check widen for [object Object] 43.5 +int array: check widen for null 43.6 +int array: check widen for undefined 43.7 +int array: check widen for false [class java.lang.Boolean] 43.8 +int array: check widen for true [class java.lang.Boolean] 43.9 +int array: check widen for 34 [class java.lang.Byte] 43.10 +int array: check widen for 344454 [class java.lang.Integer] 43.11 +int array: check widen for 454545 [class java.lang.Long] 43.12 +int array: check widen for 2147483648 [class java.lang.Long] 43.13 +int array: check widen for 34.29999923706055 [class java.lang.Float] 43.14 +int array: check widen for 3.141592653589793 [class java.lang.Double] 43.15 +int array: check widen for s 43.16 +long array: check widen for [object Object] 43.17 +long array: check widen for null 43.18 +long array: check widen for undefined 43.19 +long array: check widen for false [class java.lang.Boolean] 43.20 +long array: check widen for true [class java.lang.Boolean] 43.21 +long array: check widen for 34 [class java.lang.Byte] 43.22 +long array: check widen for 344454 [class java.lang.Integer] 43.23 +long array: check widen for 454545 [class java.lang.Long] 43.24 +long array: check widen for 2147483648 [class java.lang.Long] 43.25 +long array: check widen for 34.29999923706055 [class java.lang.Float] 43.26 +long array: check widen for 3.141592653589793 [class java.lang.Double] 43.27 +long array: check widen for s 43.28 +number array: check widen for [object Object] 43.29 +number array: check widen for null 43.30 +number array: check widen for undefined 43.31 +number array: check widen for false [class java.lang.Boolean] 43.32 +number array: check widen for true [class java.lang.Boolean] 43.33 +number array: check widen for 34 [class java.lang.Byte] 43.34 +number array: check widen for 344454 [class java.lang.Integer] 43.35 +number array: check widen for 454545 [class java.lang.Long] 43.36 +number array: check widen for 2147483648 [class java.lang.Long] 43.37 +number array: check widen for 34.29999923706055 [class java.lang.Float] 43.38 +number array: check widen for 3.141592653589793 [class java.lang.Double] 43.39 +number array: check widen for s 43.40 +object array: check widen for [object Object] 43.41 +object array: check widen for null 43.42 +object array: check widen for undefined 43.43 +object array: check widen for false [class java.lang.Boolean] 43.44 +object array: check widen for true [class java.lang.Boolean] 43.45 +object array: check widen for 34 [class java.lang.Byte] 43.46 +object array: check widen for 344454 [class java.lang.Integer] 43.47 +object array: check widen for 454545 [class java.lang.Long] 43.48 +object array: check widen for 2147483648 [class java.lang.Long] 43.49 +object array: check widen for 34.29999923706055 [class java.lang.Float] 43.50 +object array: check widen for 3.141592653589793 [class java.lang.Double] 43.51 +object array: check widen for s
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/script/basic/JDK-8079424.js Thu May 28 16:48:12 2015 -0700 44.3 @@ -0,0 +1,50 @@ 44.4 +/* 44.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. 44.11 + * 44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.15 + * version 2 for more details (a copy is included in the LICENSE file that 44.16 + * accompanied this code). 44.17 + * 44.18 + * You should have received a copy of the GNU General Public License version 44.19 + * 2 along with this work; if not, write to the Free Software Foundation, 44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.21 + * 44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.23 + * or visit www.oracle.com if you need additional information or have any 44.24 + * questions. 44.25 + */ 44.26 + 44.27 +/** 44.28 + * JDK-8079424: code generator for discarded boolean logical operation has an extra pop 44.29 + * 44.30 + * @test 44.31 + * @run 44.32 + */ 44.33 + 44.34 +// If the compiler manages to compile all of these, the test passes. 44.35 +void (true && true); 44.36 +void (true && false); 44.37 +void (false && true); 44.38 +void (false && false); 44.39 + 44.40 +void (true || true); 44.41 +void (true || false); 44.42 +void (false || true); 44.43 +void (false || false); 44.44 + 44.45 +void (1 && 1); 44.46 +void (1 && 0); 44.47 +void (0 && 1); 44.48 +void (0 && 0); 44.49 + 44.50 +void (1 || 1); 44.51 +void (1 || 0); 44.52 +void (0 || 1); 44.53 +void (0 || 0);
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/script/basic/JDK-8080848.js Thu May 28 16:48:12 2015 -0700 45.3 @@ -0,0 +1,37 @@ 45.4 +/* 45.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 45.7 + * 45.8 + * This code is free software; you can redistribute it and/or modify it 45.9 + * under the terms of the GNU General Public License version 2 only, as 45.10 + * published by the Free Software Foundation. 45.11 + * 45.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 45.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 45.15 + * version 2 for more details (a copy is included in the LICENSE file that 45.16 + * accompanied this code). 45.17 + * 45.18 + * You should have received a copy of the GNU General Public License version 45.19 + * 2 along with this work; if not, write to the Free Software Foundation, 45.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 45.21 + * 45.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 45.23 + * or visit www.oracle.com if you need additional information or have any 45.24 + * questions. 45.25 + */ 45.26 + 45.27 +/** 45.28 + * JDK-8080848: delete of bound Java method property results in crash 45.29 + * 45.30 + * @test 45.31 + * @run 45.32 + */ 45.33 + 45.34 +var obj = Object.bindProperties({}, new java.io.File(".")); 45.35 + 45.36 +delete obj.wait; 45.37 + 45.38 +if (typeof obj.wait != 'undefined') { 45.39 + throw new Error("obj.wait was not deleted"); 45.40 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/script/basic/JDK-8081156.js Thu May 28 16:48:12 2015 -0700 46.3 @@ -0,0 +1,46 @@ 46.4 +/* 46.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 + * 46.8 + * This code is free software; you can redistribute it and/or modify it 46.9 + * under the terms of the GNU General Public License version 2 only, as 46.10 + * published by the Free Software Foundation. 46.11 + * 46.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 46.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.15 + * version 2 for more details (a copy is included in the LICENSE file that 46.16 + * accompanied this code). 46.17 + * 46.18 + * You should have received a copy of the GNU General Public License version 46.19 + * 2 along with this work; if not, write to the Free Software Foundation, 46.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.21 + * 46.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.23 + * or visit www.oracle.com if you need additional information or have any 46.24 + * questions. 46.25 + */ 46.26 + 46.27 +/** 46.28 + * JDK-8081156: jjs "nashorn.args" system property is not effective when script arguments are passed 46.29 + * 46.30 + * @test 46.31 + * @fork 46.32 + * @option -Dnashorn.args=-strict 46.33 + * @argument foo 46.34 + * @argument bar 46.35 + * @run 46.36 + */ 46.37 + 46.38 +try { 46.39 + x = 14; 46.40 + throw new Error("should have thrown ReferenceError"); 46.41 +} catch (e) { 46.42 + if (! (e instanceof ReferenceError)) { 46.43 + throw e; 46.44 + } 46.45 +} 46.46 + 46.47 +Assert.assertTrue(arguments.length == 2); 46.48 +Assert.assertTrue(arguments[0] == "foo"); 46.49 +Assert.assertTrue(arguments[1] == "bar");
47.1 --- a/test/script/nosecurity/JDK-8050964.js Wed May 27 13:20:58 2015 -0700 47.2 +++ b/test/script/nosecurity/JDK-8050964.js Thu May 28 16:48:12 2015 -0700 47.3 @@ -47,7 +47,7 @@ 47.4 } 47.5 47.6 var javahome = System.getProperty("java.home"); 47.7 -var jdepsPath = javahome + "/../bin/jdeps".replaceAll(/\//g, File.separater); 47.8 +var jdepsPath = javahome + "/../bin/jdeps".replace(/\//g, File.separator); 47.9 47.10 // run jdep on nashorn.jar - only summary but print profile info 47.11 $ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin
48.1 --- a/test/script/nosecurity/JDK-8055034.js Wed May 27 13:20:58 2015 -0700 48.2 +++ b/test/script/nosecurity/JDK-8055034.js Thu May 28 16:48:12 2015 -0700 48.3 @@ -48,7 +48,7 @@ 48.4 // we want to use nashorn.jar passed and not the one that comes with JRE 48.5 var jjsCmd = javahome + "/../bin/jjs"; 48.6 jjsCmd += " -J-Djava.ext.dirs=" + nashornJarDir; 48.7 -jjsCmd = jjsCmd.toString().replaceAll(/\//g, File.separater); 48.8 +jjsCmd = jjsCmd.toString().replace(/\//g, File.separator); 48.9 $ENV.PWD=System.getProperty("user.dir") // to avoid RE on Cygwin 48.10 $EXEC(jjsCmd, "var x = Object.create(null);\nx;\nprint('PASSED');\nexit(0)"); 48.11
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/src/jdk/nashorn/internal/runtime/test/JDK_8078414_Test.java Thu May 28 16:48:12 2015 -0700 49.3 @@ -0,0 +1,99 @@ 49.4 +/* 49.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. Oracle designates this 49.11 + * particular file as subject to the "Classpath" exception as provided 49.12 + * by Oracle in the LICENSE file that accompanied this code. 49.13 + * 49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.17 + * version 2 for more details (a copy is included in the LICENSE file that 49.18 + * accompanied this code). 49.19 + * 49.20 + * You should have received a copy of the GNU General Public License version 49.21 + * 2 along with this work; if not, write to the Free Software Foundation, 49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.23 + * 49.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.25 + * or visit www.oracle.com if you need additional information or have any 49.26 + * questions. 49.27 + */ 49.28 + 49.29 +package jdk.nashorn.internal.runtime.test; 49.30 + 49.31 +import static org.testng.Assert.assertFalse; 49.32 +import static org.testng.Assert.assertTrue; 49.33 + 49.34 +import java.util.Map; 49.35 +import javax.script.Bindings; 49.36 +import jdk.nashorn.api.scripting.JSObject; 49.37 +import jdk.nashorn.api.scripting.ScriptObjectMirror; 49.38 +import jdk.nashorn.internal.objects.NativeArray; 49.39 +import jdk.nashorn.internal.runtime.ScriptObject; 49.40 +import jdk.nashorn.internal.runtime.linker.Bootstrap; 49.41 +import org.testng.annotations.Test; 49.42 + 49.43 +/** 49.44 + * @test 49.45 + * @bug 8078414 49.46 + * @summary Test that arbitrary classes can't be converted to mirror's superclasses/interfaces. 49.47 + * @run testng jdk.nashorn.internal.runtime.test.JDK_8078414_Test 49.48 + */ 49.49 +public class JDK_8078414_Test { 49.50 + @Test 49.51 + public void testCanNotConvertArbitraryClassToMirror() { 49.52 + assertCanNotConvert(Double.class, Map.class); 49.53 + assertCanNotConvert(Double.class, Bindings.class); 49.54 + assertCanNotConvert(Double.class, JSObject.class); 49.55 + assertCanNotConvert(Double.class, ScriptObjectMirror.class); 49.56 + } 49.57 + 49.58 + @Test 49.59 + public void testCanConvertObjectToMirror() { 49.60 + assertCanConvertToMirror(Object.class); 49.61 + } 49.62 + 49.63 + @Test 49.64 + public void testCanConvertScriptObjectToMirror() { 49.65 + assertCanConvertToMirror(ScriptObject.class); 49.66 + } 49.67 + 49.68 + @Test 49.69 + public void testCanConvertScriptObjectSubclassToMirror() { 49.70 + assertCanConvertToMirror(NativeArray.class); 49.71 + } 49.72 + 49.73 + @Test 49.74 + public void testCanConvertArbitraryInterfaceToMirror() { 49.75 + // We allow arbitrary interface classes, depending on what implements them, to end up being 49.76 + // convertible to ScriptObjectMirror, as an implementation can theoretically pass an 49.77 + // "instanceof ScriptObject" guard. 49.78 + assertCanConvertToMirror(TestInterface.class); 49.79 + } 49.80 + 49.81 + public static interface TestInterface { 49.82 + } 49.83 + 49.84 + private static boolean canConvert(final Class<?> from, final Class<?> to) { 49.85 + return Bootstrap.getLinkerServices().canConvert(from, to); 49.86 + } 49.87 + 49.88 + private static void assertCanConvert(final Class<?> from, final Class<?> to) { 49.89 + assertTrue(canConvert(from, to)); 49.90 + } 49.91 + 49.92 + private static void assertCanNotConvert(final Class<?> from, final Class<?> to) { 49.93 + assertFalse(canConvert(from, to)); 49.94 + } 49.95 + 49.96 + private static void assertCanConvertToMirror(final Class<?> from) { 49.97 + assertCanConvert(from, Map.class); 49.98 + assertCanConvert(from, Bindings.class); 49.99 + assertCanConvert(from, JSObject.class); 49.100 + assertCanConvert(from, ScriptObjectMirror.class); 49.101 + } 49.102 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/src/jdk/nashorn/internal/runtime/test/JDK_8081015_Test.java Thu May 28 16:48:12 2015 -0700 50.3 @@ -0,0 +1,74 @@ 50.4 +/* 50.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. Oracle designates this 50.11 + * particular file as subject to the "Classpath" exception as provided 50.12 + * by Oracle in the LICENSE file that accompanied this code. 50.13 + * 50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.17 + * version 2 for more details (a copy is included in the LICENSE file that 50.18 + * accompanied this code). 50.19 + * 50.20 + * You should have received a copy of the GNU General Public License version 50.21 + * 2 along with this work; if not, write to the Free Software Foundation, 50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.23 + * 50.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.25 + * or visit www.oracle.com if you need additional information or have any 50.26 + * questions. 50.27 + */ 50.28 + 50.29 +package jdk.nashorn.internal.runtime.test; 50.30 + 50.31 +import static org.testng.Assert.assertEquals; 50.32 +import static org.testng.Assert.assertNull; 50.33 + 50.34 +import java.util.Collection; 50.35 +import java.util.Queue; 50.36 +import javax.script.ScriptEngine; 50.37 +import javax.script.ScriptException; 50.38 +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; 50.39 +import jdk.nashorn.test.models.JDK_8081015_TestModel; 50.40 +import org.testng.annotations.Test; 50.41 + 50.42 +/** 50.43 + * @bug 8081015 50.44 + * @summary Test that native arrays get converted to {@link Queue} and {@link Collection}. 50.45 + */ 50.46 +@SuppressWarnings("javadoc") 50.47 +public class JDK_8081015_Test { 50.48 + @Test 50.49 + public void testConvertToCollection() throws ScriptException { 50.50 + test("receiveCollection"); 50.51 + } 50.52 + 50.53 + @Test 50.54 + public void testConvertToDeque() throws ScriptException { 50.55 + test("receiveDeque"); 50.56 + } 50.57 + 50.58 + @Test 50.59 + public void testConvertToList() throws ScriptException { 50.60 + test("receiveList"); 50.61 + } 50.62 + 50.63 + @Test 50.64 + public void testConvertToQueue() throws ScriptException { 50.65 + test("receiveQueue"); 50.66 + } 50.67 + 50.68 + private static void test(final String methodName) throws ScriptException { 50.69 + final ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine(); 50.70 + final JDK_8081015_TestModel model = new JDK_8081015_TestModel(); 50.71 + engine.put("test", model); 50.72 + 50.73 + assertNull(model.getLastInvoked()); 50.74 + engine.eval("test." + methodName + "([1, 2, 3.3, 'foo'])"); 50.75 + assertEquals(model.getLastInvoked(), methodName ); 50.76 + } 50.77 +}
51.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Wed May 27 13:20:58 2015 -0700 51.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java Thu May 28 16:48:12 2015 -0700 51.3 @@ -22,7 +22,6 @@ 51.4 * or visit www.oracle.com if you need additional information or have any 51.5 * questions. 51.6 */ 51.7 - 51.8 package jdk.nashorn.internal.test.framework; 51.9 51.10 import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_CHECK_COMPILE_MSG; 51.11 @@ -61,14 +60,15 @@ 51.12 import java.util.EnumSet; 51.13 import java.util.HashMap; 51.14 import java.util.HashSet; 51.15 +import java.util.Iterator; 51.16 import java.util.List; 51.17 import java.util.Map; 51.18 -import java.util.Scanner; 51.19 import java.util.Set; 51.20 import javax.xml.xpath.XPath; 51.21 import javax.xml.xpath.XPathConstants; 51.22 import javax.xml.xpath.XPathExpressionException; 51.23 import javax.xml.xpath.XPathFactory; 51.24 +import jdk.nashorn.internal.runtime.ScriptingFunctions; 51.25 import org.w3c.dom.NodeList; 51.26 import org.xml.sax.InputSource; 51.27 51.28 @@ -78,28 +78,33 @@ 51.29 */ 51.30 @SuppressWarnings("javadoc") 51.31 public final class TestFinder { 51.32 - private TestFinder() {} 51.33 + 51.34 + private TestFinder() { 51.35 + } 51.36 51.37 interface TestFactory<T> { 51.38 + 51.39 // 'test' instance type is decided by the client. 51.40 + 51.41 T createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> arguments); 51.42 + 51.43 // place to log messages from TestFinder 51.44 + 51.45 void log(String mg); 51.46 } 51.47 51.48 - 51.49 // finds all tests from configuration and calls TestFactory to create 'test' instance for each script test found 51.50 static <T> void findAllTests(final List<T> tests, final Set<String> orphans, final TestFactory<T> testFactory) throws Exception { 51.51 final String framework = System.getProperty(TEST_JS_FRAMEWORK); 51.52 final String testList = System.getProperty(TEST_JS_LIST); 51.53 final String failedTestFileName = System.getProperty(TEST_FAILED_LIST_FILE); 51.54 - if(failedTestFileName != null) { 51.55 + if (failedTestFileName != null) { 51.56 final File failedTestFile = new File(failedTestFileName); 51.57 - if(failedTestFile.exists() && failedTestFile.length() > 0L) { 51.58 - try(final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) { 51.59 - for(;;) { 51.60 + if (failedTestFile.exists() && failedTestFile.length() > 0L) { 51.61 + try (final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) { 51.62 + for (;;) { 51.63 final String testFileName = r.readLine(); 51.64 - if(testFileName == null) { 51.65 + if (testFileName == null) { 51.66 break; 51.67 } 51.68 handleOneTest(framework, new File(testFileName).toPath(), tests, orphans, testFactory); 51.69 @@ -151,7 +156,7 @@ 51.70 final Exception[] exceptions = new Exception[1]; 51.71 final List<String> excludedActualTests = new ArrayList<>(); 51.72 51.73 - if (! dir.toFile().isDirectory()) { 51.74 + if (!dir.toFile().isDirectory()) { 51.75 factory.log("WARNING: " + dir + " not found or not a directory"); 51.76 } 51.77 51.78 @@ -219,27 +224,28 @@ 51.79 51.80 boolean explicitOptimistic = false; 51.81 51.82 - try (Scanner scanner = new Scanner(testFile)) { 51.83 - while (scanner.hasNext()) { 51.84 - // TODO: Scan for /ref=file qualifiers, etc, to determine run 51.85 - // behavior 51.86 - String token = scanner.next(); 51.87 - if (token.startsWith("/*")) { 51.88 - inComment = true; 51.89 - } else if (token.endsWith(("*/"))) { 51.90 - inComment = false; 51.91 - } else if (!inComment) { 51.92 - continue; 51.93 - } 51.94 + String allContent = new String(Files.readAllBytes(testFile)); 51.95 + Iterator<String> scanner = ScriptingFunctions.tokenizeCommandLine(allContent).iterator(); 51.96 + while (scanner.hasNext()) { 51.97 + // TODO: Scan for /ref=file qualifiers, etc, to determine run 51.98 + // behavior 51.99 + String token = scanner.next(); 51.100 + if (token.startsWith("/*")) { 51.101 + inComment = true; 51.102 + } else if (token.endsWith(("*/"))) { 51.103 + inComment = false; 51.104 + } else if (!inComment) { 51.105 + continue; 51.106 + } 51.107 51.108 - // remove whitespace and trailing semicolons, if any 51.109 - // (trailing semicolons are found in some sputnik tests) 51.110 - token = token.trim(); 51.111 - final int semicolon = token.indexOf(';'); 51.112 - if (semicolon > 0) { 51.113 - token = token.substring(0, semicolon); 51.114 - } 51.115 - switch (token) { 51.116 + // remove whitespace and trailing semicolons, if any 51.117 + // (trailing semicolons are found in some sputnik tests) 51.118 + token = token.trim(); 51.119 + final int semicolon = token.indexOf(';'); 51.120 + if (semicolon > 0) { 51.121 + token = token.substring(0, semicolon); 51.122 + } 51.123 + switch (token) { 51.124 case "@test": 51.125 isTest = true; 51.126 break; 51.127 @@ -308,24 +314,21 @@ 51.128 break; 51.129 default: 51.130 break; 51.131 - } 51.132 + } 51.133 51.134 - // negative tests are expected to fail at runtime only 51.135 - // for those tests that are expected to fail at compile time, 51.136 - // add @test/compile-error 51.137 - if (token.equals("@negative") || token.equals("@strict_mode_negative")) { 51.138 - shouldRun = true; 51.139 - runFailure = true; 51.140 - } 51.141 + // negative tests are expected to fail at runtime only 51.142 + // for those tests that are expected to fail at compile time, 51.143 + // add @test/compile-error 51.144 + if (token.equals("@negative") || token.equals("@strict_mode_negative")) { 51.145 + shouldRun = true; 51.146 + runFailure = true; 51.147 + } 51.148 51.149 - if (token.equals("@strict_mode") || token.equals("@strict_mode_negative") || token.equals("@onlyStrict") || token.equals("@noStrict")) { 51.150 - if (!strictModeEnabled()) { 51.151 - return; 51.152 - } 51.153 + if (token.equals("@strict_mode") || token.equals("@strict_mode_negative") || token.equals("@onlyStrict") || token.equals("@noStrict")) { 51.154 + if (!strictModeEnabled()) { 51.155 + return; 51.156 } 51.157 } 51.158 - } catch (final Exception ignored) { 51.159 - return; 51.160 } 51.161 51.162 if (isTest) { 51.163 @@ -369,8 +372,8 @@ 51.164 private static final boolean OPTIMISTIC_OVERRIDE = true; 51.165 51.166 /** 51.167 - * Check if there is an optimistic override, that disables the default 51.168 - * false optimistic types and sets them to true, for testing purposes 51.169 + * Check if there is an optimistic override, that disables the default false 51.170 + * optimistic types and sets them to true, for testing purposes 51.171 * 51.172 * @return true if optimistic type override has been set by test suite 51.173 */ 51.174 @@ -379,10 +382,9 @@ 51.175 } 51.176 51.177 /** 51.178 - * Add an optimistic-types=true option to an argument list if this 51.179 - * is set to override the default false. Add an optimistic-types=true 51.180 - * options to an argument list if this is set to override the default 51.181 - * true 51.182 + * Add an optimistic-types=true option to an argument list if this is set to 51.183 + * override the default false. Add an optimistic-types=true options to an 51.184 + * argument list if this is set to override the default true 51.185 * 51.186 * @args new argument list array 51.187 */ 51.188 @@ -396,8 +398,8 @@ 51.189 } 51.190 51.191 /** 51.192 - * Add an optimistic-types=true option to an argument list if this 51.193 - * is set to override the default false 51.194 + * Add an optimistic-types=true option to an argument list if this is set to 51.195 + * override the default false 51.196 * 51.197 * @args argument list 51.198 */ 51.199 @@ -438,7 +440,7 @@ 51.200 51.201 private static void loadExcludesFile(final String testExcludesFile, final Set<String> testExcludeSet) throws XPathExpressionException { 51.202 final XPath xpath = XPathFactory.newInstance().newXPath(); 51.203 - final NodeList testIds = (NodeList)xpath.evaluate("/excludeList/test/@id", new InputSource(testExcludesFile), XPathConstants.NODESET); 51.204 + final NodeList testIds = (NodeList) xpath.evaluate("/excludeList/test/@id", new InputSource(testExcludesFile), XPathConstants.NODESET); 51.205 for (int i = testIds.getLength() - 1; i >= 0; i--) { 51.206 testExcludeSet.add(testIds.item(i).getNodeValue()); 51.207 }
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/test/src/jdk/nashorn/test/models/JDK_8081015_TestModel.java Thu May 28 16:48:12 2015 -0700 52.3 @@ -0,0 +1,73 @@ 52.4 +/* 52.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 + * 52.8 + * This code is free software; you can redistribute it and/or modify it 52.9 + * under the terms of the GNU General Public License version 2 only, as 52.10 + * published by the Free Software Foundation. Oracle designates this 52.11 + * particular file as subject to the "Classpath" exception as provided 52.12 + * by Oracle in the LICENSE file that accompanied this code. 52.13 + * 52.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 52.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.17 + * version 2 for more details (a copy is included in the LICENSE file that 52.18 + * accompanied this code). 52.19 + * 52.20 + * You should have received a copy of the GNU General Public License version 52.21 + * 2 along with this work; if not, write to the Free Software Foundation, 52.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.23 + * 52.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.25 + * or visit www.oracle.com if you need additional information or have any 52.26 + * questions. 52.27 + */ 52.28 + 52.29 +package jdk.nashorn.test.models; 52.30 + 52.31 +import static org.testng.Assert.assertEquals; 52.32 +import static org.testng.Assert.assertFalse; 52.33 + 52.34 +import java.util.Collection; 52.35 +import java.util.Deque; 52.36 +import java.util.Iterator; 52.37 +import java.util.List; 52.38 +import java.util.Queue; 52.39 + 52.40 +@SuppressWarnings("javadoc") 52.41 +public class JDK_8081015_TestModel { 52.42 + private String lastInvoked; 52.43 + 52.44 + public void receiveCollection(final Collection<Object> c) { 52.45 + lastInvoked = "receiveCollection"; 52.46 + walkCollection(c); 52.47 + } 52.48 + 52.49 + public void receiveDeque(final Deque<Object> d) { 52.50 + lastInvoked = "receiveDeque"; 52.51 + walkCollection(d); 52.52 + } 52.53 + 52.54 + public void receiveList(final List<Object> l) { 52.55 + lastInvoked = "receiveList"; 52.56 + walkCollection(l); 52.57 + } 52.58 + 52.59 + public void receiveQueue(final Queue<Object> q) { 52.60 + lastInvoked = "receiveQueue"; 52.61 + walkCollection(q); 52.62 + } 52.63 + 52.64 + public String getLastInvoked() { 52.65 + return lastInvoked; 52.66 + } 52.67 + 52.68 + private static void walkCollection(final Collection<Object> c) { 52.69 + final Iterator<Object> it = c.iterator(); 52.70 + assertEquals(it.next(), Integer.valueOf(1)); 52.71 + assertEquals(it.next(), Integer.valueOf(2)); 52.72 + assertEquals(it.next(), Double.valueOf(3.3)); 52.73 + assertEquals(it.next(), "foo"); 52.74 + assertFalse(it.hasNext()); 52.75 + } 52.76 +}