Back to index

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

Go to the source code of this file.

Defines

#define LOAD_CLASS(qualified_name, class)
#define _LOAD_METHOD(qualified_class, method, mvar, signature, class, is_static)
#define LOAD_METHOD(qualified_class, method, signature, class)   _LOAD_METHOD(qualified_class, method, method, signature, class, JS_FALSE)
#define LOAD_STATIC_METHOD(qualified_class, method, signature, class)   _LOAD_METHOD(qualified_class, method, method, signature, class, JS_TRUE)
#define LOAD_CONSTRUCTOR(qualified_class, method, signature, class)   _LOAD_METHOD(qualified_class,<init>, method, signature, class, JS_FALSE)
#define _LOAD_FIELDID(qualified_class, field, signature, class, is_static)
#define LOAD_FIELDID(qualified_class, field, signature, class)   _LOAD_FIELDID(qualified_class, field, signature, class, JS_FALSE)
#define LOAD_FIELD_VAL(qualified_class, field, signature, class, type)
#define LOAD_FIELD_OBJ(qualified_class, field, signature, class)
#define UNLOAD_CLASS(qualified_name, class)

Functions

static void report_java_initialization_error (JNIEnv *jEnv, const char *js_error_msg)
static JSBool init_java_VM_reflection (JSJavaVM *jsjava_vm, JNIEnv *jEnv)
static JSBool JSObject_RegisterNativeMethods (JNIEnv *jEnv)
 Workaround for the fact that MRJ loads a different instance of the shared library.
static JSBool init_netscape_java_classes (JSJavaVM *jsjava_vm, JNIEnv *jEnv)
JSJavaVMJSJ_ConnectToJavaVM (SystemJavaVM *java_vm_arg, void *initargs)
static JSBool jsj_ConnectToJavaVM (JSJavaVM *jsjava_vm)
void JSJ_Init (JSJCallbacks *callbacks)
JSBool JSJ_InitJSContext (JSContext *cx, JSObject *global_obj, JavaPackageDef *predefined_packages)
void JSJ_DisconnectFromJavaVM (JSJavaVM *jsjava_vm)
static JSJavaThreadStatenew_jsjava_thread_state (JSJavaVM *jsjava_vm, const char *thread_name, JNIEnv *jEnv)
static JSJavaThreadStatefind_jsjava_thread (JNIEnv *jEnv)
 JSJ_AttachCurrentThreadToJava (JSJavaVM *jsjava_vm, const char *name, JNIEnv **java_envp)
static JSJavaVMmap_java_vm_to_jsjava_vm (SystemJavaVM *java_vm)
JSJavaThreadStatejsj_MapJavaThreadToJSJavaThreadState (JNIEnv *jEnv, char **errp)
 JSJ_SetDefaultJSContextForJavaThread (JSContext *cx, JSJavaThreadState *jsj_env)
 JSJ_DetachCurrentThreadFromJava (JSJavaThreadState *jsj_env)
JSBool JSJ_ConvertJavaObjectToJSValue (JSContext *cx, jobject java_obj, jsval *vp)
 JSJ_ConvertJSValueToJavaObject (JSContext *cx, jsval v, jobject *vp)
 JSJ_IsJSCallApplet ()

Variables

JSBool jsj_JSIsCallingApplet = JS_FALSE
jclass jlObject
jclass jlrMethod
jclass jlrField
jclass jlrArray
jclass jlVoid
jclass jlrConstructor
jclass jlThrowable
jclass jlSystem
jclass jlClass
jclass jlBoolean
jclass jlDouble
jclass jlString
jclass jaApplet
jclass njJSObject
jclass njJSException
jclass njJSUtil
jmethodID jlClass_getMethods
jmethodID jlClass_getConstructors
jmethodID jlClass_getFields
jmethodID jlClass_getName
jmethodID jlClass_getComponentType
jmethodID jlClass_getModifiers
jmethodID jlClass_isArray
jmethodID jlrMethod_getName
jmethodID jlrMethod_getParameterTypes
jmethodID jlrMethod_getReturnType
jmethodID jlrMethod_getModifiers
jmethodID jlrConstructor_getParameterTypes
jmethodID jlrConstructor_getModifiers
jmethodID jlrField_getName
jmethodID jlrField_getType
jmethodID jlrField_getModifiers
jmethodID jlrArray_newInstance
jmethodID jlBoolean_Boolean
jmethodID jlBoolean_booleanValue
jmethodID jlDouble_Double
jmethodID jlDouble_doubleValue
jmethodID jlThrowable_toString
jmethodID jlThrowable_getMessage
jmethodID jlSystem_identityHashCode
jobject jlVoid_TYPE
jmethodID njJSException_JSException
jmethodID njJSException_JSException_wrap
jmethodID njJSObject_JSObject
jmethodID njJSUtil_getStackTrace
jfieldID njJSObject_internal
jfieldID njJSObject_long_internal
jfieldID njJSException_lineno
jfieldID njJSException_tokenIndex
jfieldID njJSException_source
jfieldID njJSException_filename
jfieldID njJSException_wrappedExceptionType
jfieldID njJSException_wrappedException
JSJavaVMjsjava_vm_list = NULL
static JSJavaThreadStatethread_list = NULL
JSJCallbacksJSJ_callbacks = NULL

Define Documentation

#define _LOAD_FIELDID (   qualified_class,
  field,
  signature,
  class,
  is_static 
)
Value:
if (is_static) {                                                         \
        class##_##field = (*jEnv)->GetStaticFieldID(jEnv, class, #field, signature);\
    } else {                                                                 \
        class##_##field = (*jEnv)->GetFieldID(jEnv, class, #field, signature);\
    }                                                                        \
    if (class##_##field == 0) {                                              \
            (*jEnv)->ExceptionClear(jEnv);                                   \
        report_java_initialization_error(jEnv,                               \
                "Can't get fid for " #qualified_class "." #field);           \
        return JS_FALSE;                                                     \
    }

Definition at line 203 of file jsj.c.

#define _LOAD_METHOD (   qualified_class,
  method,
  mvar,
  signature,
  class,
  is_static 
)
Value:
if (is_static) {                                                         \
        class##_##mvar =                                                     \
            (*jEnv)->GetStaticMethodID(jEnv, class, #method, signature);     \
    } else {                                                                 \
        class##_##mvar =                                                     \
            (*jEnv)->GetMethodID(jEnv, class, #method, signature);           \
    }                                                                        \
    if (class##_##mvar == 0) {                                               \
            (*jEnv)->ExceptionClear(jEnv);                                   \
        report_java_initialization_error(jEnv,                               \
               "Can't get mid for " #qualified_class "." #method "()");      \
        return JS_FALSE;                                                     \
    }

Definition at line 175 of file jsj.c.

#define LOAD_CLASS (   qualified_name,
  class 
)
Value:
{                                                                        \
        jclass _##class = (*jEnv)->FindClass(jEnv, #qualified_name);         \
        if (_##class == 0) {                                                 \
            (*jEnv)->ExceptionClear(jEnv);                                   \
            report_java_initialization_error(jEnv,                           \
                "Can't load class " #qualified_name);                        \
            return JS_FALSE;                                                 \
        }                                                                    \
        class = (*jEnv)->NewGlobalRef(jEnv, _##class);                       \
        (*jEnv)->DeleteLocalRef(jEnv, _##class);                             \
    }

Definition at line 161 of file jsj.c.

#define LOAD_CONSTRUCTOR (   qualified_class,
  method,
  signature,
  class 
)    _LOAD_METHOD(qualified_class,<init>, method, signature, class, JS_FALSE)

Definition at line 199 of file jsj.c.

#define LOAD_FIELD_OBJ (   qualified_class,
  field,
  signature,
  class 
)
Value:
LOAD_FIELD_VAL(qualified_class, field, signature, class, Object);        \
    class##_##field = (*jEnv)->NewGlobalRef(jEnv, class##_##field);

Definition at line 242 of file jsj.c.

#define LOAD_FIELD_VAL (   qualified_class,
  field,
  signature,
  class,
  type 
)
Value:
{                                                                        \
        jfieldID field_id;                                                   \
        field_id = (*jEnv)->GetStaticFieldID(jEnv, class, #field, signature);\
        if (field_id == 0) {                                                 \
            report_java_initialization_error(jEnv,                           \
                "Can't get fid for " #qualified_class "." #field);           \
            return JS_FALSE;                                                 \
        }                                                                    \
        class##_##field =                                                    \
            (*jEnv)->GetStatic##type##Field(jEnv, class, field_id);          \
        if (class##_##field == 0) {                                          \
            (*jEnv)->ExceptionClear(jEnv);                                   \
            report_java_initialization_error(jEnv,                           \
                "Can't read static field " #qualified_class "." #field);     \
            return JS_FALSE;                                                 \
        }                                                                    \
    }

Definition at line 221 of file jsj.c.

#define LOAD_FIELDID (   qualified_class,
  field,
  signature,
  class 
)    _LOAD_FIELDID(qualified_class, field, signature, class, JS_FALSE)

Definition at line 217 of file jsj.c.

#define LOAD_METHOD (   qualified_class,
  method,
  signature,
  class 
)    _LOAD_METHOD(qualified_class, method, method, signature, class, JS_FALSE)

Definition at line 191 of file jsj.c.

#define LOAD_STATIC_METHOD (   qualified_class,
  method,
  signature,
  class 
)    _LOAD_METHOD(qualified_class, method, method, signature, class, JS_TRUE)

Definition at line 195 of file jsj.c.

#define UNLOAD_CLASS (   qualified_name,
  class 
)
Value:
if (class) {                                                             \
        (*jEnv)->DeleteGlobalRef(jEnv, class);                               \
        class = NULL;                                                        \
    }

Definition at line 560 of file jsj.c.


Function Documentation

static JSJavaThreadState* find_jsjava_thread ( JNIEnv jEnv) [static]

Definition at line 658 of file jsj.c.

{
    JSJavaThreadState *e, **p, *jsj_env;
    jsj_env = NULL;

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(thread_list_monitor);
#endif

    /* Search for the thread state among the list of all created
       LiveConnect threads */
    for (p = &thread_list; (e = *p) != NULL; p = &(e->next)) {
        if (e->jEnv == jEnv) {
            jsj_env = e;
            break;
        }
    }

    /* Move a found thread to head of list for faster search next time. */
    if (jsj_env && p != &thread_list) {
        *p = jsj_env->next;
        jsj_env->next = thread_list;
        thread_list = jsj_env;
    }
    
#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(thread_list_monitor);
#endif

    return jsj_env;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool init_java_VM_reflection ( JSJavaVM jsjava_vm,
JNIEnv jEnv 
) [static]

Definition at line 251 of file jsj.c.

{
    /* Load Java system classes and method, including java.lang.reflect classes */
    LOAD_CLASS(java/lang/Object,                jlObject);
    LOAD_CLASS(java/lang/Class,                 jlClass);
    LOAD_CLASS(java/lang/reflect/Method,        jlrMethod);
    LOAD_CLASS(java/lang/reflect/Constructor,   jlrConstructor);
    LOAD_CLASS(java/lang/reflect/Field,         jlrField);
    LOAD_CLASS(java/lang/reflect/Array,         jlrArray);
    LOAD_CLASS(java/lang/Throwable,             jlThrowable);
    LOAD_CLASS(java/lang/System,                jlSystem);
    LOAD_CLASS(java/lang/Boolean,               jlBoolean);
    LOAD_CLASS(java/lang/Double,                jlDouble);
    LOAD_CLASS(java/lang/String,                jlString);
    LOAD_CLASS(java/lang/Void,                  jlVoid);

    LOAD_CLASS(java/applet/Applet,              jaApplet);

    LOAD_METHOD(java.lang.Class,            getMethods,         "()[Ljava/lang/reflect/Method;",jlClass);
    LOAD_METHOD(java.lang.Class,            getConstructors,    "()[Ljava/lang/reflect/Constructor;",jlClass);
    LOAD_METHOD(java.lang.Class,            getFields,          "()[Ljava/lang/reflect/Field;", jlClass);
    LOAD_METHOD(java.lang.Class,            getName,            "()Ljava/lang/String;",         jlClass);
    LOAD_METHOD(java.lang.Class,            isArray,            "()Z",                          jlClass);
    LOAD_METHOD(java.lang.Class,            getComponentType,   "()Ljava/lang/Class;",          jlClass);
    LOAD_METHOD(java.lang.Class,            getModifiers,       "()I",                          jlClass);

    LOAD_METHOD(java.lang.reflect.Method,   getName,            "()Ljava/lang/String;",         jlrMethod);
    LOAD_METHOD(java.lang.reflect.Method,   getParameterTypes,  "()[Ljava/lang/Class;",         jlrMethod);
    LOAD_METHOD(java.lang.reflect.Method,   getReturnType,      "()Ljava/lang/Class;",          jlrMethod);
    LOAD_METHOD(java.lang.reflect.Method,   getModifiers,       "()I",                          jlrMethod);

    LOAD_METHOD(java.lang.reflect.Constructor,  getParameterTypes,  "()[Ljava/lang/Class;",     jlrConstructor);
    LOAD_METHOD(java.lang.reflect.Constructor,  getModifiers,       "()I",                      jlrConstructor);
    
    LOAD_METHOD(java.lang.reflect.Field,    getName,            "()Ljava/lang/String;",         jlrField);
    LOAD_METHOD(java.lang.reflect.Field,    getType,            "()Ljava/lang/Class;",          jlrField);
    LOAD_METHOD(java.lang.reflect.Field,    getModifiers,       "()I",                          jlrField);

    LOAD_STATIC_METHOD(java.lang.reflect.Array,
                                            newInstance,        "(Ljava/lang/Class;I)Ljava/lang/Object;",jlrArray);

    LOAD_METHOD(java.lang.Throwable,        toString,           "()Ljava/lang/String;",         jlThrowable);
    LOAD_METHOD(java.lang.Throwable,        getMessage,         "()Ljava/lang/String;",         jlThrowable);

    LOAD_METHOD(java.lang.Double,           doubleValue,        "()D",                          jlDouble);

    LOAD_METHOD(java.lang.Boolean,          booleanValue,       "()Z",                          jlBoolean);
    
    LOAD_STATIC_METHOD(java.lang.System,    identityHashCode,   "(Ljava/lang/Object;)I",        jlSystem);

    LOAD_CONSTRUCTOR(java.lang.Boolean,     Boolean,            "(Z)V",                         jlBoolean);
    LOAD_CONSTRUCTOR(java.lang.Double,      Double,             "(D)V",                         jlDouble);

    LOAD_FIELD_OBJ(java.lang.Void,          TYPE,               "Ljava/lang/Class;",            jlVoid);
  
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool init_netscape_java_classes ( JSJavaVM jsjava_vm,
JNIEnv jEnv 
) [static]

Definition at line 356 of file jsj.c.

{
    LOAD_CLASS(netscape/javascript/JSObject,    njJSObject);
    LOAD_CLASS(netscape/javascript/JSException, njJSException);
    LOAD_CLASS(netscape/javascript/JSUtil,      njJSUtil);

#if !defined(OJI) 
    JSObject_RegisterNativeMethods(jEnv);
#endif

#ifndef OJI
    LOAD_CONSTRUCTOR(netscape.javascript.JSObject,
                                            JSObject,           "(I)V",                         njJSObject);
#endif
    LOAD_CONSTRUCTOR(netscape.javascript.JSException,
                                            JSException,        "(Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;I)V",
                                                                                                njJSException);

    /* Load second constructor for wrapping JS exception objects inside JSExceptions */
    _LOAD_METHOD(netscape.javascript.JSException,<init>,
                 JSException_wrap, "(ILjava/lang/Object;)V",        
                 njJSException, JS_FALSE);

#ifndef OJI
    LOAD_FIELDID(netscape.javascript.JSObject,  
                                            internal,           "I",                            njJSObject);
#endif
    LOAD_FIELDID(netscape.javascript.JSException,  
                                            lineno,             "I",                            njJSException);
    LOAD_FIELDID(netscape.javascript.JSException,  
                                            tokenIndex,         "I",                            njJSException);
    LOAD_FIELDID(netscape.javascript.JSException,  
                                            source,             "Ljava/lang/String;",           njJSException);
    LOAD_FIELDID(netscape.javascript.JSException,  
                                            filename,           "Ljava/lang/String;",           njJSException);
    LOAD_FIELDID(netscape.javascript.JSException, wrappedExceptionType, "I",
                 njJSException);
    LOAD_FIELDID(netscape.javascript.JSException, wrappedException,
                 "Ljava/lang/Object;", njJSException);

    LOAD_STATIC_METHOD(netscape.javascript.JSUtil,
                                            getStackTrace,      "(Ljava/lang/Throwable;)Ljava/lang/String;",
                                                                                                njJSUtil);

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSJ_AttachCurrentThreadToJava ( JSJavaVM jsjava_vm,
const char *  name,
JNIEnv **  java_envp 
)

Definition at line 691 of file jsj.c.

{
    JNIEnv *jEnv;
    SystemJavaVM *java_vm;
    JSJavaThreadState *jsj_env;
    
    /* Make sure we're fully connected to the Java VM */
    if (!jsj_ConnectToJavaVM(jsjava_vm))
        return NULL;

    /* Try to attach a Java thread to the current native thread */
    java_vm = jsjava_vm->java_vm;
    if (JSJ_callbacks && JSJ_callbacks->attach_current_thread)
        jEnv = JSJ_callbacks->attach_current_thread(java_vm);
    else
        return NULL;
    if (jEnv == NULL) 
        return NULL;

    /* If we found an existing thread state, just return it. */
    jsj_env = find_jsjava_thread(jEnv);
    if (jsj_env)
        return jsj_env;

    /* Create a new wrapper around the thread/VM state */
    jsj_env = new_jsjava_thread_state(jsjava_vm, name, jEnv);

    if (java_envp)
        *java_envp = jEnv;
    return jsj_env;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSJavaVM* JSJ_ConnectToJavaVM ( SystemJavaVM java_vm_arg,
void initargs 
)

Definition at line 418 of file jsj.c.

{
    SystemJavaVM* java_vm;
    JSJavaVM *jsjava_vm;
    JNIEnv *jEnv;

    JS_ASSERT(JSJ_callbacks);
    JS_ASSERT(JSJ_callbacks->attach_current_thread);
    JS_ASSERT(JSJ_callbacks->detach_current_thread);
    JS_ASSERT(JSJ_callbacks->get_java_vm);

    jsjava_vm = (JSJavaVM*)malloc(sizeof(JSJavaVM));
    if (!jsjava_vm)
        return NULL;
    memset(jsjava_vm, 0, sizeof(JSJavaVM));

    java_vm = java_vm_arg;

    /* If a Java VM was passed in, try to attach to it on the current thread. */
    if (java_vm) {
        jEnv = JSJ_callbacks->attach_current_thread(java_vm);
        if (jEnv == NULL) {
            jsj_LogError("Failed to attach to Java VM thread\n");
            free(jsjava_vm);
            return NULL;
        }

        jsjava_vm->java_vm = java_vm;
        jsjava_vm->main_thread_env = jEnv;
    } else {
        jsjava_vm->init_args = initargs;
    }
       
#ifdef JSJ_THREADSAFE
    if (jsjava_vm_list == NULL) {
        thread_list_monitor =
            (struct PRMonitor *) PR_NewMonitor();
    }
#endif /* JSJ_THREADSAFE */

    /* Put this VM on the list of all created VMs */
    jsjava_vm->next = jsjava_vm_list;
    jsjava_vm_list = jsjava_vm;

    return jsjava_vm;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSBool jsj_ConnectToJavaVM ( JSJavaVM jsjava_vm) [static]

Definition at line 467 of file jsj.c.

{
    if (!jsjava_vm->java_vm) {
        JSBool ok;
        JS_ASSERT(JSJ_callbacks->create_java_vm);
        JS_ASSERT(JSJ_callbacks->destroy_java_vm);

        ok = JSJ_callbacks->create_java_vm(&jsjava_vm->java_vm,
                                           &jsjava_vm->main_thread_env,
                                           jsjava_vm->init_args);
        if (!ok) {
            jsj_LogError("Failed to create Java VM\n");
            return JS_FALSE;
        }

        /* Remember that we created the VM so that we know to destroy it later */
        jsjava_vm->jsj_created_java_vm = JS_TRUE;
    }
    
    if (!jsjava_vm->jsj_inited_java_vm) {
        /*
         * JVM initialization for netscape.javascript.JSObject is performed
         * independently of the other classes that are initialized in
         * init_java_VM_reflection, because we allow it to fail.  In the case
         * of failure, LiveConnect is still operative, but only when calling
         * from JS to Java and not vice-versa.
         */
        init_netscape_java_classes(jsjava_vm, jsjava_vm->main_thread_env);

        /* Load the Java classes, and the method and field descriptors required for
           Java reflection. */
        if (!init_java_VM_reflection(jsjava_vm, jsjava_vm->main_thread_env) || 
            !jsj_InitJavaObjReflectionsTable()) {
            jsj_LogError("LiveConnect was unable to reflect one or more components of the Java runtime.\nGo to http://bugzilla.mozilla.org/show_bug.cgi?id=5369 for details.\n");
            /* This function crashes when called from here.
               Check that all the preconditions for this
               call are satisfied before making it. [jd]
               JSJ_DisconnectFromJavaVM(jsjava_vm); */
            return JS_FALSE;
        }
        
        jsjava_vm->jsj_inited_java_vm = JS_TRUE;
    }

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool JSJ_ConvertJavaObjectToJSValue ( JSContext cx,
jobject  java_obj,
jsval vp 
)

Definition at line 852 of file jsj.c.

{
    JNIEnv *jEnv;
    JSBool result;
    JSJavaThreadState *jsj_env;
            
    /* Get the Java per-thread environment pointer for this JSContext */
    jsj_env = jsj_EnterJava(cx, &jEnv);
    if (!jEnv)
        return JS_FALSE;

    result = jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, vp);
    jsj_ExitJava(jsj_env);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 870 of file jsj.c.

{
    if (!JSVAL_IS_PRIMITIVE(v)) {
        JSObject *js_obj = JSVAL_TO_OBJECT(v);
        JavaObjectWrapper *java_wrapper = JS_GetPrivate(cx, js_obj);
        *vp = java_wrapper->java_obj;
        return JS_TRUE;
    }
    return JS_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 806 of file jsj.c.

{
    SystemJavaVM *java_vm;
    JNIEnv* jEnv;
    JSJavaThreadState *e, **p;

    /* Disassociate the current native thread from its corresponding Java thread */
    java_vm = jsj_env->jsjava_vm->java_vm;
    jEnv = jsj_env->jEnv;

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(thread_list_monitor);
#endif /* JSJ_THREADSAFE */

    if (!JSJ_callbacks->detach_current_thread(java_vm, jEnv)) {

#ifdef JSJ_THREADSAFE
        PR_ExitMonitor(thread_list_monitor);
#endif /* JSJ_THREADSAFE */

        return JS_FALSE;
    }

    /* Destroy the LiveConnect execution environment passed in */
    jsj_ClearPendingJSErrors(jsj_env);

    for (p = &thread_list; (e = *p) != NULL; p = &(e->next)) {
        if (e == jsj_env) {
            *p = jsj_env->next;
            break;
        }
    }

    JS_ASSERT(e);

#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(thread_list_monitor);
#endif /* JSJ_THREADSAFE */

    free(jsj_env);
    return JS_TRUE;
}

Here is the call graph for this function:

Definition at line 573 of file jsj.c.

{
    SystemJavaVM *java_vm;
    JSJavaVM *j, **jp;

    /* Since JSJ_ConnectToJavaVM is now lazy */
    java_vm = jsjava_vm->java_vm;
    if (java_vm) {
        JNIEnv *jEnv = jsjava_vm->main_thread_env;

        /* Drop all references to Java objects and classes */
        jsj_DiscardJavaObjReflections(jEnv);
        jsj_DiscardJavaClassReflections(jEnv);

        if (jsjava_vm->jsj_created_java_vm) { 
            (void)JSJ_callbacks->destroy_java_vm(java_vm, jEnv);
        } else {
            UNLOAD_CLASS(java/lang/Object,                jlObject);
            UNLOAD_CLASS(java/lang/Class,                 jlClass);
            UNLOAD_CLASS(java/lang/reflect/Method,        jlrMethod);
            UNLOAD_CLASS(java/lang/reflect/Constructor,   jlrConstructor);
            UNLOAD_CLASS(java/lang/reflect/Field,         jlrField);
            UNLOAD_CLASS(java/lang/reflect/Array,         jlrArray);
            UNLOAD_CLASS(java/lang/Throwable,             jlThrowable);
            UNLOAD_CLASS(java/lang/System,                jlSystem);
            UNLOAD_CLASS(java/lang/Boolean,               jlBoolean);
            UNLOAD_CLASS(java/lang/Double,                jlDouble);
            UNLOAD_CLASS(java/lang/String,                jlString);
            UNLOAD_CLASS(java/lang/Void,                  jlVoid);
            UNLOAD_CLASS(java/applet/Applet,              jaApplet);
            UNLOAD_CLASS(netscape/javascript/JSObject,    njJSObject);
            UNLOAD_CLASS(netscape/javascript/JSException, njJSException);
            UNLOAD_CLASS(netscape/javascript/JSUtil,      njJSUtil);
        }
    }

    /* Remove this VM from the list of all JSJavaVM objects. */
    for (jp = &jsjava_vm_list; (j = *jp) != NULL; jp = &j->next) {
        if (j == jsjava_vm) {
            *jp = jsjava_vm->next;
            break;
        }
    }
    JS_ASSERT(j); /* vm not found in list */

#ifdef JSJ_THREADSAFE
    if (jsjava_vm_list == NULL) {
        PR_DestroyMonitor(thread_list_monitor);
        thread_list_monitor = NULL;
    }
#endif /* JSJ_THREADSAFE */
    
    free(jsjava_vm);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void JSJ_Init ( JSJCallbacks callbacks)

Definition at line 518 of file jsj.c.

{
    JS_ASSERT(callbacks);
    JSJ_callbacks = callbacks;
}

Here is the caller graph for this function:

JSBool JSJ_InitJSContext ( JSContext cx,
JSObject global_obj,
JavaPackageDef predefined_packages 
)

Definition at line 534 of file jsj.c.

{
    /* Initialize the JavaScript classes used for reflection */
    if (!jsj_init_JavaObject(cx, global_obj))
        return JS_FALSE;
    
/*    if (!jsj_init_JavaMember(cx, global_obj))
        return JS_FALSE; */
    
    if (!jsj_init_JavaPackage(cx, global_obj, predefined_packages))
        return JS_FALSE;

    if (!jsj_init_JavaClass(cx, global_obj))
        return JS_FALSE;

    if (!jsj_init_JavaArray(cx, global_obj))
        return JS_FALSE;

    if (!jsj_init_JavaMember(cx, global_obj))
        return JS_FALSE;
    
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 883 of file jsj.c.

Here is the caller graph for this function:

Definition at line 747 of file jsj.c.

{
    JSJavaThreadState *jsj_env;
    SystemJavaVM *java_vm;
    JSJavaVM *jsjava_vm;

    /* If we found an existing thread state, just return it. */
    jsj_env = find_jsjava_thread(jEnv);
    if (jsj_env)
        return jsj_env;

    /* No one set up a LiveConnect thread state for a given Java thread.
       Invoke the callback to create one on-the-fly. */

    /* First, figure out which Java VM is calling us */
    if (JSJ_callbacks && JSJ_callbacks->get_java_vm)
        java_vm = JSJ_callbacks->get_java_vm(jEnv);
    else
        return NULL;
    if (java_vm == NULL)
        return NULL;

    /* Get our private JavaVM data */
    jsjava_vm = map_java_vm_to_jsjava_vm(java_vm);
    if (!jsjava_vm) {
        *errp = JS_smprintf("Total weirdness:   No JSJavaVM wrapper ever created "
                            "for JavaVM 0x%08x", java_vm);
        return NULL;
    }

    jsj_env = new_jsjava_thread_state(jsjava_vm, NULL, jEnv);
    if (!jsj_env)
        return NULL;

    return jsj_env;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 794 of file jsj.c.

{
    JSContext *old_context;
    old_context = jsj_env->cx;
    jsj_env->cx = cx;

    /* The following line prevents clearing of jsj_env->cx by jsj_ExitJava() */
    jsj_env->recursion_depth++;
    return old_context;
}

Here is the caller graph for this function:

static JSBool JSObject_RegisterNativeMethods ( JNIEnv jEnv) [static]

Workaround for the fact that MRJ loads a different instance of the shared library.

Definition at line 319 of file jsj.c.

{

    static JNINativeMethod nativeMethods[] = {
        {"initClass", "()V", (void*)&Java_netscape_javascript_JSObject_initClass},

#ifndef OJI
        {"getMember", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getMember},
        {"getSlot", "(I)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getSlot},
        {"setMember", "(Ljava/lang/String;Ljava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setMember},
        {"setSlot", "(ILjava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setSlot},
        {"removeMember", "(Ljava/lang/String;)V", (void*)&Java_netscape_javascript_JSObject_removeMember},
        {"call", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_call},
        {"eval", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_eval},
        
        {"toString", "()Ljava/lang/String;", (void*)&Java_netscape_javascript_JSObject_toString},
        {"getWindow", "(Ljava/applet/Applet;)Lnetscape/javascript/JSObject;", (void*)&Java_netscape_javascript_JSObject_getWindow},
        {"finalize", "()V", (void*)&Java_netscape_javascript_JSObject_finalize},
        {"equals", "(Ljava/lang/Object;)Z", (void*)&Java_netscape_javascript_JSObject_equals}
#endif  /* !OJI */

    };
    (*jEnv)->RegisterNatives(jEnv, njJSObject, nativeMethods, sizeof(nativeMethods) / sizeof(JNINativeMethod));
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        report_java_initialization_error(jEnv, "Couldn't initialize JSObject native methods.");
        (*jEnv)->ExceptionClear(jEnv);
        return JS_FALSE;
    }
    /* Call the initClass method */
    Java_netscape_javascript_JSObject_initClass(jEnv, njJSObject);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSJavaVM* map_java_vm_to_jsjava_vm ( SystemJavaVM java_vm) [static]

Definition at line 724 of file jsj.c.

{
    JSJavaVM *v;
    for (v = jsjava_vm_list; v; v = v->next) {
        if (!jsj_ConnectToJavaVM(v))
            return NULL;
        if (v->java_vm == java_vm)
            return v;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSJavaThreadState* new_jsjava_thread_state ( JSJavaVM jsjava_vm,
const char *  thread_name,
JNIEnv jEnv 
) [static]

Definition at line 629 of file jsj.c.

{
    JSJavaThreadState *jsj_env;

    jsj_env = (JSJavaThreadState *)malloc(sizeof(JSJavaThreadState));
    if (!jsj_env)
        return NULL;
    memset(jsj_env, 0, sizeof(JSJavaThreadState));

    jsj_env->jEnv = jEnv;
    jsj_env->jsjava_vm = jsjava_vm;
    if (thread_name)
        jsj_env->name = strdup(thread_name);

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(thread_list_monitor);
#endif

    jsj_env->next = thread_list;
    thread_list = jsj_env;

#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(thread_list_monitor);
#endif

    return jsj_env;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void report_java_initialization_error ( JNIEnv jEnv,
const char *  js_error_msg 
) [static]

Definition at line 67 of file jsj.c.

{
    const char *error_msg, *java_error_msg;

    java_error_msg = NULL;

    if (jEnv) {
        java_error_msg = jsj_GetJavaErrorMessage(jEnv);
        (*jEnv)->ExceptionClear(jEnv);
    }

    if (java_error_msg) { 
        error_msg = JS_smprintf("initialization error: %s (%s)\n",
                                js_error_msg, java_error_msg);
        free((void*)java_error_msg);
    } else {
        error_msg = JS_smprintf("initialization error: %s\n",
                                js_error_msg);
    }

    jsj_LogError(error_msg);
    free((void*)error_msg);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 108 of file jsj.c.

Definition at line 105 of file jsj.c.

Definition at line 135 of file jsj.c.

Definition at line 136 of file jsj.c.

Definition at line 104 of file jsj.c.

Definition at line 117 of file jsj.c.

Definition at line 114 of file jsj.c.

Definition at line 115 of file jsj.c.

Definition at line 113 of file jsj.c.

Definition at line 118 of file jsj.c.

Definition at line 116 of file jsj.c.

Definition at line 119 of file jsj.c.

Definition at line 106 of file jsj.c.

Definition at line 137 of file jsj.c.

Definition at line 138 of file jsj.c.

Definition at line 96 of file jsj.c.

Definition at line 99 of file jsj.c.

Definition at line 133 of file jsj.c.

Definition at line 101 of file jsj.c.

Definition at line 127 of file jsj.c.

Definition at line 126 of file jsj.c.

Definition at line 98 of file jsj.c.

Definition at line 131 of file jsj.c.

Definition at line 129 of file jsj.c.

Definition at line 130 of file jsj.c.

Definition at line 97 of file jsj.c.

Definition at line 124 of file jsj.c.

Definition at line 121 of file jsj.c.

Definition at line 122 of file jsj.c.

Definition at line 123 of file jsj.c.

Definition at line 107 of file jsj.c.

Definition at line 103 of file jsj.c.

Definition at line 143 of file jsj.c.

Definition at line 102 of file jsj.c.

Definition at line 141 of file jsj.c.

Definition at line 140 of file jsj.c.

Definition at line 100 of file jsj.c.

Definition at line 145 of file jsj.c.

Definition at line 514 of file jsj.c.

Definition at line 58 of file jsj.c.

Definition at line 403 of file jsj.c.

Definition at line 110 of file jsj.c.

Definition at line 156 of file jsj.c.

Definition at line 147 of file jsj.c.

Definition at line 148 of file jsj.c.

Definition at line 153 of file jsj.c.

Definition at line 155 of file jsj.c.

Definition at line 154 of file jsj.c.

Definition at line 158 of file jsj.c.

Definition at line 157 of file jsj.c.

Definition at line 109 of file jsj.c.

Definition at line 151 of file jsj.c.

Definition at line 149 of file jsj.c.

Definition at line 152 of file jsj.c.

Definition at line 111 of file jsj.c.

Definition at line 150 of file jsj.c.

Definition at line 405 of file jsj.c.