Common package names preloaded

Prior to 1.7R1, Java classes in packages starting with "java." could be
 referenced directly, while classes in other packages would need to use the
 "Packages" object first. Now the following top-level packages are available,
 like "java", in the global scope: "javax", "org", "com", "edu", and "net".
This commit is contained in:
nboyd%atg.com 2007-09-18 16:54:52 +00:00
Родитель ccfd40ca10
Коммит 27bbdb5ce6
2 изменённых файлов: 14 добавлений и 2 удалений

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

@ -123,7 +123,11 @@ public class NativeJavaTopPackage
// We want to get a real alias, and not a distinct JavaPackage
// with the same packageName, so that we share classes and top
// that are underneath.
NativeJavaPackage javaAlias = (NativeJavaPackage)top.get("java", top);
String[] topNames = { "java", "javax", "org", "com", "edu", "net" };
NativeJavaPackage[] topPackages = new NativeJavaPackage[topNames.length];
for (int i=0; i < topNames.length; i++) {
topPackages[i] = (NativeJavaPackage)top.get(topNames[i], top);
}
// It's safe to downcast here since initStandardObjects takes
// a ScriptableObject.
@ -134,7 +138,10 @@ public class NativeJavaTopPackage
}
getClass.exportAsScopeProperty();
global.defineProperty("Packages", top, ScriptableObject.DONTENUM);
global.defineProperty("java", javaAlias, ScriptableObject.DONTENUM);
for (int i=0; i < topNames.length; i++) {
global.defineProperty(topNames[i], topPackages[i],
ScriptableObject.DONTENUM);
}
}
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,

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

@ -141,6 +141,11 @@ public class ScriptRuntime {
"RegExp", "org.mozilla.javascript.regexp.NativeRegExp",
"Packages", "org.mozilla.javascript.NativeJavaTopPackage",
"java", "org.mozilla.javascript.NativeJavaTopPackage",
"javax", "org.mozilla.javascript.NativeJavaTopPackage",
"org", "org.mozilla.javascript.NativeJavaTopPackage",
"com", "org.mozilla.javascript.NativeJavaTopPackage",
"edu", "org.mozilla.javascript.NativeJavaTopPackage",
"net", "org.mozilla.javascript.NativeJavaTopPackage",
"getClass", "org.mozilla.javascript.NativeJavaTopPackage",
"JavaAdapter", "org.mozilla.javascript.JavaAdapter",
"JavaImporter", "org.mozilla.javascript.ImporterTopLevel",