test/script/trusted/JDK-8021129.js

Wed, 24 Jul 2013 11:13:24 +0200

author
attila
date
Wed, 24 Jul 2013 11:13:24 +0200
changeset 464
a58a07a00122
parent 463
8b97fe2b7c98
child 468
dc54df348a58
permissions
-rw-r--r--

8021189: Prevent access to constructors of restricted classes
Reviewed-by: lagergren, sundar

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@463 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@463 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@463 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@463 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@463 28 *
attila@463 29 * @test
attila@463 30 * @run
attila@463 31 */
attila@464 32 var R = Java.type("jdk.nashorn.internal.test.models.InternalRunnable")
attila@464 33 var r1 = R.class.newInstance()
attila@464 34
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
attila@463 44 var r2 = new (Java.type("jdk.nashorn.test.models.InternalRunnableSuperclass"))
attila@464 45 print(r2.canSeeThisField) // Superclass field works fine on its own

mercurial