mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-07 11:56:51 +00:00
Switch to use IdFunction to define ImporterTopLevel script methods. A separated class is used to implement IdFunctionMaster interface to avoid interface clashes with possible ImporterTopLevel subclasses implementing the same interface.
This commit is contained in:
parent
baa6ad963f
commit
607b4b7a6c
@ -83,14 +83,7 @@ public class ImporterTopLevel extends ScriptableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
String[] names = { "importClass", "importPackage" };
|
(new ImporterFunctions(this)).define(this);
|
||||||
|
|
||||||
try {
|
|
||||||
this.defineFunctionProperties(names, ImporterTopLevel.class,
|
|
||||||
ScriptableObject.DONTENUM);
|
|
||||||
} catch (PropertyException e) {
|
|
||||||
throw new Error(); // should never happen
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassName() {
|
public String getClassName() {
|
||||||
@ -138,8 +131,8 @@ public class ImporterTopLevel extends ScriptableObject {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void importClass(Context cx, Scriptable thisObj,
|
void importClass(Context cx, Scriptable thisObj, Object[] args)
|
||||||
Object[] args, Function funObj) {
|
{
|
||||||
for (int i=0; i<args.length; i++) {
|
for (int i=0; i<args.length; i++) {
|
||||||
Object cl = args[i];
|
Object cl = args[i];
|
||||||
if (!(cl instanceof NativeJavaClass)) {
|
if (!(cl instanceof NativeJavaClass)) {
|
||||||
@ -157,8 +150,8 @@ public class ImporterTopLevel extends ScriptableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void importPackage(Context cx, Scriptable thisObj,
|
void importPackage(Context cx, Scriptable thisObj, Object[] args)
|
||||||
Object[] args, Function funObj) {
|
{
|
||||||
Scriptable importedPackages;
|
Scriptable importedPackages;
|
||||||
Object plist = thisObj.get("_packages_", thisObj);
|
Object plist = thisObj.get("_packages_", thisObj);
|
||||||
if (plist == NOT_FOUND) {
|
if (plist == NOT_FOUND) {
|
||||||
@ -186,3 +179,42 @@ public class ImporterTopLevel extends ScriptableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class ImporterFunctions implements IdFunctionMaster
|
||||||
|
{
|
||||||
|
ImporterFunctions(ImporterTopLevel importer)
|
||||||
|
{
|
||||||
|
this.importer = importer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void define(Scriptable scope)
|
||||||
|
{
|
||||||
|
IdFunction.define(scope, "importClass", this, Id_importClass);
|
||||||
|
IdFunction.define(scope, "importPackage", this, Id_importPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execMethod(int methodId, IdFunction function, Context cx,
|
||||||
|
Scriptable scope, Scriptable thisObj,
|
||||||
|
Object[] args)
|
||||||
|
throws JavaScriptException
|
||||||
|
{
|
||||||
|
if (methodId == Id_importClass) {
|
||||||
|
importer.importClass(cx, thisObj, args);
|
||||||
|
} else {
|
||||||
|
if (methodId != Id_importPackage) Context.codeBug();
|
||||||
|
importer.importPackage(cx, thisObj, args);
|
||||||
|
}
|
||||||
|
return Undefined.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int methodArity(int methodId)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int
|
||||||
|
Id_importClass = 1,
|
||||||
|
Id_importPackage = 2;
|
||||||
|
|
||||||
|
private ImporterTopLevel importer;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user