test/script/basic/JDK-8158467.js

Fri, 10 Mar 2017 18:30:39 +0100

author
hannesw
date
Fri, 10 Mar 2017 18:30:39 +0100
changeset 2023
1786ff57788b
parent 1837
27842bf384fe
permissions
-rw-r--r--

8176511: JSObject property access is broken for numeric keys outside the int range
Reviewed-by: sundar

sundar@1837 1 /*
sundar@1837 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
sundar@1837 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sundar@1837 4 *
sundar@1837 5 * This code is free software; you can redistribute it and/or modify it
sundar@1837 6 * under the terms of the GNU General Public License version 2 only, as
sundar@1837 7 * published by the Free Software Foundation.
sundar@1837 8 *
sundar@1837 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sundar@1837 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sundar@1837 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sundar@1837 12 * version 2 for more details (a copy is included in the LICENSE file that
sundar@1837 13 * accompanied this code).
sundar@1837 14 *
sundar@1837 15 * You should have received a copy of the GNU General Public License version
sundar@1837 16 * 2 along with this work; if not, write to the Free Software Foundation,
sundar@1837 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sundar@1837 18 *
sundar@1837 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sundar@1837 20 * or visit www.oracle.com if you need additional information or have any
sundar@1837 21 * questions.
sundar@1837 22 */
sundar@1837 23
sundar@1837 24 /**
sundar@1837 25 * JDK-8158467: AccessControlException is thrown on public Java class access if "script app loader" is set to null
sundar@1837 26 *
sundar@1837 27 * @option -scripting
sundar@1837 28 * @test
sundar@1837 29 * @run
sundar@1837 30 */
sundar@1837 31
sundar@1837 32 var Factory = Java.type("jdk.nashorn.api.scripting.NashornScriptEngineFactory");
sundar@1837 33 var fac = new Factory();
sundar@1837 34
sundar@1837 35 // This script has to be given RuntimePermission("nashorn.setConfig")
sundar@1837 36 var e = fac["getScriptEngine(java.lang.ClassLoader)"](null);
sundar@1837 37
sundar@1837 38 print(e.eval("java.lang.System"));
sundar@1837 39 print(e.eval("({ foo: 42})").foo);
sundar@1837 40 print((e.eval("function(x) x*x"))(31));
sundar@1837 41
sundar@1837 42 e.put("output", print);
sundar@1837 43 var runnable = e.eval(<<EOF
sundar@1837 44 new java.lang.Runnable() {
sundar@1837 45 run: function() {
sundar@1837 46 output("hello Runnable");
sundar@1837 47 }
sundar@1837 48 }
sundar@1837 49 EOF);
sundar@1837 50
sundar@1837 51 runnable.run();
sundar@1837 52
sundar@1837 53 var obj = e.eval(<<EOF
sundar@1837 54 new (Java.extend(Java.type("java.lang.Object"))) {
sundar@1837 55 hashCode: function() 33,
sundar@1837 56 toString: function() "I'm object"
sundar@1837 57 }
sundar@1837 58 EOF);
sundar@1837 59
sundar@1837 60 print(obj.hashCode());
sundar@1837 61 print(obj.toString());
sundar@1837 62
sundar@1837 63 // should throw SecurityException!
sundar@1837 64 try {
sundar@1837 65 e.eval("Packages.jdk.internal");
sundar@1837 66 } catch (ex) {
sundar@1837 67 print(ex);
sundar@1837 68 }
sundar@1837 69
sundar@1837 70 // should throw SecurityException!
sundar@1837 71 try {
sundar@1837 72 e.eval("Java.type('jdk.internal.misc.Unsafe')");
sundar@1837 73 } catch (ex) {
sundar@1837 74 print(ex);
sundar@1837 75 }
sundar@1837 76
sundar@1837 77 // should throw SecurityException!
sundar@1837 78 try {
sundar@1837 79 e.eval("Java.type('jdk.nashorn.internal.Context')");
sundar@1837 80 } catch (ex) {
sundar@1837 81 print(ex);
sundar@1837 82 }
sundar@1837 83
sundar@1837 84 // should throw ClassNotFoundException as null is script
sundar@1837 85 // "app loader" [and not platform loader which loads nashorn]
sundar@1837 86 e.eval(<<EOF
sundar@1837 87 try {
sundar@1837 88 Java.type('jdk.nashorn.api.scripting.JSObject');
sundar@1837 89 } catch (ex) {
sundar@1837 90 output(ex);
sundar@1837 91 }
sundar@1837 92 EOF);

mercurial