Tue, 12 Mar 2013 18:12:42 +0530
8009757: Package access clean up and refactoring
Reviewed-by: jlaskey, lagergren, attila
jlaskey@3 | 1 | /* |
jlaskey@7 | 2 | * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
jlaskey@3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlaskey@3 | 4 | * |
jlaskey@3 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlaskey@3 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlaskey@3 | 7 | * published by the Free Software Foundation. Oracle designates this |
jlaskey@3 | 8 | * particular file as subject to the "Classpath" exception as provided |
jlaskey@3 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jlaskey@3 | 10 | * |
jlaskey@3 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlaskey@3 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlaskey@3 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlaskey@3 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jlaskey@3 | 15 | * accompanied this code). |
jlaskey@3 | 16 | * |
jlaskey@3 | 17 | * You should have received a copy of the GNU General Public License version |
jlaskey@3 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlaskey@3 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlaskey@3 | 20 | * |
jlaskey@3 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlaskey@3 | 22 | * or visit www.oracle.com if you need additional information or have any |
jlaskey@3 | 23 | * questions. |
jlaskey@3 | 24 | */ |
jlaskey@3 | 25 | |
jlaskey@3 | 26 | package jdk.nashorn.internal.runtime; |
jlaskey@3 | 27 | |
jlaskey@3 | 28 | import java.security.CodeSource; |
sundar@136 | 29 | import java.security.ProtectionDomain; |
jlaskey@3 | 30 | |
jlaskey@3 | 31 | /** |
sundar@82 | 32 | * Responsible for loading script generated classes. |
jlaskey@3 | 33 | * |
jlaskey@3 | 34 | */ |
jlaskey@3 | 35 | final class ScriptLoader extends NashornLoader { |
jlaskey@3 | 36 | /** |
jlaskey@3 | 37 | * Constructor. |
jlaskey@3 | 38 | */ |
sundar@82 | 39 | ScriptLoader(final StructureLoader parent, final Context context) { |
jlaskey@3 | 40 | super(parent, context); |
jlaskey@3 | 41 | } |
jlaskey@3 | 42 | |
attila@90 | 43 | @Override |
attila@90 | 44 | protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { |
attila@90 | 45 | checkPackageAccess(name); |
attila@90 | 46 | return super.loadClassTrusted(name, resolve); |
attila@90 | 47 | } |
attila@90 | 48 | |
jlaskey@3 | 49 | // package-private and private stuff below this point |
jlaskey@3 | 50 | |
jlaskey@3 | 51 | /** |
jlaskey@3 | 52 | * Install a class for use by the Nashorn runtime |
jlaskey@3 | 53 | * |
jlaskey@3 | 54 | * @param name Binary name of class. |
jlaskey@3 | 55 | * @param data Class data bytes. |
jlaskey@3 | 56 | * @param cs CodeSource code source of the class bytes. |
jlaskey@3 | 57 | * |
jlaskey@3 | 58 | * @return Installed class. |
jlaskey@3 | 59 | */ |
jlaskey@3 | 60 | synchronized Class<?> installClass(final String name, final byte[] data, final CodeSource cs) { |
sundar@136 | 61 | if (cs == null) { |
sundar@136 | 62 | return defineClass(name, data, 0, data.length, new ProtectionDomain(null, getPermissions(null))); |
sundar@136 | 63 | } else { |
sundar@136 | 64 | return defineClass(name, data, 0, data.length, cs); |
sundar@136 | 65 | } |
jlaskey@3 | 66 | } |
jlaskey@3 | 67 | } |