Using IdFunction in place of JIFunction in NativeJavaTopPackage

This commit is contained in:
igor%mir2.org 2004-06-08 15:29:34 +00:00
Родитель 4ab02a8202
Коммит 7be4658c39
3 изменённых файлов: 35 добавлений и 41 удалений

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

@ -60,34 +60,14 @@ public class IdFunction extends BaseFunction
return this.tag == tag;
}
public static void define(Scriptable scope, String name,
IdFunctionMaster master, int id)
public final int getMethodId()
{
define(scope, name, master, id, ScriptableObject.DONTENUM, false);
return methodId;
}
public static void define(Scriptable scope, String name,
IdFunctionMaster master, int id,
int attributes)
public final void enableConstructorUsage()
{
define(scope, name, master, id, attributes, false);
}
public static void define(Scriptable scope, String name,
IdFunctionMaster master, int id,
int attributes, boolean seal)
{
IdFunction f = new IdFunction(master, name, id);
f.defineAsScopeProperty(scope, attributes, seal);
}
public static void defineConstructor(Scriptable scope, String name,
IdFunctionMaster master, int id,
int attributes, boolean seal)
{
IdFunction f = new IdFunction(master, name, id);
f.useCallAsConstructor = true;
f.defineAsScopeProperty(scope, attributes, seal);
useCallAsConstructor = true;
}
public final void defineAsScopeProperty(Scriptable scope, boolean seal)
@ -103,11 +83,6 @@ public class IdFunction extends BaseFunction
ScriptableObject.defineProperty(scope, functionName, this, attributes);
}
public final int getMethodId()
{
return methodId;
}
public Scriptable getPrototype()
{
// Lazy initialization of prototype: for native functions this

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

@ -168,8 +168,9 @@ public final class JavaAdapter implements IdFunctionMaster
public static void init(Context cx, Scriptable scope, boolean sealed)
{
JavaAdapter obj = new JavaAdapter();
new IdFunction(FTAG, obj, "JavaAdapter", Id_JavaAdapter)
.defineAsScopeProperty(scope, sealed);
IdFunction f = new IdFunction(FTAG, obj, "JavaAdapter", Id_JavaAdapter);
f.enableConstructorUsage();
f.defineAsScopeProperty(scope, sealed);
}
public Object execMethod(IdFunction f, Context cx, Scriptable scope,

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

@ -53,7 +53,7 @@ import java.lang.reflect.*;
*/
public class NativeJavaTopPackage
extends NativeJavaPackage implements Function
extends NativeJavaPackage implements Function, IdFunctionMaster
{
// we know these are packages so we can skip the class check
@ -117,13 +117,8 @@ public class NativeJavaTopPackage
}
// getClass implementation
JIFunction getClass = new JIFunction("getClass", 1) {
public Object call(Context fcx, Scriptable fscope,
Scriptable thisObj, Object[] args)
{
return top.js_getClass(fcx, fscope, args);
}
};
IdFunction
getClass = new IdFunction(FTAG, top, "getClass", Id_getClass);
// We want to get a real alias, and not a distinct JavaPackage
// with the same packageName, so that we share classes and top
@ -134,12 +129,33 @@ public class NativeJavaTopPackage
// a ScriptableObject.
ScriptableObject global = (ScriptableObject) scope;
getClass.defineAsProperty(global, ScriptableObject.DONTENUM);
getClass.defineAsScopeProperty(global, sealed);
global.defineProperty("Packages", top, ScriptableObject.DONTENUM);
global.defineProperty("java", javaAlias, ScriptableObject.DONTENUM);
}
final Scriptable js_getClass(Context cx, Scriptable scope, Object[] args)
public Object execMethod(IdFunction f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_getClass) {
return js_getClass(cx, scope, args);
}
}
throw f.unknown();
}
public int methodArity(IdFunction f)
{
if (f.hasTag(FTAG)) {
if (f.methodId == Id_getClass) {
return 1;
}
}
throw f.unknown();
}
private Scriptable js_getClass(Context cx, Scriptable scope, Object[] args)
{
if (args.length > 0 && args[0] instanceof Wrapper) {
Scriptable result = this;
@ -166,5 +182,7 @@ public class NativeJavaTopPackage
Context.getMessage0("msg.not.java.obj"));
}
private static final Object FTAG = new Object();
private static final int Id_getClass = 1;
}