Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
jsjava.h File Reference
#include "jstypes.h"
#include "jni.h"
#include "jsapi.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JSJCallbacks
struct  JavaPackageDef

Defines

#define PKG_SYSTEM   1
#define PKG_USER   2

Typedefs

typedef struct JSJavaVM
typedef struct JSJavaThreadState
typedef JavaVM SystemJavaVM
typedef struct JSJCallbacks JSJCallbacks
typedef struct JavaPackageDef JavaPackageDef

Functions

 JSJ_SimpleInit (JSContext *cx, JSObject *global_obj, SystemJavaVM *java_vm, const char *classpath)
 JSJ_SimpleShutdown (void)
 JSJ_Init (JSJCallbacks *callbacks)
 JSJ_ConnectToJavaVM (SystemJavaVM *java_vm, void *initargs)
 JSJ_InitJSContext (JSContext *cx, JSObject *global_obj, JavaPackageDef *predefined_packages)
 JSJ_AttachCurrentThreadToJava (JSJavaVM *jsjava_vm, const char *thread_name, JNIEnv **java_envp)
 JSJ_DetachCurrentThreadFromJava (JSJavaThreadState *jsj_env)
 JSJ_SetDefaultJSContextForJavaThread (JSContext *cx, JSJavaThreadState *jsj_env)
 JSJ_DisconnectFromJavaVM (JSJavaVM *)
 JSJ_ConvertJavaObjectToJSValue (JSContext *cx, jobject java_obj, jsval *vp)
 JSJ_ConvertJSValueToJavaObject (JSContext *cx, jsval js_val, jobject *vp)
 JSJ_IsJSCallApplet ()

Variables

JS_BEGIN_EXTERN_C typedef jint lcjsobject

Class Documentation

struct JavaPackageDef

Definition at line 192 of file jsjava.h.

Collaboration diagram for JavaPackageDef:
Class Members
int access
int flags
const char * name
const char * path

Define Documentation

#define PKG_SYSTEM   1

Definition at line 180 of file jsjava.h.

#define PKG_USER   2

Definition at line 189 of file jsjava.h.


Typedef Documentation

typedef struct JSJavaThreadState

Definition at line 72 of file jsjava.h.

typedef struct JSJavaVM

Definition at line 69 of file jsjava.h.

typedef struct JSJCallbacks JSJCallbacks

Definition at line 83 of file jsjava.h.


Function Documentation

JSJ_AttachCurrentThreadToJava ( JSJavaVM jsjava_vm,
const char *  thread_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:

JSJ_ConnectToJavaVM ( SystemJavaVM java_vm,
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:

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:

JSJ_ConvertJSValueToJavaObject ( JSContext cx,
jsval  js_val,
jobject vp 
)

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:

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:

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 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:

JSJ_SimpleInit ( JSContext cx,
JSObject global_obj,
SystemJavaVM java_vm,
const char *  classpath 
)

Definition at line 179 of file jsj_simpleapi.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 211 of file jsj_simpleapi.c.

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 62 of file jsjava.h.