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 check = true;
static final boolean useJSObject = false;
static boolean isCachingEnabled = true; static boolean isCachingEnabled = true;
private static Hashtable threadContexts = new Hashtable(11); private static Hashtable threadContexts = new Hashtable(11);

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

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

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

@ -188,20 +188,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
Class cls = obj.getClass(); Class cls = obj.getClass();
if (cls.isArray()) if (cls.isArray())
return NativeJavaArray.wrap(scope, obj); 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); return new NativeJavaObject(scope, obj, staticType);
} }
@ -374,10 +360,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
if (to == ScriptRuntime.ClassClass) { if (to == ScriptRuntime.ClassClass) {
result = 1; result = 1;
} }
else if (Context.useJSObject && jsObjectClass != null &&
jsObjectClass.isAssignableFrom(to)) {
result = 2;
}
else if (to == ScriptRuntime.ObjectClass) { else if (to == ScriptRuntime.ObjectClass) {
result = 3; result = 3;
} }
@ -410,11 +392,7 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
case JSTYPE_OBJECT: case JSTYPE_OBJECT:
// Other objects takes #1-#3 spots // Other objects takes #1-#3 spots
if (Context.useJSObject && jsObjectClass != null && if (fromObj instanceof NativeArray && to.isArray()) {
jsObjectClass.isAssignableFrom(to)) {
result = 1;
}
else if (fromObj instanceof NativeArray && to.isArray()) {
// This is a native array conversion to a java array // This is a native array conversion to a java array
// Array conversions are all equal, and preferable to object // Array conversions are all equal, and preferable to object
// and string conversion, per LC3. // and string conversion, per LC3.
@ -612,26 +590,19 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
break; break;
case JSTYPE_JAVA_CLASS: case JSTYPE_JAVA_CLASS:
if (Context.useJSObject && jsObjectClass != null && if (value instanceof Wrapper) {
(type == ScriptRuntime.ObjectClass || value = ((Wrapper)value).unwrap();
jsObjectClass.isAssignableFrom(type))) { }
return coerceToJSObject(type, (Scriptable)value);
if (type == ScriptRuntime.ClassClass ||
type == ScriptRuntime.ObjectClass) {
return value;
}
else if (type == ScriptRuntime.StringClass) {
return value.toString();
} }
else { else {
if (value instanceof Wrapper) { reportConversionError(value, type, !useErrorHandler);
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);
}
} }
break; break;
@ -662,12 +633,7 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
break; break;
case JSTYPE_OBJECT: case JSTYPE_OBJECT:
if (Context.useJSObject && jsObjectClass != null && if (type == ScriptRuntime.StringClass) {
(type == ScriptRuntime.ObjectClass ||
jsObjectClass.isAssignableFrom(type))) {
return coerceToJSObject(type, (Scriptable)value);
}
else if (type == ScriptRuntime.StringClass) {
return ScriptRuntime.toString(value); return ScriptRuntime.toString(value);
} }
else if (type.isPrimitive()) { else if (type.isPrimitive()) {
@ -714,28 +680,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
return value; 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) { static Object coerceToNumber(Class type, Object value, boolean useErrorHandler) {
Class valueClass = value.getClass(); Class valueClass = value.getClass();
@ -934,23 +878,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
value.toString(), NativeJavaMethod.javaSignature(type)); 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. * The prototype of this object.
*/ */
@ -965,9 +892,6 @@ WrapFactory#wrap(Context cx, Scriptable scope, Object obj, Class)}
protected JavaMembers members; protected JavaMembers members;
protected Class staticType; protected Class staticType;
private Hashtable fieldAndMethods; private Hashtable fieldAndMethods;
static Class jsObjectClass;
static Constructor jsObjectCtor;
static Method jsObjectGetScriptable;
public void writeExternal(ObjectOutput out) public void writeExternal(ObjectOutput out)
throws IOException throws IOException

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

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