JIFunction was wrong idea at the end: it is better to stick with IdFunction and teach it missed functionality. The patch changes JavaAdapter to use IdFunction for its constructor call.

This commit is contained in:
igor%mir2.org 2004-06-08 12:38:20 +00:00
parent 3688853ede
commit f5bd7a5a11
2 changed files with 31 additions and 15 deletions

View File

@ -69,6 +69,17 @@ public class IdFunction extends BaseFunction
ScriptableObject.defineProperty(scope, name, f, attributes);
}
public static void defineConstructor(Scriptable scope, String name,
IdFunctionMaster master, int id,
int attributes, boolean sealed)
{
IdFunction f = new IdFunction(master, name, id);
f.setParentScope(scope);
f.useCallAsConstructor = true;
if (sealed) { f.sealObject(); }
ScriptableObject.defineProperty(scope, name, f, attributes);
}
public final int getMethodId()
{
return methodId;

View File

@ -47,7 +47,7 @@ import java.lang.reflect.*;
import java.io.*;
import java.util.*;
public final class JavaAdapter
public final class JavaAdapter implements IdFunctionMaster
{
/**
* Base class for interface with single method to function glue classes
@ -167,20 +167,25 @@ public final class JavaAdapter
public static void init(Context cx, Scriptable scope, boolean sealed)
{
JIFunction x = new JIFunction("JavaAdapter", 1)
{
public Scriptable createObject(Context cx, Scriptable scope)
{
return null;
}
JavaAdapter obj = new JavaAdapter();
IdFunction.defineConstructor(scope, "JavaAdapter", obj, Id_JavaAdapter,
ScriptableObject.DONTENUM, sealed);
}
public Object call(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
return js_createAdpter(cx, scope, args);
}
};
x.defineAsProperty(scope);
public Object execMethod(int methodId, IdFunction function, Context cx,
Scriptable scope, Scriptable thisObj,
Object[] args)
{
if (methodId == Id_JavaAdapter) {
return js_createAdpter(cx, scope, args);
}
throw IdFunction.onBadMethodId(this, methodId);
}
public int methodArity(int methodId)
{
if (methodId == Id_JavaAdapter) { return 1; }
throw IdFunction.onBadMethodId(this, methodId);
}
public static Object convertResult(Object result, Class c)
@ -1221,5 +1226,5 @@ public final class JavaAdapter
return array;
}
private static final int Id_JavaAdapter = 1;
}