equal
deleted
inserted
replaced
29 import java.security.AccessController; |
29 import java.security.AccessController; |
30 import java.security.PrivilegedAction; |
30 import java.security.PrivilegedAction; |
31 import java.security.ProtectionDomain; |
31 import java.security.ProtectionDomain; |
32 import java.security.SecureClassLoader; |
32 import java.security.SecureClassLoader; |
33 import jdk.internal.dynalink.beans.StaticClass; |
33 import jdk.internal.dynalink.beans.StaticClass; |
|
34 import jdk.nashorn.internal.runtime.Context; |
|
35 import jdk.nashorn.internal.runtime.ScriptFunction; |
34 |
36 |
35 /** |
37 /** |
36 * This class encapsulates the bytecode of the adapter class and can be used to load it into the JVM as an actual Class. |
38 * This class encapsulates the bytecode of the adapter class and can be used to load it into the JVM as an actual Class. |
37 * It can be invoked repeatedly to create multiple adapter classes from the same bytecode; adapter classes that have |
39 * It can be invoked repeatedly to create multiple adapter classes from the same bytecode; adapter classes that have |
38 * class-level overrides must be re-created for every set of such overrides. Note that while this class is named |
40 * class-level overrides must be re-created for every set of such overrides. Note that while this class is named |
83 private final ClassLoader myLoader = getClass().getClassLoader(); |
85 private final ClassLoader myLoader = getClass().getClassLoader(); |
84 |
86 |
85 @Override |
87 @Override |
86 public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { |
88 public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { |
87 try { |
89 try { |
|
90 Context.checkPackageAccess(name); |
88 return super.loadClass(name, resolve); |
91 return super.loadClass(name, resolve); |
89 } catch (final SecurityException se) { |
92 } catch (final SecurityException se) { |
90 // we may be implementing an interface or extending a class that was |
93 // we may be implementing an interface or extending a class that was |
91 // loaded by a loader that prevents package.access. If so, it'd throw |
94 // loaded by a loader that prevents package.access. If so, it'd throw |
92 // SecurityException for nashorn's classes!. For adapter's to work, we |
95 // SecurityException for nashorn's classes!. For adapter's to work, we |
93 // should be able to refer to nashorn classes. |
96 // should be able to refer to the few classes it needs in its implementation. |
94 if (name.startsWith("jdk.nashorn.internal.")) { |
97 if(ScriptFunction.class.getName().equals(name) || JavaAdapterServices.class.getName().equals(name)) { |
95 return myLoader.loadClass(name); |
98 return myLoader.loadClass(name); |
96 } |
99 } |
97 throw se; |
100 throw se; |
98 } |
101 } |
99 } |
102 } |