Initialize invoker in FunctionObject constructor, not during first call and catch possible SecurityException. In this way initialization will happen without script code on java stack which may not have permissions to create class loaders.
This commit is contained in:
igor%mir2.org 2003-03-31 13:18:04 +00:00
Родитель a0d589924f
Коммит 9e16916a56
2 изменённых файлов: 21 добавлений и 9 удалений

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

@ -186,9 +186,21 @@ public class FunctionObject extends BaseFunction {
hasVoidReturn = method != null && method.getReturnType() == Void.TYPE;
ScriptRuntime.setFunctionProtoAndParent(scope, this);
Context cx = Context.getCurrentContext();
useDynamicScope = cx != null &&
cx.hasCompileFunctionsWithDynamicScope();
Context cx = Context.getContext();
useDynamicScope = cx.hasCompileFunctionsWithDynamicScope();
if (method != null) {
Invoker master = invokerMaster;
if (master != null) {
try {
invoker = master.createInvoker(cx, method, types);
} catch (SecurityException ex) {
// Ignore invoker optimization in case of SecurityException
// which can be the case if class loader creation is
// disabled.
}
}
}
}
/**
@ -489,11 +501,7 @@ public class FunctionObject extends BaseFunction {
private final Object doInvoke(Context cx, Object thisObj, Object[] args)
throws IllegalAccessException, InvocationTargetException
{
Invoker master = invokerMaster;
if (master != null) {
if (invoker == null) {
invoker = master.createInvoker(cx, method, types);
}
if (invoker != null) {
try {
return invoker.invoke(thisObj, args);
} catch (Exception e) {

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

@ -57,9 +57,13 @@ public class InvokerImpl extends Invoker {
int classNum;
synchronized (this) {
if (invokersCache == null) {
invokersCache = new Hashtable();
ClassLoader parentLoader = cx.getClass().getClassLoader();
classLoader = cx.createClassLoader(parentLoader);
// Initialize invokersCache after creation of classloader
// since it can throw SecurityException. It prevents
// NullPointerException when accessing classLoader on
// the second Invoker invocation.
invokersCache = new Hashtable();
} else {
result = (Invoker)invokersCache.get(method);
if (result != null) { return result; }