Removal of unused code for explicit JSObject support:

> Norris Boyd wrote:
>
> Igor Bukaniv wrote:
> >
> > I am curios, why there is a need to have a special JSObject support in Rhino? Was it used for anything? The implementation in the ICEbrowser does not use it as in rare cases where conversion from JSObject to/from JS type may be needed (like calling JSObject.getWindow from a script), it seems that WrapHandler (or similar modifications to pre Rhino 1.5R2 sources) and Wrapper are enough to cover all the cases.
> Yes, we should probably just remove the JSObject code. We added it early on when Rhino was first written and we thought we might need JSObject compatibility with the JS + Java implementation in Navigator 4.x. That's not important now, so we should just remove this code (which likely doesn't work at this point anyway).
This commit is contained in:
igor%mir2.org 2002-06-12 05:32:35 +00:00
Родитель d5c0bf6b9b
Коммит 558b670d29
4 изменённых файлов: 24 добавлений и 123 удалений

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

@ -2239,8 +2239,6 @@ public class Context {
static final boolean check = true;
static final boolean useJSObject = false;
static boolean isCachingEnabled = true;
private static Hashtable threadContexts = new Hashtable(11);

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

@ -320,35 +320,17 @@ public class NativeJavaMethod extends NativeFunction implements Function {
if (methodsOrCtors.length == 0)
return null;
boolean hasMethods = methodsOrCtors[0] instanceof Method;
if (Context.useJSObject &&
NativeJavaObject.jsObjectClass != null)
{
try {
for (int i = 0; i < args.length; i++) {
if (NativeJavaObject.jsObjectClass.isInstance(args[i]))
args[i] = NativeJavaObject.jsObjectGetScriptable.invoke(
args[i], ScriptRuntime.emptyArgs);
}
}
catch (InvocationTargetException e) {
// Just abandon conversion from JSObject
}
catch (IllegalAccessException e) {
// Just abandon conversion from JSObject
}
} else {
// Wrapper support
for (int i=0; i < args.length; i++) {
Object arg = args[i];
if (arg instanceof Wrapper) {
arg = ((Wrapper)arg).unwrap();
if (!(arg instanceof Number)) {
// Since numbers are internally represented as
// java.lang.Double, etc. then java.lang.Doubles are
// distinquished by being wrapped. Thus don't unwrap
// here or we'll get overloading wrong.
args[i] = arg;
}
// Wrapper support
for (int i=0; i < args.length; i++) {
Object arg = args[i];
if (arg instanceof Wrapper) {
arg = ((Wrapper)arg).unwrap();
if (!(arg instanceof Number)) {
// Since numbers are internally represented as
// java.lang.Double, etc. then java.lang.Doubles are
// distinquished by being wrapped. Thus don't unwrap
// here or we'll get overloading wrong.
args[i] = arg;
}
}
}

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

@ -188,20 +188,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
Class cls = obj.getClass();
if (cls.isArray())
return NativeJavaArray.wrap(scope, obj);
if (Context.useJSObject && jsObjectClass != null &&
staticType != jsObjectClass && jsObjectClass.isInstance(obj))
{
try {
return jsObjectGetScriptable.
invoke(obj, ScriptRuntime.emptyArgs);
}
catch (InvocationTargetException e) {
// Just abandon conversion from JSObject
}
catch (IllegalAccessException e) {
// Just abandon conversion from JSObject
}
}
return new NativeJavaObject(scope, obj, staticType);
}
@ -374,10 +360,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
if (to == ScriptRuntime.ClassClass) {
result = 1;
}
else if (Context.useJSObject && jsObjectClass != null &&
jsObjectClass.isAssignableFrom(to)) {
result = 2;
}
else if (to == ScriptRuntime.ObjectClass) {
result = 3;
}
@ -410,11 +392,7 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
case JSTYPE_OBJECT:
// Other objects takes #1-#3 spots
if (Context.useJSObject && jsObjectClass != null &&
jsObjectClass.isAssignableFrom(to)) {
result = 1;
}
else if (fromObj instanceof NativeArray && to.isArray()) {
if (fromObj instanceof NativeArray && to.isArray()) {
// This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object
// and string conversion, per LC3.
@ -612,26 +590,19 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
break;
case JSTYPE_JAVA_CLASS:
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
jsObjectClass.isAssignableFrom(type))) {
return coerceToJSObject(type, (Scriptable)value);
if (value instanceof Wrapper) {
value = ((Wrapper)value).unwrap();
}
if (type == ScriptRuntime.ClassClass ||
type == ScriptRuntime.ObjectClass) {
return value;
}
else if (type == ScriptRuntime.StringClass) {
return value.toString();
}
else {
if (value instanceof Wrapper) {
value = ((Wrapper)value).unwrap();
}
if (type == ScriptRuntime.ClassClass ||
type == ScriptRuntime.ObjectClass) {
return value;
}
else if (type == ScriptRuntime.StringClass) {
return value.toString();
}
else {
reportConversionError(value, type, !useErrorHandler);
}
reportConversionError(value, type, !useErrorHandler);
}
break;
@ -662,12 +633,7 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
break;
case JSTYPE_OBJECT:
if (Context.useJSObject && jsObjectClass != null &&
(type == ScriptRuntime.ObjectClass ||
jsObjectClass.isAssignableFrom(type))) {
return coerceToJSObject(type, (Scriptable)value);
}
else if (type == ScriptRuntime.StringClass) {
if (type == ScriptRuntime.StringClass) {
return ScriptRuntime.toString(value);
}
else if (type.isPrimitive()) {
@ -714,28 +680,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
return value;
}
static Object coerceToJSObject(Class type, Scriptable value) {
// If JSObject compatibility is enabled, and the method wants it,
// wrap the Scriptable value in a JSObject.
if (ScriptRuntime.ScriptableClass.isAssignableFrom(type))
return value;
try {
Object ctorArgs[] = { value };
return jsObjectCtor.newInstance(ctorArgs);
} catch (InstantiationException instEx) {
throw new EvaluatorException("error generating JSObject wrapper for " +
value);
} catch (IllegalArgumentException argEx) {
throw new EvaluatorException("JSObject constructor doesn't want [Scriptable]!");
} catch (InvocationTargetException e) {
throw WrappedException.wrapException(e.getTargetException());
} catch (IllegalAccessException accessEx) {
throw new EvaluatorException("JSObject constructor is protected/private!");
}
}
static Object coerceToNumber(Class type, Object value, boolean useErrorHandler) {
Class valueClass = value.getClass();
@ -934,23 +878,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
value.toString(), NativeJavaMethod.javaSignature(type));
}
public static void initJSObject() {
// if netscape.javascript.JSObject is in the CLASSPATH, enable JSObject
// compatability wrappers
jsObjectClass = null;
try {
jsObjectClass = Class.forName("netscape.javascript.JSObject");
Class ctorParms[] = { ScriptRuntime.ScriptableClass };
jsObjectCtor = jsObjectClass.getConstructor(ctorParms);
jsObjectGetScriptable = jsObjectClass.getMethod("getScriptable",
new Class[0]);
} catch (ClassNotFoundException classEx) {
// jsObjectClass already null
} catch (NoSuchMethodException methEx) {
// jsObjectClass already null
}
}
/**
* The prototype of this object.
*/
@ -965,9 +892,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
protected JavaMembers members;
protected Class staticType;
private Hashtable fieldAndMethods;
static Class jsObjectClass;
static Constructor jsObjectCtor;
static Method jsObjectGetScriptable;
public void writeExternal(ObjectOutput out)
throws IOException

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

@ -131,9 +131,6 @@ public class NativeJavaPackage extends ScriptableObject {
for (int i = 0; i < commonPackages.length; i++)
packages.forcePackage(commonPackages[i]);
if (Context.useJSObject)
NativeJavaObject.initJSObject();
Method[] m = FunctionObject.findMethods(NativeJavaPackage.class,
"jsFunction_getClass");
FunctionObject f = new FunctionObject("getClass", m[0], global);