mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-09 00:11:44 +00:00
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:
parent
d066ea04be
commit
907a84e3c8
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user