test/script/trusted/JDK-8021129.js

Fri, 06 Sep 2019 03:21:30 +0100

author
andrew
date
Fri, 06 Sep 2019 03:21:30 +0100
changeset 2516
ad8af81cc28b
parent 962
ac62e33a99b0
child 1205
4112748288bb
permissions
-rw-r--r--

Added tag jdk8u242-b00 for changeset 8a951fd037e2

attila@463 1 /*
attila@463 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
attila@463 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
attila@463 5 * This code is free software; you can redistribute it and/or modify it
attila@463 6 * under the terms of the GNU General Public License version 2 only, as
attila@463 7 * published by the Free Software Foundation.
attila@962 8 *
attila@463 9 * This code is distributed in the hope that it will be useful, but WITHOUT
attila@463 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
attila@463 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
attila@463 12 * version 2 for more details (a copy is included in the LICENSE file that
attila@463 13 * accompanied this code).
attila@962 14 *
attila@463 15 * You should have received a copy of the GNU General Public License version
attila@463 16 * 2 along with this work; if not, write to the Free Software Foundation,
attila@463 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
attila@463 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
attila@463 20 * or visit www.oracle.com if you need additional information or have any
attila@463 21 * questions.
attila@463 22 */
attila@463 23
attila@463 24 /**
attila@463 25 * JDK-8021129: Test prevention of access to members of restricted classes.
attila@463 26 * Note that even though the script runs as trusted, we still don't allow
attila@463 27 * access to non-public portions of restricted classes.
attila@962 28 *
attila@463 29 * @test
attila@463 30 * @run
attila@463 31 */
attila@464 32
sundar@468 33 var InternalRunnableSuperclass = Java.type("jdk.nashorn.test.models.InternalRunnableSuperclass");
sundar@468 34 var r1 = InternalRunnableSuperclass.makeInternalRunnable();
attila@463 35 r1.run() // Can execute method from an implemented non-restricted interface
attila@463 36 print(r1.toString()) // Can execute public method from a superclass
attila@463 37
attila@463 38 print(r1.restrictedRun === undefined) // Can't see method from a restricted interface
attila@463 39 print(r1.canNotInvokeThis === undefined) // Can't see any other public methods
attila@463 40 print(r1.invisibleProperty === undefined) // Can't see any other properties
attila@463 41 print(r1.canSeeThisField === undefined) // Can't see fields from superclasses
attila@463 42 print(r1.canNotSeeThisField === undefined) // Can't see its own fields
attila@463 43
sundar@468 44 var r2 = new InternalRunnableSuperclass();
attila@464 45 print(r2.canSeeThisField) // Superclass field works fine on its own

mercurial