Thu, 10 Oct 2013 13:17:57 +0200
8026248: importClass has to be a varargs function
Reviewed-by: jlaskey, hannesw
1.1 --- a/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js Thu Oct 10 11:48:56 2013 +0200 1.2 +++ b/src/jdk/nashorn/internal/runtime/resources/mozilla_compat.js Thu Oct 10 13:17:57 2013 +0200 1.3 @@ -41,7 +41,12 @@ 1.4 } 1.5 }); 1.6 1.7 + 1.8 // importPackage 1.9 +// avoid unnecessary chaining of __noSuchProperty__ again 1.10 +// in case user loads this script more than once. 1.11 +if (typeof importPackage == 'undefined') { 1.12 + 1.13 Object.defineProperty(this, "importPackage", { 1.14 configurable: true, enumerable: false, writable: true, 1.15 value: (function() { 1.16 @@ -91,6 +96,8 @@ 1.17 })() 1.18 }); 1.19 1.20 +} 1.21 + 1.22 // Object.prototype.__defineGetter__ 1.23 Object.defineProperty(Object.prototype, "__defineGetter__", { 1.24 configurable: true, enumerable: false, writable: true, 1.25 @@ -344,13 +351,16 @@ 1.26 // Rhino: global.importClass 1.27 Object.defineProperty(this, "importClass", { 1.28 configurable: true, enumerable: false, writable: true, 1.29 - value: function(clazz) { 1.30 - if (Java.isType(clazz)) { 1.31 - var className = Java.typeName(clazz); 1.32 - var simpleName = className.substring(className.lastIndexOf('.') + 1); 1.33 - this[simpleName] = clazz; 1.34 - } else { 1.35 - throw new TypeError(clazz + " is not a Java class"); 1.36 + value: function() { 1.37 + for (var arg in arguments) { 1.38 + var clazz = arguments[arg]; 1.39 + if (Java.isType(clazz)) { 1.40 + var className = Java.typeName(clazz); 1.41 + var simpleName = className.substring(className.lastIndexOf('.') + 1); 1.42 + this[simpleName] = clazz; 1.43 + } else { 1.44 + throw new TypeError(clazz + " is not a Java class"); 1.45 + } 1.46 } 1.47 } 1.48 });
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/basic/JDK-8026248.js Thu Oct 10 13:17:57 2013 +0200 2.3 @@ -0,0 +1,51 @@ 2.4 +/* 2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * JDK-8026248: importClass has to be a varargs function 2.29 + * 2.30 + * @test 2.31 + * @run 2.32 + */ 2.33 + 2.34 +load('nashorn:mozilla_compat.js') 2.35 + 2.36 +importClass(java.io.File, java.io.InputStream) 2.37 + 2.38 +print(File) 2.39 +print(InputStream) 2.40 + 2.41 +importClass(java.util.Map, java.util.HashMap, java.io.PrintStream) 2.42 + 2.43 +print(HashMap) 2.44 +print(Map) 2.45 +print(PrintStream) 2.46 + 2.47 +importClass.call(this, java.util.Collections, java.util.List); 2.48 +print(Collections) 2.49 +print(List) 2.50 + 2.51 +importClass.apply(this, [ java.util.Queue, java.math.BigInteger, java.math.BigDecimal ]); 2.52 +print(Queue) 2.53 +print(BigInteger) 2.54 +print(BigDecimal)
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/basic/JDK-8026248.js.EXPECTED Thu Oct 10 13:17:57 2013 +0200 3.3 @@ -0,0 +1,10 @@ 3.4 +[JavaClass java.io.File] 3.5 +[JavaClass java.io.InputStream] 3.6 +[JavaClass java.util.HashMap] 3.7 +[JavaClass java.util.Map] 3.8 +[JavaClass java.io.PrintStream] 3.9 +[JavaClass java.util.Collections] 3.10 +[JavaClass java.util.List] 3.11 +[JavaClass java.util.Queue] 3.12 +[JavaClass java.math.BigInteger] 3.13 +[JavaClass java.math.BigDecimal]