Back to index

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

Go to the source code of this file.

Functions

const char * jsj_GetJavaClassName (JSContext *cx, JNIEnv *jEnv, jclass java_class)
void jsj_MakeJNIClassname (char *class_name)
static JavaSignatureChar get_signature_type (JSContext *cx, JavaClassDescriptor *class_descriptor)
static JSBool is_java_array_class (JNIEnv *jEnv, jclass java_class)
static jclass get_java_array_component_class (JSContext *cx, JNIEnv *jEnv, jclass java_class)
static JSBool compute_java_class_signature (JSContext *cx, JNIEnv *jEnv, JavaSignature *signature)
static char get_jdk_signature_char (JavaSignatureChar type)
const char * jsj_ConvertJavaSignatureToString (JSContext *cx, JavaSignature *signature)
const char * jsj_ConvertJavaSignatureToHRString (JSContext *cx, JavaSignature *signature)
static void destroy_java_member_descriptor (JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor *member_descriptor)
static void destroy_class_member_descriptors (JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor *member_descriptor)
static void destroy_class_descriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
static JavaClassDescriptornew_class_descriptor (JSContext *cx, JNIEnv *jEnv, jclass java_class)
 enumerate_remove_java_class (JSJHashEntry *he, JSIntn i, void *arg)
void jsj_DiscardJavaClassReflections (JNIEnv *jEnv)
JavaClassDescriptorjsj_GetJavaClassDescriptor (JSContext *cx, JNIEnv *jEnv, jclass java_class)
void jsj_ReleaseJavaClassDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
static JSBool reflect_java_methods_and_fields (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, JSBool reflect_statics_only)
JavaMemberDescriptorjsj_GetClassStaticMembers (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_GetClassInstanceMembers (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_LookupJavaStaticMemberDescriptorById (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jsid id)
JavaMemberDescriptorjsj_GetJavaStaticMemberDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jstring member_name_jstr)
JavaMemberDescriptorjsj_GetJavaClassConstructors (JSContext *cx, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_LookupJavaClassConstructors (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_LookupJavaMemberDescriptorById (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jsid id)
JavaMemberDescriptorjsj_GetJavaMemberDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jstring member_name_jstr)
JSBool jsj_InitJavaClassReflectionsTable ()

Variables

static JSJHashTablejava_class_reflections

Function Documentation

static JSBool compute_java_class_signature ( JSContext cx,
JNIEnv jEnv,
JavaSignature *  signature 
) [static]

Definition at line 207 of file jsj_class.c.

{
    jclass java_class = signature->java_class;

    if (is_java_array_class(jEnv, java_class)) {
        jclass component_class;
        
        signature->type = JAVA_SIGNATURE_ARRAY;

        component_class = get_java_array_component_class(cx, jEnv, java_class);
        if (!component_class)
            return JS_FALSE;

        signature->array_component_signature =
            jsj_GetJavaClassDescriptor(cx, jEnv, component_class);
        if (!signature->array_component_signature) {
            (*jEnv)->DeleteLocalRef(jEnv, component_class);
            return JS_FALSE;
        }
    } else {
        signature->type = get_signature_type(cx, signature);
    }
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void destroy_class_descriptor ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor 
) [static]

Definition at line 354 of file jsj_class.c.

{
    JS_FREE_IF(cx, (char *)class_descriptor->name);
    if (class_descriptor->java_class)
        (*jEnv)->DeleteGlobalRef(jEnv, class_descriptor->java_class);

    if (class_descriptor->array_component_signature)
        jsj_ReleaseJavaClassDescriptor(cx, jEnv, class_descriptor->array_component_signature);

    destroy_class_member_descriptors(cx, jEnv, class_descriptor->instance_members);
    destroy_class_member_descriptors(cx, jEnv, class_descriptor->static_members);
    destroy_class_member_descriptors(cx, jEnv, class_descriptor->constructors);
    JS_free(cx, class_descriptor);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void destroy_class_member_descriptors ( JSContext cx,
JNIEnv jEnv,
JavaMemberDescriptor member_descriptor 
) [static]

Definition at line 342 of file jsj_class.c.

{
    JavaMemberDescriptor *next_member;
    
    while (member_descriptor) {
        next_member = member_descriptor->next;
        destroy_java_member_descriptor(cx, jEnv, member_descriptor);
        member_descriptor = next_member;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void destroy_java_member_descriptor ( JSContext cx,
JNIEnv jEnv,
JavaMemberDescriptor member_descriptor 
) [static]

Definition at line 321 of file jsj_class.c.

{
    JavaMethodSpec *method, *next_method;
    if (member_descriptor->field)
        jsj_DestroyFieldSpec(cx, jEnv, member_descriptor->field);

    method = member_descriptor->methods;
    while (method) {
        next_method = method->next;
        jsj_DestroyMethodSpec(cx, jEnv, method);
        method = next_method;
    }

    if (member_descriptor->invoke_func_obj)
        JS_RemoveRoot(cx, &member_descriptor->invoke_func_obj);

    JS_FREE_IF(cx, (char *)member_descriptor->name);
    JS_free(cx, member_descriptor);
}

Here is the call graph for this function:

Here is the caller graph for this function:

enumerate_remove_java_class ( JSJHashEntry he,
JSIntn  i,
void arg 
)

Definition at line 410 of file jsj_class.c.

{
    JSJavaThreadState *jsj_env = (JSJavaThreadState *)arg;
    JavaClassDescriptor *class_descriptor;

    class_descriptor = (JavaClassDescriptor*)he->value;

    destroy_class_descriptor(jsj_env->cx, jsj_env->jEnv, class_descriptor);

    return HT_ENUMERATE_REMOVE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static jclass get_java_array_component_class ( JSContext cx,
JNIEnv jEnv,
jclass  java_class 
) [static]

Definition at line 189 of file jsj_class.c.

{
    jclass result;
    result = (*jEnv)->CallObjectMethod(jEnv, java_class, jlClass_getComponentType);
    if (!result) {
        jsj_UnexpectedJavaError(cx, jEnv,
                                "Can't get Java array component class using "
                                "java.lang.Class.getComponentType()");
        return NULL;
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char get_jdk_signature_char ( JavaSignatureChar  type) [static]

Definition at line 237 of file jsj_class.c.

{
    return "XVZCBSIJFD[LLLLLL"[(int)type];
}

Here is the caller graph for this function:

static JavaSignatureChar get_signature_type ( JSContext cx,
JavaClassDescriptor class_descriptor 
) [static]

Definition at line 129 of file jsj_class.c.

{
    JavaSignatureChar type;
    const char *java_class_name;

    /* Get UTF8 encoding of class name */
    java_class_name = class_descriptor->name;
    JS_ASSERT(java_class_name);
    if (!java_class_name)
        return JAVA_SIGNATURE_UNKNOWN;

    if (!strcmp(java_class_name, "byte"))
        type = JAVA_SIGNATURE_BYTE;
    else if (!strcmp(java_class_name, "char"))
        type = JAVA_SIGNATURE_CHAR;
    else if (!strcmp(java_class_name, "float"))
        type = JAVA_SIGNATURE_FLOAT;
    else if (!strcmp(java_class_name, "double"))
        type = JAVA_SIGNATURE_DOUBLE;
    else if (!strcmp(java_class_name, "int"))
        type = JAVA_SIGNATURE_INT;
    else if (!strcmp(java_class_name, "long"))
        type = JAVA_SIGNATURE_LONG;
    else if (!strcmp(java_class_name, "short"))
        type = JAVA_SIGNATURE_SHORT;
    else if (!strcmp(java_class_name, "boolean"))
        type = JAVA_SIGNATURE_BOOLEAN;
    else if (!strcmp(java_class_name, "void"))
        type = JAVA_SIGNATURE_VOID;
    else if (!strcmp(java_class_name, "java.lang.Boolean"))
        type = JAVA_SIGNATURE_JAVA_LANG_BOOLEAN;
    else if (!strcmp(java_class_name, "java.lang.Double"))
        type = JAVA_SIGNATURE_JAVA_LANG_DOUBLE;
    else if (!strcmp(java_class_name, "java.lang.String"))
        type = JAVA_SIGNATURE_JAVA_LANG_STRING;
    else if (!strcmp(java_class_name, "java.lang.Object"))
        type = JAVA_SIGNATURE_JAVA_LANG_OBJECT;
    else if (!strcmp(java_class_name, "java.lang.Class"))
        type = JAVA_SIGNATURE_JAVA_LANG_CLASS;
    else if (!strcmp(java_class_name, "netscape.javascript.JSObject"))
        type = JAVA_SIGNATURE_NETSCAPE_JAVASCRIPT_JSOBJECT;
    else
        type = JAVA_SIGNATURE_OBJECT;
    return type;
}

Here is the caller graph for this function:

static JSBool is_java_array_class ( JNIEnv jEnv,
jclass  java_class 
) [static]

Definition at line 176 of file jsj_class.c.

{
    return (*jEnv)->CallBooleanMethod(jEnv, java_class, jlClass_isArray);
}

Here is the caller graph for this function:

const char* jsj_ConvertJavaSignatureToHRString ( JSContext cx,
JavaSignature *  signature 
)

Definition at line 291 of file jsj_class.c.

{
    char *sig;
    JavaSignature *acs;

    if (signature->type == JAVA_SIGNATURE_ARRAY) {
        /* An array class */
        const char *component_signature_string;
        acs = signature->array_component_signature;
        component_signature_string =
            jsj_ConvertJavaSignatureToHRString(cx, acs);
        if (!component_signature_string)
            return NULL;
        sig = JS_smprintf("%s[]", component_signature_string);
        JS_free(cx, (char*)component_signature_string);

    } else {
        /* A primitive class or a non-array object class */
        sig = JS_strdup(cx, signature->name);
    }

    if (!sig) {
        JS_ReportOutOfMemory(cx);
        return NULL;
    }
    return sig;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* jsj_ConvertJavaSignatureToString ( JSContext cx,
JavaSignature *  signature 
)

Definition at line 250 of file jsj_class.c.

{
    char *sig;

    if (IS_OBJECT_TYPE(signature->type)) {
        /* A non-array object class */
        sig = JS_smprintf("L%s;", signature->name);
        if (sig)
            jsj_MakeJNIClassname(sig);

    } else if (signature->type == JAVA_SIGNATURE_ARRAY) {
        /* An array class */
        const char *component_signature_string;

        component_signature_string =
            jsj_ConvertJavaSignatureToString(cx, signature->array_component_signature);
        if (!component_signature_string)
            return NULL;
        sig = JS_smprintf("[%s", component_signature_string);
        JS_free(cx, (char*)component_signature_string);

    } else {
        /* A primitive class */
        sig = JS_smprintf("%c", get_jdk_signature_char(signature->type));
    }

    if (!sig) {
        JS_ReportOutOfMemory(cx);
        return NULL;
    }
    return sig;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 426 of file jsj_class.c.

{
    JSJavaThreadState *jsj_env;
    char *err_msg;
    JSContext *cx;

    /* Get the per-thread state corresponding to the current Java thread */
    jsj_env = jsj_MapJavaThreadToJSJavaThreadState(jEnv, &err_msg);
    JS_ASSERT(jsj_env);
    if (!jsj_env)
        return;

    /* Get the JSContext that we're supposed to use for this Java thread */
    cx = jsj_env->cx;
    if (!cx) {
        /* We called spontaneously into JS from Java, rather than from JS into
           Java and back into JS.  Invoke a callback to obtain/create a
           JSContext for us to use. */
        if (JSJ_callbacks->map_jsj_thread_to_js_context) {
#ifdef OJI
            cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
                                                             NULL, /* FIXME: What should this argument be ? */
                                                             jEnv, &err_msg);
#else
            cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
                                                             jEnv, &err_msg);
#endif
            if (!cx)
                return;
        } else {
            err_msg = JS_smprintf("Unable to find/create JavaScript execution "
                                  "context for JNI thread 0x%08x", jEnv);
            jsj_LogError(err_msg);
            free(err_msg);
            return;
        }
    }

    if (java_class_reflections) {
        JSJ_HashTableEnumerateEntries(java_class_reflections,
                                      enumerate_remove_java_class,
                                      (void*)jsj_env);
        JSJ_HashTableDestroy(java_class_reflections);
        java_class_reflections = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 596 of file jsj_class.c.

{
    if (class_descriptor->instance_members_reflected != REFLECT_COMPLETE)
        reflect_java_methods_and_fields(cx, jEnv, class_descriptor, JS_FALSE);
    return class_descriptor->instance_members;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 586 of file jsj_class.c.

{
    if (class_descriptor->static_members_reflected != REFLECT_COMPLETE)
        reflect_java_methods_and_fields(cx, jEnv, class_descriptor, JS_TRUE);
    return class_descriptor->static_members;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 657 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;

    if (class_descriptor->constructors)
        return class_descriptor->constructors;

    member_descriptor = JS_malloc(cx, sizeof(JavaMemberDescriptor));
    if (!member_descriptor)
        return NULL;
    memset(member_descriptor, 0, sizeof(JavaMemberDescriptor));

    member_descriptor->name = JS_strdup(cx, "<init>");
    if (!member_descriptor->name) {
        JS_free(cx, member_descriptor);
        return NULL;
    }

    class_descriptor->constructors = member_descriptor;

    return member_descriptor;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JavaClassDescriptor* jsj_GetJavaClassDescriptor ( JSContext cx,
JNIEnv jEnv,
jclass  java_class 
)

Definition at line 474 of file jsj_class.c.

{
    JavaClassDescriptor *class_descriptor = NULL;

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(java_class_reflections_monitor);
#endif

    if (java_class_reflections) {
        class_descriptor = JSJ_HashTableLookup(java_class_reflections,
                                               (const void *)java_class,
                                               (void*)jEnv);
    }
    if (!class_descriptor) {
        class_descriptor = new_class_descriptor(cx, jEnv, java_class);

#ifdef JSJ_THREADSAFE
        PR_ExitMonitor(java_class_reflections_monitor);
#endif
        return class_descriptor;
    }

#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(java_class_reflections_monitor);
#endif

    JS_ASSERT(class_descriptor->ref_count > 0);
    class_descriptor->ref_count++;
    return class_descriptor;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* jsj_GetJavaClassName ( JSContext cx,
JNIEnv jEnv,
jclass  java_class 
)

Definition at line 76 of file jsj_class.c.

{
    jstring java_class_name_jstr;
    const char *java_class_name;

    /* Get java.lang.String object containing class name */
    java_class_name_jstr =
        (*jEnv)->CallObjectMethod(jEnv, java_class, jlClass_getName);

    if (!java_class_name_jstr)
        goto error;

    /* Fix bugzilla #183092
     * It is necessary to check Exception from JPI
     * even though java_class_name_jstr != null */
#ifdef XP_UNIX
    if ((*jEnv)->ExceptionOccurred(jEnv))
        goto error;
#endif

    /* Convert to UTF8 encoding and copy */
    java_class_name = jsj_DupJavaStringUTF(cx, jEnv, java_class_name_jstr);

    (*jEnv)->DeleteLocalRef(jEnv, java_class_name_jstr);
    return java_class_name;

error:
    jsj_UnexpectedJavaError(cx, jEnv, "Can't get Java class name using"
                                      "java.lang.Class.getName()");
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JavaMemberDescriptor* jsj_GetJavaMemberDescriptor ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jstring  member_name_jstr 
)

Definition at line 707 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;
    jsid id;

    if (!JavaStringToId(cx, jEnv, member_name_jstr, &id))
        return NULL;

    member_descriptor = jsj_LookupJavaMemberDescriptorById(cx, jEnv, class_descriptor, id);
    if (member_descriptor)
        return member_descriptor;

    member_descriptor = JS_malloc(cx, sizeof(JavaMemberDescriptor));
    if (!member_descriptor)
        return NULL;
    memset(member_descriptor, 0, sizeof(JavaMemberDescriptor));

    member_descriptor->name = jsj_DupJavaStringUTF(cx, jEnv, member_name_jstr);
    if (!member_descriptor->name) {
        JS_free(cx, member_descriptor);
        return NULL;
    }
    member_descriptor->id = id;

    member_descriptor->next = class_descriptor->instance_members;
    class_descriptor->instance_members = member_descriptor;

    return member_descriptor;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JavaMemberDescriptor* jsj_GetJavaStaticMemberDescriptor ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jstring  member_name_jstr 
)

Definition at line 623 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;
    jsid id;

    if (!JavaStringToId(cx, jEnv, member_name_jstr, &id))
        return NULL;

    member_descriptor = jsj_LookupJavaStaticMemberDescriptorById(cx, jEnv, class_descriptor, id);
    if (member_descriptor)
        return member_descriptor;

    member_descriptor = JS_malloc(cx, sizeof(JavaMemberDescriptor));
    if (!member_descriptor)
        return NULL;
    memset(member_descriptor, 0, sizeof(JavaMemberDescriptor));

    member_descriptor->name = jsj_DupJavaStringUTF(cx, jEnv, member_name_jstr);
    if (!member_descriptor->name) {
        JS_free(cx, member_descriptor);
        return NULL;
    }
    member_descriptor->id = id;

    member_descriptor->next = class_descriptor->static_members;
    class_descriptor->static_members = member_descriptor;

    return member_descriptor;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 741 of file jsj_class.c.

{
    if (!java_class_reflections) {
        java_class_reflections =
            JSJ_NewHashTable(64, jsj_HashJavaObject, jsj_JavaObjectComparator,
                            NULL, NULL, NULL);

        if (!java_class_reflections)
            return JS_FALSE;

#ifdef JSJ_THREADSAFE
        java_class_reflections_monitor =
                (struct PRMonitor *) PR_NewMonitor();
        if (!java_class_reflections_monitor)
            return JS_FALSE;

        java_reflect_monitor =
                (struct PRMonitor *) PR_NewMonitor();
        if (!java_reflect_monitor)
            return JS_FALSE;
#endif
    }
    
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 682 of file jsj_class.c.

{
    if (class_descriptor->static_members_reflected != REFLECT_COMPLETE)
        reflect_java_methods_and_fields(cx, jEnv, class_descriptor, JS_TRUE);
    return class_descriptor->constructors;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 691 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;

    member_descriptor = jsj_GetClassInstanceMembers(cx, jEnv, class_descriptor);
    while (member_descriptor) {
        if (id == member_descriptor->id)
            return member_descriptor;
        member_descriptor = member_descriptor->next;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 606 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;

    member_descriptor = jsj_GetClassStaticMembers(cx, jEnv, class_descriptor);
    while (member_descriptor) {
        if (id == member_descriptor->id)
            return member_descriptor;
        member_descriptor = member_descriptor->next;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void jsj_MakeJNIClassname ( char *  class_name)

Definition at line 114 of file jsj_class.c.

{
    char * c;
    for (c = class_name; *c; c++)
        if (*c == '.')
            *c = '/';
}

Here is the caller graph for this function:

void jsj_ReleaseJavaClassDescriptor ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor 
)

Definition at line 506 of file jsj_class.c.

{
#if 0
    /* The ref-counting code doesn't work very well because cycles in the data
       structures routinely lead to uncollectible JavaClassDescriptor's.  Skip it. */
    JS_ASSERT(class_descriptor->ref_count >= 1);
    if (!--class_descriptor->ref_count) {
        JSJ_HashTableRemove(java_class_reflections,
                            class_descriptor->java_class, (void*)jEnv);
        destroy_class_descriptor(cx, jEnv, class_descriptor);
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JavaClassDescriptor* new_class_descriptor ( JSContext cx,
JNIEnv jEnv,
jclass  java_class 
) [static]

Definition at line 370 of file jsj_class.c.

{
    JavaClassDescriptor *class_descriptor;

    class_descriptor = (JavaClassDescriptor *)JS_malloc(cx, sizeof(JavaClassDescriptor));
    if (!class_descriptor)
        return NULL;
    memset(class_descriptor, 0, sizeof(JavaClassDescriptor));

    class_descriptor->name = jsj_GetJavaClassName(cx, jEnv, java_class);
    if (!class_descriptor->name)
        goto error;

    java_class = (*jEnv)->NewGlobalRef(jEnv, java_class);
    if (!java_class) {
        jsj_UnexpectedJavaError(cx, jEnv, "Unable to reference Java class");
        goto error;
    }
    class_descriptor->java_class = java_class;

    if (!compute_java_class_signature(cx, jEnv, class_descriptor))
        goto error;

    class_descriptor->modifiers =
        (*jEnv)->CallIntMethod(jEnv, java_class, jlClass_getModifiers);
    class_descriptor->ref_count = 1;

    if (!JSJ_HashTableAdd(java_class_reflections, java_class, class_descriptor,
                          (void*)jEnv))
        goto error;

    return class_descriptor;

error:
    destroy_class_descriptor(cx, jEnv, class_descriptor);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool reflect_java_methods_and_fields ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
JSBool  reflect_statics_only 
) [static]

Definition at line 525 of file jsj_class.c.

{
    JavaMemberDescriptor *member_descriptor;
    JSBool success;

    success = JS_TRUE;  /* optimism */

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(java_reflect_monitor);
#endif

    /* See if we raced with another thread to reflect members of this class.
       If the status is REFLECT_COMPLETE, another thread beat us to it.  If
       the status is REFLECT_IN_PROGRESS, we've recursively called this
       function within a single thread.  Either way, we're done. */
    if (reflect_statics_only) {
        if (class_descriptor->static_members_reflected != REFLECT_NO)
            goto done;
        class_descriptor->static_members_reflected = REFLECT_IN_PROGRESS;
    } else {
        if (class_descriptor->instance_members_reflected != REFLECT_NO)
            goto done;
        class_descriptor->instance_members_reflected = REFLECT_IN_PROGRESS;
    }
    
    if (!jsj_ReflectJavaMethods(cx, jEnv, class_descriptor, reflect_statics_only))
        goto error;
    if (!jsj_ReflectJavaFields(cx, jEnv, class_descriptor, reflect_statics_only))
        goto error;

    if (reflect_statics_only) {
        member_descriptor = class_descriptor->static_members;
        while (member_descriptor) {
            class_descriptor->num_static_members++;
            member_descriptor = member_descriptor->next;
        }
        class_descriptor->static_members_reflected = REFLECT_COMPLETE;
    } else {
        member_descriptor = class_descriptor->instance_members;
        while (member_descriptor) {
            class_descriptor->num_instance_members++;
            member_descriptor = member_descriptor->next;
        }
        class_descriptor->instance_members_reflected = REFLECT_COMPLETE;
    }

done:
#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(java_reflect_monitor);
#endif
    return success;

error:
    success = JS_FALSE;
    goto done;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 62 of file jsj_class.c.