I added ContextFactory.createClassLoader that is called from Context.createClassLoader to remove the need to subclass Context if a custom ClassLoader is required.

This commit is contained in:
igor%mir2.org 2004-10-14 07:31:00 +00:00
Родитель d066ea04be
Коммит 907a84e3c8
3 изменённых файлов: 28 добавлений и 5 удалений

Просмотреть файл

@ -2179,9 +2179,15 @@ public class Context
f.observeInstructionCount(this, instructionCount);
}
/**
* Create class loader for generated classes.
* The method calls {@link ContextFactory#createClassLoader(ClassLoader)}
* using the result of {@link #getFactory()}.
*/
public GeneratedClassLoader createClassLoader(ClassLoader parent)
{
return new DefiningClassLoader(parent);
ContextFactory f = getFactory();
return f.createClassLoader(parent);
}
public final ClassLoader getApplicationClassLoader()

Просмотреть файл

@ -273,6 +273,20 @@ public class ContextFactory
throw new IllegalArgumentException(String.valueOf(featureIndex));
}
/**
* Create class loader for generated classes.
* This method creates an instance of the default implementation
* of {@link GeneratedClassLoader}. Rhino uses this interface to load
* generated JVM classes when no {@link SecurityController}
* is installed.
* Application can override the method to provide custom class loading.
*/
protected GeneratedClassLoader createClassLoader(ClassLoader parent)
{
return new DefiningClassLoader(parent);
}
/**
* Execute top call to script or function.
* When the runtime is about to execute a script or function that will

Просмотреть файл

@ -105,16 +105,19 @@ public class Codegen extends Interpreter
return f;
}
private static Class defineClass(Object bytecode,
Object staticSecurityDomain)
private Class defineClass(Object bytecode,
Object staticSecurityDomain)
{
Object[] nameBytesPair = (Object[])bytecode;
String className = (String)nameBytesPair[0];
byte[] classBytes = (byte[])nameBytesPair[1];
// The generated classes in this case refer only to Rhino classes
// which must be accessible through this class loader
ClassLoader rhinoLoader = getClass().getClassLoader();
GeneratedClassLoader loader;
loader = SecurityController.createLoader(null, staticSecurityDomain);
loader = SecurityController.createLoader(rhinoLoader,
staticSecurityDomain);
Exception e;
try {
Class cl = loader.defineClass(className, classBytes);