Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
jsj_convert.c File Reference
#include <stdlib.h>
#include <string.h>
#include "jsj_private.h"

Go to the source code of this file.

Defines

#define JSDOUBLE_HI32(x)   (((uint32 *)&(x))[0])
#define JSDOUBLE_LO32(x)   (((uint32 *)&(x))[1])
#define JSDOUBLE_HI32_SIGNBIT   0x80000000
#define JSDOUBLE_HI32_EXPMASK   0x7ff00000
#define JSDOUBLE_HI32_MANTMASK   0x000fffff
#define JSDOUBLE_IS_NaN(x)
#define JSDOUBLE_IS_INFINITE(x)
#define jbyte_MAX_VALUE   127.0
#define jbyte_MIN_VALUE   -128.0
#define jchar_MAX_VALUE   65535.0
#define jchar_MIN_VALUE   0.0
#define jshort_MAX_VALUE   32767.0
#define jshort_MIN_VALUE   -32768.0
#define jint_MAX_VALUE   2147483647.0
#define jint_MIN_VALUE   -2147483648.0
#define jlong_MAX_VALUE   9223372036854775807.0
#define jlong_MIN_VALUE   -9223372036854775808.0
#define JSVAL_TO_INTEGRAL_JVALUE(type_name, member_name, member_type, jsval, java_value)
#define jlong_to_jdouble(lvalue)   ((jdouble) lvalue)

Functions

static JSBool convert_js_obj_to_JSObject_wrapper (JSContext *cx, JNIEnv *jEnv, JSObject *js_obj, JavaSignature *signature, int *cost, jobject *java_value)
static JSBool convert_js_array_to_java_array (JSContext *cx, JNIEnv *jEnv, JSObject *js_array, JavaSignature *signature, jobject *java_valuep)
jstring jsj_ConvertJSStringToJavaString (JSContext *cx, JNIEnv *jEnv, JSString *js_str)
JSBool jsj_ConvertJSValueToJavaObject (JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature, int *cost, jobject *java_value, JSBool *is_local_refp)
JSBool jsj_ConvertJSValueToJavaValue (JSContext *cx, JNIEnv *jEnv, jsval v_arg, JavaSignature *signature, int *cost, jvalue *java_value, JSBool *is_local_refp)
JSStringjsj_ConvertJavaStringToJSString (JSContext *cx, JNIEnv *jEnv, jstring java_str)
JSBool jsj_ConvertJavaObjectToJSString (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jobject java_obj, jsval *vp)
JSBool jsj_ConvertJavaObjectToJSNumber (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jobject java_obj, jsval *vp)
JSBool jsj_ConvertJavaObjectToJSBoolean (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jobject java_obj, jsval *vp)
JSBool jsj_ConvertJavaObjectToJSValue (JSContext *cx, JNIEnv *jEnv, jobject java_obj, jsval *vp)
JSBool jsj_ConvertJavaValueToJSValue (JSContext *cx, JNIEnv *jEnv, JavaSignature *signature, jvalue *java_value, jsval *vp)

Define Documentation

#define jbyte_MAX_VALUE   127.0

Definition at line 333 of file jsj_convert.c.

#define jbyte_MIN_VALUE   -128.0

Definition at line 334 of file jsj_convert.c.

#define jchar_MAX_VALUE   65535.0

Definition at line 335 of file jsj_convert.c.

Definition at line 336 of file jsj_convert.c.

#define jint_MAX_VALUE   2147483647.0

Definition at line 339 of file jsj_convert.c.

#define jint_MIN_VALUE   -2147483648.0

Definition at line 340 of file jsj_convert.c.

#define jlong_MAX_VALUE   9223372036854775807.0

Definition at line 341 of file jsj_convert.c.

#define jlong_MIN_VALUE   -9223372036854775808.0

Definition at line 342 of file jsj_convert.c.

#define jlong_to_jdouble (   lvalue)    ((jdouble) lvalue)

Definition at line 435 of file jsj_convert.c.

#define JSDOUBLE_HI32 (   x)    (((uint32 *)&(x))[0])

Definition at line 61 of file jsj_convert.c.

#define JSDOUBLE_HI32_EXPMASK   0x7ff00000

Definition at line 65 of file jsj_convert.c.

#define JSDOUBLE_HI32_MANTMASK   0x000fffff

Definition at line 66 of file jsj_convert.c.

#define JSDOUBLE_HI32_SIGNBIT   0x80000000

Definition at line 64 of file jsj_convert.c.

Value:

Definition at line 72 of file jsj_convert.c.

#define JSDOUBLE_LO32 (   x)    (((uint32 *)&(x))[1])

Definition at line 62 of file jsj_convert.c.

#define jshort_MAX_VALUE   32767.0

Definition at line 337 of file jsj_convert.c.

#define jshort_MIN_VALUE   -32768.0

Definition at line 338 of file jsj_convert.c.

#define JSVAL_TO_INTEGRAL_JVALUE (   type_name,
  member_name,
  member_type,
  jsval,
  java_value 
)

Definition at line 345 of file jsj_convert.c.


Function Documentation

static JSBool convert_js_array_to_java_array ( JSContext cx,
JNIEnv jEnv,
JSObject js_array,
JavaSignature *  signature,
jobject java_valuep 
) [static]

Definition at line 103 of file jsj_convert.c.

{
    jsuint i;
    jsval js_val;
    jsuint length;
    jclass component_class;
    jarray java_array;
    JavaSignature *array_component_signature;

    if (!JS_GetArrayLength(cx, js_array, &length))
        return JS_FALSE;

    /* Get the Java class of each element of the array */
    array_component_signature = signature->array_component_signature;
    component_class = array_component_signature->java_class;

    /* Create a new empty Java array with the same length as the JS array */
    java_array = (*jEnv)->CallStaticObjectMethod(jEnv, jlrArray, jlrArray_newInstance,
                                                 component_class, length);
    if (!java_array) {
        jsj_ReportJavaError(cx, jEnv, "Error while constructing empty array of %s",
                            jsj_GetJavaClassName(cx, jEnv, component_class));
        return JS_FALSE;
    }

    /* Convert each element of the JS array to an element of the Java array.
       If an error occurs, there is no need to worry about releasing the
       individual elements of the Java array - they will eventually be GC'ed
       by the JVM. */
    for (i = 0; i < length; i++) {
        if (!JS_LookupElement(cx, js_array, i, &js_val))
            return JS_FALSE;

        if (!jsj_SetJavaArrayElement(cx, jEnv, java_array, i, array_component_signature, js_val))
            return JS_FALSE;
    }

    /* Return the result array */
    *java_valuep = java_array;
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool convert_js_obj_to_JSObject_wrapper ( JSContext cx,
JNIEnv jEnv,
JSObject js_obj,
JavaSignature *  signature,
int cost,
jobject java_value 
) [static]

Definition at line 77 of file jsj_convert.c.

{
    if (!njJSObject) {
        if (java_value)
            JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL, 
                                                JSJMSG_CANT_LOAD_JSOBJECT);
        return JS_FALSE;
    }

    if (!(*jEnv)->IsAssignableFrom(jEnv, njJSObject, signature->java_class))
        return JS_FALSE;

    if (!java_value)
        return JS_TRUE;

    *java_value = jsj_WrapJSObject(cx, jEnv, js_obj);

    return (*java_value != NULL);   
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJavaObjectToJSBoolean ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jobject  java_obj,
jsval vp 
)

Definition at line 722 of file jsj_convert.c.

{
    jboolean b;
    jmethodID booleanValue;
    jclass java_class;
    
    /* Null converts to false. */
    if (!java_obj) {
        *vp = JSVAL_FALSE;
        return JS_TRUE;
    }
    java_class = class_descriptor->java_class;
    booleanValue = (*jEnv)->GetMethodID(jEnv, java_class, "booleanValue", "()Z");

    /* Non-null Java object does not have a booleanValue() method, so
       it converts to true. */
    if (!booleanValue) {
        (*jEnv)->ExceptionClear(jEnv);
        *vp = JSVAL_TRUE;
        return JS_TRUE;
    }

    b = (*jEnv)->CallBooleanMethod(jEnv, java_obj, booleanValue);
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "booleanValue() method failed");
        return JS_FALSE;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJavaObjectToJSNumber ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jobject  java_obj,
jsval vp 
)

Definition at line 675 of file jsj_convert.c.

{
    jdouble d;
    jmethodID doubleValue;
    jclass java_class;

    java_class = class_descriptor->java_class;
    doubleValue = (*jEnv)->GetMethodID(jEnv, java_class, "doubleValue", "()D");
    if (!doubleValue) {
        /* There is no doubleValue() method for the object.  Try toString()
           instead and the JS engine will attempt to convert the result to
           a number. */
        (*jEnv)->ExceptionClear(jEnv);
        return jsj_ConvertJavaObjectToJSString(cx, jEnv, class_descriptor,
                                               java_obj, vp);
    }
    /*
     * Sun Java-Plugin team work around bug to be fixed in JRE1.5, where GetMethodID 
     * called with a non-existent method name returns a non-null result.
     * See Mozilla bug 201164.
     */
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "No doubleValue() method for class %s!",
            class_descriptor->name);
        return JS_FALSE;
    }
    
    d = (*jEnv)->CallDoubleMethod(jEnv, java_obj, doubleValue);
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "doubleValue() method failed");
        return JS_FALSE;

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJavaObjectToJSString ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jobject  java_obj,
jsval vp 
)

Definition at line 617 of file jsj_convert.c.

{
    JSString *js_str;
    jstring java_str;
    jmethodID toString;
    jclass java_class;
    
    /* Create a Java string, unless java_obj is already a java.lang.String */
    if ((*jEnv)->IsInstanceOf(jEnv, java_obj, jlString)) {

        /* Extract Unicode from java.lang.String instance and convert to JS string */
        js_str = jsj_ConvertJavaStringToJSString(cx, jEnv, java_obj);
        if (!js_str)
            return JS_FALSE;
        *vp = STRING_TO_JSVAL(js_str);
        return JS_TRUE;
    }
    
    java_class = class_descriptor->java_class;
    toString = (*jEnv)->GetMethodID(jEnv, java_class, "toString",
        "()Ljava/lang/String;");
    if (!toString) {
        /* All Java objects have a toString method */
        jsj_UnexpectedJavaError(cx, jEnv, "No toString() method for class %s!",
            class_descriptor->name);
        return JS_FALSE;
    }
    java_str = (*jEnv)->CallObjectMethod(jEnv, java_obj, toString);
    if (!java_str) {
        jsj_ReportJavaError(cx, jEnv, "toString() method failed");
        return JS_FALSE;
    }
    
    /* Extract Unicode from java.lang.String instance and convert to JS string */
    js_str = jsj_ConvertJavaStringToJSString(cx, jEnv, java_str);
    if (!js_str) {
        (*jEnv)->DeleteLocalRef(jEnv, java_str);
        return JS_FALSE;
    }

    *vp = STRING_TO_JSVAL(js_str);

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJavaObjectToJSValue ( JSContext cx,
JNIEnv jEnv,
jobject  java_obj,
jsval vp 
)

Definition at line 760 of file jsj_convert.c.

{
    jclass java_class;
    JSObject *js_obj;

    /* A null in Java-land is also null in JS */
    if (!java_obj) {
        *vp = JSVAL_NULL;
        return JS_TRUE;
    }

    java_class = (*jEnv)->GetObjectClass(jEnv, java_obj);

    /*
     * If it's an instance of netscape.javascript.JSObject, i.e. a wrapper
     * around a JS object that has been passed into the Java world, unwrap
     * it to obtain the original JS object.
     */
     if (njJSObject && (*jEnv)->IsInstanceOf(jEnv, java_obj, njJSObject)) {
#ifdef PRESERVE_JSOBJECT_IDENTITY
#if JS_BYTES_PER_LONG == 8
        js_obj = (JSObject *)((*jEnv)->GetLongField(jEnv, java_obj, njJSObject_long_internal));
#else
        js_obj = (JSObject *)((*jEnv)->GetIntField(jEnv, java_obj, njJSObject_internal));
#endif
#else
        js_obj = jsj_UnwrapJSObjectWrapper(jEnv, java_obj);
#endif
              /* NULL is actually a valid value. It means 'null'.

        JS_ASSERT(js_obj);
        if (!js_obj)
            goto error;
              */

        *vp = OBJECT_TO_JSVAL(js_obj);
        goto done;
     }

    /* otherwise, wrap it inside a JavaObject */
    js_obj = jsj_WrapJavaObject(cx, jEnv, java_obj, java_class);
    if (!js_obj)
        goto error;
    *vp = OBJECT_TO_JSVAL(js_obj);

done:
    (*jEnv)->DeleteLocalRef(jEnv, java_class);
    return JS_TRUE;

error:

Here is the call graph for this function:

Here is the caller graph for this function:

JSString* jsj_ConvertJavaStringToJSString ( JSContext cx,
JNIEnv jEnv,
jstring  java_str 
)

Definition at line 586 of file jsj_convert.c.

{
    JSString *js_str;
    jboolean is_copy;
    const jchar *ucs2_str;
    jsize ucs2_str_len;

    ucs2_str_len = (*jEnv)->GetStringLength(jEnv, java_str);
    ucs2_str = (*jEnv)->GetStringChars(jEnv, java_str, &is_copy);
    if (!ucs2_str) {
        jsj_UnexpectedJavaError(cx, jEnv,
                                "Unable to extract native Unicode from Java string");
        return NULL;
    }

    /* The string data passed into JS_NewUCString() is
       not copied, so make a copy of the Unicode character vector. */
    js_str = JS_NewUCStringCopyN(cx, ucs2_str, ucs2_str_len);

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJavaValueToJSValue ( JSContext cx,
JNIEnv jEnv,
JavaSignature *  signature,
jvalue java_value,
jsval vp 
)

Definition at line 822 of file jsj_convert.c.

{
    int32 ival32;

    switch (signature->type) {
    case JAVA_SIGNATURE_VOID:
        *vp = JSVAL_VOID;
        return JS_TRUE;

    case JAVA_SIGNATURE_BYTE:
        *vp = INT_TO_JSVAL((jsint)java_value->b);
        return JS_TRUE;

    case JAVA_SIGNATURE_CHAR:
        *vp = INT_TO_JSVAL((jsint)java_value->c);
        return JS_TRUE;

    case JAVA_SIGNATURE_SHORT:
        *vp = INT_TO_JSVAL((jsint)java_value->s);
        return JS_TRUE;

    case JAVA_SIGNATURE_INT:
        ival32 = java_value->i;
        if (INT_FITS_IN_JSVAL(ival32)) {
            *vp = INT_TO_JSVAL((jsint) ival32);
            return JS_TRUE;
        } else {
            return JS_NewDoubleValue(cx, ival32, vp);
        }

    case JAVA_SIGNATURE_BOOLEAN:
        *vp = BOOLEAN_TO_JSVAL((JSBool) java_value->z);
        return JS_TRUE;

    case JAVA_SIGNATURE_LONG:
        return JS_NewDoubleValue(cx, jlong_to_jdouble(java_value->j), vp);
  
    case JAVA_SIGNATURE_FLOAT:
        return JS_NewDoubleValue(cx, java_value->f, vp);

    case JAVA_SIGNATURE_DOUBLE:
        return JS_NewDoubleValue(cx, java_value->d, vp);

    case JAVA_SIGNATURE_UNKNOWN:
        JS_ASSERT(0);
        return JS_FALSE;
        
    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(signature->type));
        return jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_value->l, vp);

Here is the call graph for this function:

Here is the caller graph for this function:

jstring jsj_ConvertJSStringToJavaString ( JSContext cx,
JNIEnv jEnv,
JSString js_str 
)

Definition at line 148 of file jsj_convert.c.

{
    jstring result;
    result = (*jEnv)->NewString(jEnv, JS_GetStringChars(js_str),
                                JS_GetStringLength(js_str));
    if (!result) {
        jsj_UnexpectedJavaError(cx, jEnv, "Couldn't construct instance "
                                          "of java.lang.String");
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJSValueToJavaObject ( JSContext cx,
JNIEnv jEnv,
jsval  v,
JavaSignature *  signature,
int cost,
jobject java_value,
JSBool is_local_refp 
)

Definition at line 169 of file jsj_convert.c.

{
    JSString *jsstr;
    jclass target_java_class;
    
    JS_ASSERT(IS_REFERENCE_TYPE(signature->type));

    /* Initialize to default case, in which no new Java object is
       synthesized to perform the conversion and, therefore, no JNI local
       references are being held. */
    *is_local_refp = JS_FALSE;

    /* Get the Java type of the target value */
    target_java_class = signature->java_class;
    
    if (JSVAL_IS_OBJECT(v)) {
        JSObject *js_obj = JSVAL_TO_OBJECT(v);
        
        /* JS null is always assignable to a Java object */
        if (!js_obj) {
            if (java_value)
                *java_value = NULL;
            return JS_TRUE;
        }
        
        if (JS_InstanceOf(cx, js_obj, &JavaObject_class, 0) ||
            JS_InstanceOf(cx, js_obj, &JavaArray_class, 0)) {
            
            /* The source value is a Java object wrapped inside a JavaScript
               object.  Unwrap the JS object and return the original Java
               object if it's class makes it assignment-compatible with the
               target class using Java's assignability rules. */
            JavaObjectWrapper *java_wrapper = JS_GetPrivate(cx, js_obj);
            jobject java_obj = java_wrapper->java_obj;
            
            if ((*jEnv)->IsInstanceOf(jEnv, java_obj, target_java_class)) {
                if (java_value)
                    *java_value = java_obj;
                return JS_TRUE;
            }
            
            /* Fall through, to attempt conversion to a Java string */
            
        } else if (JS_InstanceOf(cx, js_obj, &JavaClass_class, 0)) {
            /* We're dealing with the reflection of a Java class */
            JavaClassDescriptor *java_class_descriptor = JS_GetPrivate(cx, js_obj);
            
            /* Check if target type is java.lang.Class class */
            if ((*jEnv)->IsAssignableFrom(jEnv, jlClass, target_java_class)) {
                if (java_value)
                    *java_value = java_class_descriptor->java_class;
                return JS_TRUE;
            }
            
            /* Check if target type is netscape.javascript.JSObject wrapper class */
            if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value)) {
                if (java_value && *java_value)
                    *is_local_refp = JS_TRUE;
                return JS_TRUE;
            }
            
            /* Fall through, to attempt conversion to a Java string */
            
        } else if (JS_InstanceOf(cx, js_obj, &JavaMember_class, 0)) {

            if (!JS_ConvertValue(cx, v, JSTYPE_OBJECT, &v))
                return JS_FALSE;
            return jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost,
                                                  java_value, is_local_refp);

        /* JS Arrays are converted, element by element, to Java arrays */
        } else if (JS_IsArrayObject(cx, js_obj) && (signature->type == JAVA_SIGNATURE_ARRAY)) {
            if (convert_js_array_to_java_array(cx, jEnv, js_obj, signature, java_value)) {
                if (java_value && *java_value)
                    *is_local_refp = JS_TRUE;
                return JS_TRUE;
            }
            return JS_FALSE;

        } else {
            /* Otherwise, see if the target type is the  netscape.javascript.JSObject
               wrapper class or one of its subclasses, in which case a
               reference is passed to the original JS object by wrapping it
               inside an instance of netscape.javascript.JSObject */
            if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value))             {
                if (java_value && *java_value)
                    *is_local_refp = JS_TRUE;
                return JS_TRUE;
            }
            
            /* Fall through, to attempt conversion to a Java string */
        }
        
    } else if (JSVAL_IS_NUMBER(v)) {
        /* JS numbers, integral or not, can be converted to instances of java.lang.Double */
        if ((*jEnv)->IsAssignableFrom(jEnv, jlDouble, target_java_class)) {
            if (java_value) {
                jsdouble d;
                if (!JS_ValueToNumber(cx, v, &d))
                    goto conversion_error;
                *java_value = (*jEnv)->NewObject(jEnv, jlDouble, jlDouble_Double, d);
                if (*java_value) {
                    *is_local_refp = JS_TRUE;
                } else {
                    jsj_UnexpectedJavaError(cx, jEnv,
                        "Couldn't construct instance of java.lang.Double");
                    return JS_FALSE;
                }
            }

            return JS_TRUE;
        }
        /* Fall through, to attempt conversion to a java.lang.String ... */
        
    } else if (JSVAL_IS_BOOLEAN(v)) {
        /* JS boolean values can be converted to instances of java.lang.Boolean */
        if ((*jEnv)->IsAssignableFrom(jEnv, jlBoolean, target_java_class)) {
            if (java_value) {
                JSBool b;
                if (!JS_ValueToBoolean(cx, v, &b))
                    goto conversion_error;
                *java_value =
                    (*jEnv)->NewObject(jEnv, jlBoolean, jlBoolean_Boolean, b);
                if (*java_value) {
                    *is_local_refp = JS_TRUE;
                } else {
                    jsj_UnexpectedJavaError(cx, jEnv, "Couldn't construct instance " 
                        "of java.lang.Boolean");
                    return JS_FALSE;
                }
            }

            return JS_TRUE;
        }
        /* Fall through, to attempt conversion to a java.lang.String ... */
    }
    
    /* If the source JS type is either a string or undefined, or if no conversion
       is possible from a number, boolean or JS object, see if the target type is
       java.lang.String */
    if ((*jEnv)->IsAssignableFrom(jEnv, jlString, target_java_class)) {
        
        /* Convert to JS string, if necessary, and then to a Java Unicode string */
        jsstr = JS_ValueToString(cx, v);
        if (jsstr) {
            if (java_value) {
                *java_value = jsj_ConvertJSStringToJavaString(cx, jEnv, jsstr);
                if (*java_value) {
                    *is_local_refp = JS_TRUE;
                } else {
                    return JS_FALSE;
                }
            }

            return JS_TRUE;
        }
    }
    
conversion_error:
    return JS_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ConvertJSValueToJavaValue ( JSContext cx,
JNIEnv jEnv,
jsval  v_arg,
JavaSignature *  signature,
int cost,
jvalue java_value,
JSBool is_local_refp 
)

Definition at line 452 of file jsj_convert.c.

{
    JavaSignatureChar type;
    jsval v;
    JSBool success = JS_FALSE;

    /* Initialize to default case, in which no new Java object is
       synthesized to perform the conversion and, therefore, no JNI local
       references are being held. */
    *is_local_refp = JS_FALSE;   
    
    type = signature->type;
    v = v_arg;
    switch (type) {
    case JAVA_SIGNATURE_BOOLEAN:
        if (!JSVAL_IS_BOOLEAN(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_BOOLEAN, &v))
                goto conversion_error;
            if (JSVAL_IS_VOID(v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value)
            java_value->z = (jboolean)(JSVAL_TO_BOOLEAN(v) == JS_TRUE);
        break;

    case JAVA_SIGNATURE_SHORT:
        JSVAL_TO_INTEGRAL_JVALUE(short, s, jshort, v, java_value);
        break;

    case JAVA_SIGNATURE_BYTE:
        JSVAL_TO_INTEGRAL_JVALUE(byte, b, jbyte, v, java_value);
        break;

    case JAVA_SIGNATURE_CHAR:
        /* A one-character string can be converted into a character */
        if (JSVAL_IS_STRING(v) && (JS_GetStringLength(JSVAL_TO_STRING(v)) == 1)) {
            v = INT_TO_JSVAL(*JS_GetStringChars(JSVAL_TO_STRING(v)));
        }
        JSVAL_TO_INTEGRAL_JVALUE(char, c, jchar, v, java_value);
        break;

    case JAVA_SIGNATURE_INT:
        JSVAL_TO_INTEGRAL_JVALUE(int, i, jint, v, java_value);
        break;

    case JAVA_SIGNATURE_LONG:
#if (defined(XP_OS2) && !defined(HAVE_LONG_LONG))
        JSVAL_TO_JLONG_JVALUE(j, jlong, v, java_value);
#else
        JSVAL_TO_INTEGRAL_JVALUE(long, j, jlong, v, java_value);
#endif
        break;
    
    case JAVA_SIGNATURE_FLOAT:
        if (!JSVAL_IS_NUMBER(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_NUMBER, &v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value) {
            if (JSVAL_IS_INT(v))
                java_value->f = (jfloat) JSVAL_TO_INT(v);
            else
                java_value->f = (jfloat) *JSVAL_TO_DOUBLE(v);
        }
        break;

    case JAVA_SIGNATURE_DOUBLE:
        if (!JSVAL_IS_NUMBER(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_NUMBER, &v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value) {
            if (JSVAL_IS_INT(v))
                java_value->d = (jdouble) JSVAL_TO_INT(v);
            else
                java_value->d = (jdouble) *JSVAL_TO_DOUBLE(v);
        }
        break;

    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(type));
        if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost,
            &java_value->l, is_local_refp))
            goto conversion_error;
        break;

    case JAVA_SIGNATURE_UNKNOWN:
    case JAVA_SIGNATURE_VOID:
        JS_ASSERT(0);
        return JS_FALSE;
    }

    /* Success */
    return JS_TRUE;

numeric_conversion_error:
    success = JS_TRUE;
    /* Fall through ... */

conversion_error:

    if (java_value) {
        const char *jsval_string;
        const char *class_name;
        JSString *jsstr;

        jsval_string = NULL;
        jsstr = JS_ValueToString(cx, v_arg);
        if (jsstr)
            jsval_string = JS_GetStringBytes(jsstr);
        if (!jsval_string)
            jsval_string = "";
        
        class_name = jsj_ConvertJavaSignatureToHRString(cx, signature);
        JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL, 
                             JSJMSG_CANT_CONVERT_JS, jsval_string,
                             class_name);

        return JS_FALSE;

Here is the call graph for this function:

Here is the caller graph for this function: