Fix following problem:
Subject:
another getClassLoader exception
Date:
Tue, 12 Oct 1999 10:39:26 -0400
From:
Andrew Wason <aw@softcom.com>
To:
norris@netscape.com (Norris Boyd)
CC:
Howard Lin <howard@softcom.com>
Norris,
It looks like the classes the optimizer generates call
ScriptRuntime.defineFunction which calls getClassLoader. This throws a
SecurityException.
java.security.AccessControlException: access denied
(java.lang.RuntimePermission getClassLoader )
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java
, Compiled Code)
at java.security.AccessController.checkPermission(AccessController.java,
Compiled Code)
at java.lang.SecurityManager.checkPermission(SecurityManager.java, Compiled
Code)
at java.lang.Class.getClassLoader(Class.java, Compiled Code)
at
org.mozilla.javascript.ScriptRuntime.defineFunction(ScriptRuntime.java:2045)
at org.mozilla.javascript.gen.c5.initScript(order.js)
at org.mozilla.javascript.gen.c5.exec(order.js)
at org.mozilla.javascript.Context.evaluateReader(Context.java:728)
[...]
Andrew
--
Andrew Wason
SoftCom, Inc.
aw@softcom.com
git-svn-id: svn://10.0.0.236/trunk@50514 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -2033,26 +2033,15 @@ public class ScriptRuntime {
|
||||
return scope.getParentScope();
|
||||
}
|
||||
|
||||
public static NativeFunction defineFunction(Scriptable scope,
|
||||
String className,
|
||||
String fnName,
|
||||
Object loadingObject,
|
||||
Context cx)
|
||||
throws ClassNotFoundException
|
||||
public static NativeFunction initFunction(NativeFunction fn,
|
||||
Scriptable scope,
|
||||
String fnName,
|
||||
Context cx)
|
||||
{
|
||||
NativeFunction fn;
|
||||
try {
|
||||
ClassLoader loader = loadingObject.getClass().getClassLoader();
|
||||
Class clazz = (loader == null) ? Class.forName(className)
|
||||
: loader.loadClass(className);
|
||||
fn = createFunctionObject(scope, clazz, cx);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
fn.setPrototype(ScriptableObject.getClassPrototype(scope, "Function"));
|
||||
fn.setParentScope(scope);
|
||||
if (fnName != null && fnName.length() != 0)
|
||||
setName(scope, fn, scope, fnName);
|
||||
|
||||
setName(scope, fn, scope, fnName);
|
||||
return fn;
|
||||
}
|
||||
|
||||
|
||||
@@ -1395,32 +1395,45 @@ public class Codegen extends Interpreter {
|
||||
Node def = (Node) fns.elementAt(i);
|
||||
Codegen codegen = new Codegen();
|
||||
String fnClassName = codegen.generateCode(def, results, itsNameHelper);
|
||||
// initialize a property by that name, and push the object
|
||||
// as a result
|
||||
|
||||
addByteCode(ByteCode.NEW, fnClassName);
|
||||
addByteCode(ByteCode.DUP);
|
||||
if (inFunction) {
|
||||
addByteCode(ByteCode.ALOAD_0); // load "this" argument
|
||||
} else {
|
||||
aload(variableObjectLocal);
|
||||
}
|
||||
push(fnClassName);
|
||||
aload(contextLocal); // load 'cx'
|
||||
addSpecialInvoke(fnClassName, "<init>",
|
||||
"(Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"V");
|
||||
|
||||
// 'fn' still on stack
|
||||
// load 'scope'
|
||||
if (inFunction) {
|
||||
addByteCode(ByteCode.ALOAD_0); // load "this" argument
|
||||
} else {
|
||||
aload(variableObjectLocal);
|
||||
}
|
||||
// load 'fnName'
|
||||
String str = def.getString();
|
||||
if (str != null) {
|
||||
push(str);
|
||||
} else {
|
||||
addByteCode(ByteCode.ACONST_NULL);
|
||||
}
|
||||
addByteCode(ByteCode.ALOAD_0); // load 'this'
|
||||
aload(contextLocal); // load 'cx'
|
||||
addScriptRuntimeInvoke("defineFunction",
|
||||
"(Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Ljava/lang/Object;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"Lorg/mozilla/javascript/NativeFunction;");
|
||||
// load 'cx'
|
||||
aload(contextLocal);
|
||||
addScriptRuntimeInvoke("initFunction",
|
||||
"(Lorg/mozilla/javascript/NativeFunction;" +
|
||||
"Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"Lorg/mozilla/javascript/NativeFunction;");
|
||||
def.putProp(Node.FUNCTION_PROP, new Short(i));
|
||||
addByteCode(ByteCode.AASTORE); // store NativeFunction
|
||||
// instance to array
|
||||
// instance to array
|
||||
}
|
||||
|
||||
// add the array as the nestedFunctions field; array should
|
||||
|
||||
@@ -2033,26 +2033,15 @@ public class ScriptRuntime {
|
||||
return scope.getParentScope();
|
||||
}
|
||||
|
||||
public static NativeFunction defineFunction(Scriptable scope,
|
||||
String className,
|
||||
String fnName,
|
||||
Object loadingObject,
|
||||
Context cx)
|
||||
throws ClassNotFoundException
|
||||
public static NativeFunction initFunction(NativeFunction fn,
|
||||
Scriptable scope,
|
||||
String fnName,
|
||||
Context cx)
|
||||
{
|
||||
NativeFunction fn;
|
||||
try {
|
||||
ClassLoader loader = loadingObject.getClass().getClassLoader();
|
||||
Class clazz = (loader == null) ? Class.forName(className)
|
||||
: loader.loadClass(className);
|
||||
fn = createFunctionObject(scope, clazz, cx);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw WrappedException.wrapException(e);
|
||||
}
|
||||
fn.setPrototype(ScriptableObject.getClassPrototype(scope, "Function"));
|
||||
fn.setParentScope(scope);
|
||||
if (fnName != null && fnName.length() != 0)
|
||||
setName(scope, fn, scope, fnName);
|
||||
|
||||
setName(scope, fn, scope, fnName);
|
||||
return fn;
|
||||
}
|
||||
|
||||
|
||||
@@ -1395,32 +1395,45 @@ public class Codegen extends Interpreter {
|
||||
Node def = (Node) fns.elementAt(i);
|
||||
Codegen codegen = new Codegen();
|
||||
String fnClassName = codegen.generateCode(def, results, itsNameHelper);
|
||||
// initialize a property by that name, and push the object
|
||||
// as a result
|
||||
|
||||
addByteCode(ByteCode.NEW, fnClassName);
|
||||
addByteCode(ByteCode.DUP);
|
||||
if (inFunction) {
|
||||
addByteCode(ByteCode.ALOAD_0); // load "this" argument
|
||||
} else {
|
||||
aload(variableObjectLocal);
|
||||
}
|
||||
push(fnClassName);
|
||||
aload(contextLocal); // load 'cx'
|
||||
addSpecialInvoke(fnClassName, "<init>",
|
||||
"(Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"V");
|
||||
|
||||
// 'fn' still on stack
|
||||
// load 'scope'
|
||||
if (inFunction) {
|
||||
addByteCode(ByteCode.ALOAD_0); // load "this" argument
|
||||
} else {
|
||||
aload(variableObjectLocal);
|
||||
}
|
||||
// load 'fnName'
|
||||
String str = def.getString();
|
||||
if (str != null) {
|
||||
push(str);
|
||||
} else {
|
||||
addByteCode(ByteCode.ACONST_NULL);
|
||||
}
|
||||
addByteCode(ByteCode.ALOAD_0); // load 'this'
|
||||
aload(contextLocal); // load 'cx'
|
||||
addScriptRuntimeInvoke("defineFunction",
|
||||
"(Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Ljava/lang/Object;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"Lorg/mozilla/javascript/NativeFunction;");
|
||||
// load 'cx'
|
||||
aload(contextLocal);
|
||||
addScriptRuntimeInvoke("initFunction",
|
||||
"(Lorg/mozilla/javascript/NativeFunction;" +
|
||||
"Lorg/mozilla/javascript/Scriptable;" +
|
||||
"Ljava/lang/String;" +
|
||||
"Lorg/mozilla/javascript/Context;)",
|
||||
"Lorg/mozilla/javascript/NativeFunction;");
|
||||
def.putProp(Node.FUNCTION_PROP, new Short(i));
|
||||
addByteCode(ByteCode.AASTORE); // store NativeFunction
|
||||
// instance to array
|
||||
// instance to array
|
||||
}
|
||||
|
||||
// add the array as the nestedFunctions field; array should
|
||||
|
||||
Reference in New Issue
Block a user