зеркало из https://github.com/mozilla/gecko-dev.git
Move code to try to load a class from getPkgProperty to the separated findClass method and add catching of SecurityException there.
This commit is contained in:
Родитель
6c08e83f5d
Коммит
25a4f559fd
|
@ -210,27 +210,22 @@ public class NativeJavaPackage extends ScriptableObject {
|
|||
: packageName + "." + name;
|
||||
Context cx = Context.getContext();
|
||||
ClassShutter shutter = cx.getClassShutter();
|
||||
Scriptable newValue;
|
||||
try {
|
||||
if (shutter != null && !shutter.visibleToScripts(newPackage))
|
||||
throw new ClassNotFoundException();
|
||||
Class newClass = classLoader != null
|
||||
? classLoader.loadClass(newPackage)
|
||||
: ScriptRuntime.loadClassName(newPackage);
|
||||
newValue = new NativeJavaClass(getTopLevelScope(this), newClass);
|
||||
newValue.setParentScope(this);
|
||||
newValue.setPrototype(this.prototype);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
if (createPkg) {
|
||||
NativeJavaPackage pkg = new NativeJavaPackage(newPackage,
|
||||
classLoader);
|
||||
pkg.setParentScope(this);
|
||||
pkg.setPrototype(this.prototype);
|
||||
newValue = pkg;
|
||||
} else {
|
||||
newValue = null;
|
||||
Scriptable newValue = null;
|
||||
if (shutter == null || shutter.visibleToScripts(newPackage)) {
|
||||
Class cl = findClass(classLoader, newPackage);
|
||||
if (cl != null) {
|
||||
newValue = new NativeJavaClass(getTopLevelScope(this), cl);
|
||||
newValue.setParentScope(this);
|
||||
newValue.setPrototype(this.prototype);
|
||||
}
|
||||
}
|
||||
if (newValue == null && createPkg) {
|
||||
NativeJavaPackage pkg = new NativeJavaPackage(newPackage,
|
||||
classLoader);
|
||||
pkg.setParentScope(this);
|
||||
pkg.setPrototype(this.prototype);
|
||||
newValue = pkg;
|
||||
}
|
||||
if (newValue != null) {
|
||||
// Make it available for fast lookup and sharing of
|
||||
// lazily-reflected constructors and static members.
|
||||
|
@ -277,6 +272,19 @@ public class NativeJavaPackage extends ScriptableObject {
|
|||
Context.getMessage0("msg.not.java.obj"));
|
||||
}
|
||||
|
||||
private static Class findClass(ClassLoader loader, String className) {
|
||||
try {
|
||||
if (loader != null) {
|
||||
return loader.loadClass(className);
|
||||
} else {
|
||||
return ScriptRuntime.loadClassName(className);
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String packageName;
|
||||
private ClassLoader classLoader;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче