In reading the LiveConnect spec, it looks like Mark's problem with overloading
methods is due to a bug in Rhino with respect to how LiveConnect is
implemented.

In NativeJavaObject.java, the getConversionWeight method has the case for
JSTYPE_JAVA_ARRAY and JSTYPE_JAVA_OBJECT shares common code.  In the
LiveConnect 3 spec, section 3.3.6.1 describes wrapped Java objects, and 3.3.6.2
describes wrapped Java arrays.  Mark has a wrapped Java array of byte.

He is trying to call a method that has an overload of byte[] and for byte as
well.  It is reporting an ambiguous choice, which is why we needed the syntax
for selecting the overload.  BUt it looks like this should not be necessary.

According to the spec, you can pass a wrapped Java object to a primitive (non
boolean) type, but you cnnot do so for a wrapped Java array.  Around line 366
in my version of the file, there is a test to account for the JSTYPE_JAVA_ARRAY
for passing to a primitive type.  It looks to me like it should return
CONVERSION_NONE for a wrapped array, but it is returning CONVERSION_NONTRIVIAL.
The relevant lines of code are:

        case JSTYPE_JAVA_OBJECT:
        case JSTYPE_JAVA_ARRAY:
            Object javaObj = fromObj;
            if (javaObj instanceof Wrapper) {
                javaObj = ((Wrapper)javaObj).unwrap();
            }
            if (to.isInstance(javaObj)) {
                return CONVERSION_NONTRIVIAL;
            }
            if (to == ScriptRuntime.StringClass) {
                return 2;
            }
            else if (to.isPrimitive() && to != Boolean.TYPE) {
                return (fromCode == JSTYPE_JAVA_ARRAY)
                       ? CONVERSION_NONTRIVIAL : 2 + getSizeRank(to);
            }
            break;
This commit is contained in:
nboyd%atg.com 2007-09-28 17:43:38 +00:00
Родитель 7b9d947479
Коммит e78090b0e8
1 изменённых файлов: 1 добавлений и 1 удалений

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

@ -364,7 +364,7 @@ WrapFactory#wrap(Context, Scriptable, Object, Class)}
}
else if (to.isPrimitive() && to != Boolean.TYPE) {
return (fromCode == JSTYPE_JAVA_ARRAY)
? CONVERSION_NONTRIVIAL : 2 + getSizeRank(to);
? CONVERSION_NONE : 2 + getSizeRank(to);
}
break;