Back to index

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

Go to the source code of this file.

Classes

struct  JavaMethodSignature
struct  JavaFieldSpec
struct  JavaMethodSpec
struct  JavaMemberDescriptor
struct  JavaClassDescriptor
struct  JavaObjectWrapper
struct  JSJavaVM
struct  JSJavaThreadState
struct  JavaToJSSavedState
struct  JSObjectHandle
union  JavaObjectWrapper.u

Defines

#define IS_REFERENCE_TYPE(sig)   ((int)(sig) >= (int)JAVA_SIGNATURE_ARRAY)
#define IS_OBJECT_TYPE(sig)   ((int)(sig) >= (int)JAVA_SIGNATURE_OBJECT)
#define IS_PRIMITIVE_TYPE(sig)   (((int)(sig) >= (int)JAVA_SIGNATURE_BOOLEAN) && !IS_REFERENCE_TYPE(sig)) \
#define JSTYPE_EMPTY   -1
#define ACC_PUBLIC   0x0001 /* visible to everyone */
#define ACC_STATIC   0x0008 /* instance variable is static */
#define ACC_FINAL   0x0010 /* no further subclassing,overriding */
#define ACC_INTERFACE   0x0200 /* class is an interface */
#define ACC_ABSTRACT   0x0400 /* no definition provided */
#define JS_FREE_IF(cx, x)
#define MSG_DEF(name, number, format, count)   name = number,

Typedefs

typedef struct JavaMemberDescriptor
typedef struct JavaMethodSpec
typedef struct JavaClassDescriptor
typedef struct CapturedJSError
typedef struct JavaMethodSignature JavaMethodSignature
typedef struct JavaFieldSpec JavaFieldSpec
typedef struct JavaObjectWrapper
typedef struct JavaToJSSavedState
typedef struct JSObjectHandle

Enumerations

enum  JavaSignatureChar {
  JAVA_SIGNATURE_UNKNOWN, JAVA_SIGNATURE_VOID, JAVA_SIGNATURE_BOOLEAN, JAVA_SIGNATURE_CHAR,
  JAVA_SIGNATURE_BYTE, JAVA_SIGNATURE_SHORT, JAVA_SIGNATURE_INT, JAVA_SIGNATURE_LONG,
  JAVA_SIGNATURE_FLOAT, JAVA_SIGNATURE_DOUBLE, JAVA_SIGNATURE_ARRAY, JAVA_SIGNATURE_OBJECT,
  JAVA_SIGNATURE_JAVA_LANG_BOOLEAN, JAVA_SIGNATURE_JAVA_LANG_CLASS, JAVA_SIGNATURE_JAVA_LANG_DOUBLE, JAVA_SIGNATURE_NETSCAPE_JAVASCRIPT_JSOBJECT,
  JAVA_SIGNATURE_JAVA_LANG_OBJECT, JAVA_SIGNATURE_JAVA_LANG_STRING, JAVA_SIGNATURE_LIMIT
}
enum  ReflectStatus { REFLECT_NO, REFLECT_IN_PROGRESS, REFLECT_COMPLETE }
enum  JSJErrNum { MSG_DEF, MSG_DEF }

Functions

JSBool jsj_ComputeJavaClassSignature (JSContext *cx, JavaSignature *signature, jclass java_class)
const char * jsj_ConvertJavaSignatureToString (JSContext *cx, JavaSignature *signature)
const char * jsj_ConvertJavaSignatureToHRString (JSContext *cx, JavaSignature *signature)
JavaMethodSignaturejsj_InitJavaMethodSignature (JSContext *cx, JNIEnv *jEnv, jobject method, JavaMethodSignature *method_signature)
const char * jsj_ConvertJavaMethodSignatureToString (JSContext *cx, JavaMethodSignature *method_signature)
const char * jsj_ConvertJavaMethodSignatureToHRString (JSContext *cx, const char *method_name, JavaMethodSignature *method_signature)
void jsj_PurgeJavaMethodSignature (JSContext *cx, JNIEnv *jEnv, JavaMethodSignature *signature)
JSBool jsj_ConvertJSValueToJavaValue (JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature, int *cost, jvalue *java_value, JSBool *is_local_refp)
JSBool jsj_ConvertJSValueToJavaObject (JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature, int *cost, jobject *java_value, JSBool *is_local_refp)
jstring jsj_ConvertJSStringToJavaString (JSContext *cx, JNIEnv *jEnv, JSString *js_str)
JSBool jsj_ConvertJavaValueToJSValue (JSContext *cx, JNIEnv *jEnv, JavaSignature *signature, jvalue *java_value, jsval *vp)
JSBool jsj_ConvertJavaObjectToJSValue (JSContext *cx, JNIEnv *jEnv, jobject java_obj, jsval *vp)
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)
JSJavaThreadStatejsj_enter_js (JNIEnv *jEnv, void *java_applet_obj, jobject java_wrapper_obj, JSContext **cxp, JSObject **js_objp, JSErrorReporter *old_error_reporterp, void **pNSIPrincipaArray, int numPrincipals, void *pNSISecurityContext)
JSBool jsj_exit_js (JSContext *cx, JSJavaThreadState *jsj_env, JSErrorReporter old_error_reporterp)
JavaClassDescriptorjsj_get_jlObject_descriptor (JSContext *cx, JNIEnv *jEnv)
JSBool jsj_remove_js_obj_reflection_from_hashtable (JSContext *cx, JSObject *js_obj)
JSBool jsj_init_js_obj_reflections_table (void)
JSBool jsj_init_JavaPackage (JSContext *, JSObject *, JavaPackageDef *predefined_packages)
JSBool jsj_init_JavaClass (JSContext *cx, JSObject *global_obj)
void jsj_DiscardJavaClassReflections (JNIEnv *jEnv)
const char * jsj_GetJavaClassName (JSContext *cx, JNIEnv *jEnv, jclass java_class)
JavaClassDescriptorjsj_GetJavaClassDescriptor (JSContext *cx, JNIEnv *jEnv, jclass java_class)
void jsj_ReleaseJavaClassDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JSObjectjsj_define_JavaClass (JSContext *cx, JNIEnv *jEnv, JSObject *obj, const char *unqualified_class_name, jclass jclazz)
JavaMemberDescriptorjsj_GetJavaMemberDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jstring member_name)
JavaMemberDescriptorjsj_LookupJavaMemberDescriptorById (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jsid id)
JavaMemberDescriptorjsj_LookupJavaStaticMemberDescriptorById (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jsid id)
JavaMemberDescriptorjsj_GetJavaStaticMemberDescriptor (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jstring member_name)
JavaMemberDescriptorjsj_GetJavaClassConstructors (JSContext *cx, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_LookupJavaClassConstructors (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_GetClassInstanceMembers (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JavaMemberDescriptorjsj_GetClassStaticMembers (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor)
JSBool jsj_InitJavaClassReflectionsTable (void)
JSBool jsj_GetJavaFieldValue (JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec, jobject java_obj, jsval *vp)
JSBool jsj_SetJavaFieldValue (JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec, jobject java_obj, jsval js_val)
JSBool jsj_ReflectJavaFields (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, JSBool reflect_only_static_fields)
void jsj_DestroyFieldSpec (JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field)
 jsj_JavaInstanceMethodWrapper (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
 jsj_JavaStaticMethodWrapper (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
 jsj_JavaConstructorWrapper (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
JSBool jsj_ReflectJavaMethods (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, JSBool reflect_only_static_methods)
JavaMemberDescriptorjsj_ResolveExplicitMethod (JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor, jsid method_name_id, JSBool is_static)
void jsj_DestroyMethodSpec (JSContext *cx, JNIEnv *jEnv, JavaMethodSpec *method_spec)
JSBool jsj_init_JavaMember (JSContext *, JSObject *)
JSBool jsj_ReflectJavaMethodsAndFields (JSContext *cx, JavaClassDescriptor *class_descriptor, JSBool reflect_only_statics)
JSObjectjsj_CreateJavaMember (JSContext *cx, jsval method_val, jsval field_val)
JSBool jsj_init_JavaObject (JSContext *, JSObject *)
JSBool jsj_InitJavaObjReflectionsTable (void)
JSObjectjsj_WrapJavaObject (JSContext *cx, JNIEnv *jEnv, jobject java_obj, jclass java_class)
void jsj_DiscardJavaObjReflections (JNIEnv *jEnv)
JSBool JS_DLL_CALLBACK JavaObject_convert (JSContext *cx, JSObject *obj, JSType type, jsval *vp)
 JavaObject_finalize (JSContext *cx, JSObject *obj)
JSBool JavaObject_resolve (JSContext *cx, JSObject *obj, jsval id)
JSBool JavaObject_getProperty (JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 JavaObject_getPropertyById (JSContext *cx, JSObject *obj, jsid id, jsval *vp)
JSBool jsj_init_JavaArray (JSContext *cx, JSObject *global_obj)
JSBool jsj_GetJavaArrayElement (JSContext *cx, JNIEnv *jEnv, jarray java_array, jsize index, JavaSignature *array_component_signature, jsval *vp)
JSBool jsj_SetJavaArrayElement (JSContext *cx, JNIEnv *jEnv, jarray java_array, jsize index, JavaSignature *array_component_signature, jsval js_val)
jobject jsj_WrapJSObject (JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
JSObjectjsj_UnwrapJSObjectWrapper (JNIEnv *jEnv, jobject java_wrapper_obj)
void jsj_ClearPendingJSErrors (JSJavaThreadState *jsj_env)
JSBool jsj_ReportUncaughtJSException (JSContext *cx, JNIEnv *jEnv, jthrowable java_exception)
void jsj_ReportJavaError (JSContext *cx, JNIEnv *env, const char *format,...)
void jsj_UnexpectedJavaError (JSContext *cx, JNIEnv *env, const char *format,...)
const char * jsj_GetJavaErrorMessage (JNIEnv *env)
void jsj_LogError (const char *error_msg)
const JSErrorFormatString
*JS_DLL_CALLBACK 
jsj_GetErrorMessage (void *userRef, const char *locale, const uintN errorNumber)
JSJHashNumber JS_DLL_CALLBACK jsj_HashJavaObject (const void *key, void *env)
intN JS_DLL_CALLBACK jsj_JavaObjectComparator (const void *v1, const void *v2, void *arg)
JSJavaThreadStatejsj_MapJavaThreadToJSJavaThreadState (JNIEnv *jEnv, char **errp)
void jsj_MakeJNIClassname (char *jClassName)
const char * jsj_ClassNameOfJavaObject (JSContext *cx, JNIEnv *jEnv, jobject java_object)
jsize jsj_GetJavaArrayLength (JSContext *cx, JNIEnv *jEnv, jarray java_array)
JSBool JavaStringToId (JSContext *cx, JNIEnv *jEnv, jstring jstr, jsid *idp)
const char * jsj_DupJavaStringUTF (JSContext *cx, JNIEnv *jEnv, jstring jstr)
JSJavaThreadStatejsj_EnterJava (JSContext *cx, JNIEnv **envp)
void jsj_ExitJava (JSJavaThreadState *jsj_env)
JSObjectMap *JS_DLL_CALLBACK jsj_wrapper_newObjectMap (JSContext *cx, jsrefcount nrefs, JSObjectOps *ops, JSClass *clasp, JSObject *obj)
void JS_DLL_CALLBACK jsj_wrapper_destroyObjectMap (JSContext *cx, JSObjectMap *map)
jsval JS_DLL_CALLBACK jsj_wrapper_getRequiredSlot (JSContext *cx, JSObject *obj, uint32 slot)
JSBool JS_DLL_CALLBACK jsj_wrapper_setRequiredSlot (JSContext *cx, JSObject *obj, uint32 slot, jsval v)

Variables

JSJCallbacksJSJ_callbacks
JSClass JavaObject_class
JSClass JavaArray_class
JSClass JavaClass_class
JSClass JavaMember_class
jclass jlObject
jclass jlrConstructor
jclass jlrArray
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 jlThrowable_getMessage
jmethodID jlThrowable_toString
jmethodID jlBoolean_Boolean
jmethodID jlBoolean_booleanValue
jmethodID jlDouble_Double
jmethodID jlDouble_doubleValue
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
JSBool jsj_JSIsCallingApplet

Class Documentation

struct JavaMethodSignature

Definition at line 147 of file jsj_private.h.

Class Members
JavaSignature ** arg_signatures
jsize num_args
JavaSignature * return_val_signature
struct JavaFieldSpec

Definition at line 154 of file jsj_private.h.

Collaboration diagram for JavaFieldSpec:
Class Members
jfieldID fieldID
int modifiers
const char * name
JavaSignature * signature
struct JavaMethodSpec

Definition at line 163 of file jsj_private.h.

Collaboration diagram for JavaMethodSpec:
Class Members
JSBool is_alias
jmethodID methodID
const char * name
JavaMethodSpec * next
JavaMethodSignature signature
struct JavaMemberDescriptor

Definition at line 178 of file jsj_private.h.

Collaboration diagram for JavaMemberDescriptor:
Class Members
JavaFieldSpec * field
jsid id
JSObject * invoke_func_obj
JavaMethodSpec * methods
const char * name
JavaMemberDescriptor * next
struct JavaClassDescriptor

Definition at line 195 of file jsj_private.h.

Collaboration diagram for JavaClassDescriptor:
Class Members
JavaSignature * array_component_signature
JavaMemberDescriptor * constructors
JavaMemberDescriptor * instance_members
volatile ReflectStatus instance_members_reflected
jclass java_class
int modifiers
const char * name
int num_instance_members
int num_static_members
int ref_count
JavaMemberDescriptor * static_members
volatile ReflectStatus static_members_reflected
JavaSignatureChar type
struct JavaObjectWrapper

Definition at line 215 of file jsj_private.h.

Collaboration diagram for JavaObjectWrapper:
Class Members
JavaClassDescriptor * class_descriptor
jobject java_obj
union JavaObjectWrapper u
struct JSJavaVM

Definition at line 235 of file jsj_private.h.

Collaboration diagram for JSJavaVM:
Class Members
void * init_args
SystemJavaVM * java_vm
JSPackedBool jsj_created_java_vm
JSPackedBool jsj_inited_java_vm
JNIEnv * main_thread_env
JSJavaVM * next
int num_attached_threads
struct JSJavaThreadState

Definition at line 249 of file jsj_private.h.

Collaboration diagram for JSJavaThreadState:
Class Members
JSContext * cx
JNIEnv * jEnv
JSJavaVM * jsjava_vm
const char * name
JSJavaThreadState * next
CapturedJSError * pending_js_errors
int recursion_depth
struct JavaToJSSavedState

Definition at line 259 of file jsj_private.h.

Collaboration diagram for JavaToJSSavedState:
Class Members
JSErrorReporter error_reporter
JSJavaThreadState * java_jsj_env
struct JSObjectHandle

Definition at line 268 of file jsj_private.h.

Collaboration diagram for JSObjectHandle:
Class Members
JSObject * js_obj
JSRuntime * rt
union JavaObjectWrapper.u

Definition at line 218 of file jsj_private.h.

Class Members
JSJHashNumber hash_code
JavaObjectWrapper * next

Define Documentation

#define ACC_ABSTRACT   0x0400 /* no definition provided */

Definition at line 231 of file jsj_private.h.

#define ACC_FINAL   0x0010 /* no further subclassing,overriding */

Definition at line 229 of file jsj_private.h.

#define ACC_INTERFACE   0x0200 /* class is an interface */

Definition at line 230 of file jsj_private.h.

#define ACC_PUBLIC   0x0001 /* visible to everyone */

Definition at line 227 of file jsj_private.h.

#define ACC_STATIC   0x0008 /* instance variable is static */

Definition at line 228 of file jsj_private.h.

#define IS_OBJECT_TYPE (   sig)    ((int)(sig) >= (int)JAVA_SIGNATURE_OBJECT)

Definition at line 138 of file jsj_private.h.

#define IS_PRIMITIVE_TYPE (   sig)    (((int)(sig) >= (int)JAVA_SIGNATURE_BOOLEAN) && !IS_REFERENCE_TYPE(sig)) \

Definition at line 139 of file jsj_private.h.

#define IS_REFERENCE_TYPE (   sig)    ((int)(sig) >= (int)JAVA_SIGNATURE_ARRAY)

Definition at line 137 of file jsj_private.h.

#define JS_FREE_IF (   cx,
  x 
)
Value:
JS_BEGIN_MACRO                                                          \
        if (x)                                                              \
            JS_free(cx, x);                                                 \
    JS_END_MACRO

Definition at line 663 of file jsj_private.h.

#define JSTYPE_EMPTY   -1

Definition at line 143 of file jsj_private.h.

#define MSG_DEF (   name,
  number,
  format,
  count 
)    name = number,

Definition at line 671 of file jsj_private.h.


Typedef Documentation

typedef struct CapturedJSError

Definition at line 102 of file jsj_private.h.

typedef struct JavaClassDescriptor

Definition at line 100 of file jsj_private.h.

typedef struct JavaFieldSpec JavaFieldSpec
typedef struct JavaMemberDescriptor

Definition at line 98 of file jsj_private.h.

typedef struct JavaMethodSpec

Definition at line 99 of file jsj_private.h.

typedef struct JavaObjectWrapper

Definition at line 212 of file jsj_private.h.

typedef struct JavaToJSSavedState

Definition at line 263 of file jsj_private.h.

typedef struct JSObjectHandle

Definition at line 272 of file jsj_private.h.


Enumeration Type Documentation

Enumerator:
JAVA_SIGNATURE_UNKNOWN 
JAVA_SIGNATURE_VOID 
JAVA_SIGNATURE_BOOLEAN 
JAVA_SIGNATURE_CHAR 
JAVA_SIGNATURE_BYTE 
JAVA_SIGNATURE_SHORT 
JAVA_SIGNATURE_INT 
JAVA_SIGNATURE_LONG 
JAVA_SIGNATURE_FLOAT 
JAVA_SIGNATURE_DOUBLE 
JAVA_SIGNATURE_ARRAY 
JAVA_SIGNATURE_OBJECT 
JAVA_SIGNATURE_JAVA_LANG_BOOLEAN 
JAVA_SIGNATURE_JAVA_LANG_CLASS 
JAVA_SIGNATURE_JAVA_LANG_DOUBLE 
JAVA_SIGNATURE_NETSCAPE_JAVASCRIPT_JSOBJECT 
JAVA_SIGNATURE_JAVA_LANG_OBJECT 
JAVA_SIGNATURE_JAVA_LANG_STRING 
JAVA_SIGNATURE_LIMIT 

Definition at line 109 of file jsj_private.h.

             {
    JAVA_SIGNATURE_UNKNOWN,
    JAVA_SIGNATURE_VOID,

    /* Primitive types */
    JAVA_SIGNATURE_BOOLEAN,
    JAVA_SIGNATURE_CHAR,
    JAVA_SIGNATURE_BYTE,
    JAVA_SIGNATURE_SHORT,
    JAVA_SIGNATURE_INT,
    JAVA_SIGNATURE_LONG,
    JAVA_SIGNATURE_FLOAT,
    JAVA_SIGNATURE_DOUBLE,

    /* Reference types */
    JAVA_SIGNATURE_ARRAY,              /* Any array class */
    JAVA_SIGNATURE_OBJECT,             /* non-array object, but not one of the
                                          more specific types below */
    JAVA_SIGNATURE_JAVA_LANG_BOOLEAN,  /* java.lang.Boolean */
    JAVA_SIGNATURE_JAVA_LANG_CLASS,    /* java.lang.Class */
    JAVA_SIGNATURE_JAVA_LANG_DOUBLE,   /* java.lang.Double */
    JAVA_SIGNATURE_NETSCAPE_JAVASCRIPT_JSOBJECT,  /* netscape.javascript.JSObject */
    JAVA_SIGNATURE_JAVA_LANG_OBJECT,   /* java.lang.Object */
    JAVA_SIGNATURE_JAVA_LANG_STRING,   /* java.lang.String */

    JAVA_SIGNATURE_LIMIT
} JavaSignatureChar;
enum JSJErrNum
Enumerator:
MSG_DEF 
MSG_DEF 

Definition at line 670 of file jsj_private.h.

               {
#define MSG_DEF(name, number, format, count) \
    name = number,
#include "jsj.msg"
#undef MSG_DEF
    JSJ_Err_Limit
#undef MSGDEF
};
Enumerator:
REFLECT_NO 
REFLECT_IN_PROGRESS 
REFLECT_COMPLETE 

Definition at line 188 of file jsj_private.h.


Function Documentation

JSBool JS_DLL_CALLBACK JavaObject_convert ( JSContext cx,
JSObject obj,
JSType  type,
jsval vp 
)

Definition at line 367 of file jsj_JavaObject.c.

{
    JavaObjectWrapper *java_wrapper;
    JavaClassDescriptor *class_descriptor;
    jobject java_obj;
    JNIEnv *jEnv;
    JSJavaThreadState *jsj_env;
    JSBool result;

    java_wrapper = JS_GetPrivate(cx, obj);
    if (!java_wrapper) {
        if (type == JSTYPE_OBJECT) {
            *vp = OBJECT_TO_JSVAL(obj);
            return JS_TRUE;
        }

        JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL,
                             JSJMSG_BAD_OP_JOBJECT);
        return JS_FALSE;
    }

    java_obj = java_wrapper->java_obj;
    class_descriptor = java_wrapper->class_descriptor;

    switch (type) {
    case JSTYPE_OBJECT:
        *vp = OBJECT_TO_JSVAL(obj);
        return JS_TRUE;

    case JSTYPE_FUNCTION:
        JS_ReportErrorNumber(cx, jsj_GetErrorMessage, NULL,
                             JSJMSG_CONVERT_TO_FUNC);
        return JS_FALSE;

    case JSTYPE_VOID:
    case JSTYPE_STRING:
        /* Get the Java per-thread environment pointer for this JSContext */
        jsj_env = jsj_EnterJava(cx, &jEnv);
        if (!jEnv)
            return JS_FALSE;

        /* Either extract a C-string from the java.lang.String object
           or call the Java toString() method */
        result = jsj_ConvertJavaObjectToJSString(cx, jEnv, class_descriptor, java_obj, vp);
        jsj_ExitJava(jsj_env);
        return result;

    case JSTYPE_NUMBER:
        /* Get the Java per-thread environment pointer for this JSContext */
        jsj_env = jsj_EnterJava(cx, &jEnv);
        if (!jEnv)
            return JS_FALSE;

        /* Call Java doubleValue() method, if applicable */
        result = jsj_ConvertJavaObjectToJSNumber(cx, jEnv, class_descriptor, java_obj, vp);
        jsj_ExitJava(jsj_env);
        return result;

    case JSTYPE_BOOLEAN:
        /* Get the Java per-thread environment pointer for this JSContext */
        jsj_env = jsj_EnterJava(cx, &jEnv);
        if (!jEnv)
            return JS_FALSE;

        /* Call booleanValue() method, if applicable */
        result = jsj_ConvertJavaObjectToJSBoolean(cx, jEnv, class_descriptor, java_obj, vp);
        jsj_ExitJava(jsj_env);
        return result;

    default:
        JS_ASSERT(0);
        return JS_FALSE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

JavaObject_finalize ( JSContext cx,
JSObject obj 
)

Definition at line 292 of file jsj_JavaObject.c.

{
    JavaObjectWrapper *java_wrapper;
    jobject java_obj;
    JNIEnv *jEnv;
    JSJavaThreadState *jsj_env;

    java_wrapper = JS_GetPrivate(cx, obj);
    if (!java_wrapper)
        return;
    java_obj = java_wrapper->java_obj;

    if (java_obj) {
        remove_java_obj_reflection_from_hashtable(java_obj, java_wrapper->u.hash_code);
        /* defer releasing global refs until it is safe to do so. */
        java_wrapper->u.next = deferred_wrappers;
        deferred_wrappers = java_wrapper;
    } else {
        jsj_env = jsj_EnterJava(cx, &jEnv);
        if (jEnv) {
            jsj_ReleaseJavaClassDescriptor(cx, jEnv, java_wrapper->class_descriptor);
            JS_free(cx, java_wrapper);
            jsj_ExitJava(jsj_env);
        } else {
            java_wrapper->u.next = deferred_wrappers;
            deferred_wrappers = java_wrapper;
        }
    }
}

Here is the call graph for this function:

JSBool JavaObject_getProperty ( JSContext cx,
JSObject obj,
jsval  id,
jsval vp 
)
JavaObject_getPropertyById ( JSContext cx,
JSObject obj,
jsid  id,
jsval vp 
)

Definition at line 617 of file jsj_JavaObject.c.

{
    jobject java_obj;
    JavaMemberDescriptor *member_descriptor;
    JavaObjectWrapper *java_wrapper;
    JNIEnv *jEnv;
    JSObject *funobj;
    jsval field_val, method_val;
    JSBool success;
    JSJavaThreadState *jsj_env;
    JSObject *proto_chain;
    JSJPropertyInfo prop_info;

    /* printf("In JavaObject_getProperty\n"); */

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

    if (vp)
        *vp = JSVAL_VOID;
    prop_info.wantProp = JS_FALSE;
    if (!lookup_member_by_id(cx, jEnv, obj, &java_wrapper, id, &member_descriptor, vp,
                             &proto_chain, &prop_info)) {
        jsj_ExitJava(jsj_env);
        return JS_FALSE;
    }

    /* Handle access to special, non-Java properties of JavaObjects, e.g. the
       "constructor" property of the prototype object */
    if (!member_descriptor) {
        jsj_ExitJava(jsj_env);
        if (proto_chain)
            return JS_GetProperty(cx, proto_chain, prop_info.name, vp);
        return JS_TRUE;
    }

    java_obj = java_wrapper->java_obj;
    field_val = method_val = JSVAL_VOID;

    if (jaApplet && (*jEnv)->IsInstanceOf(jEnv, java_obj, jaApplet)) {
        jsj_JSIsCallingApplet = JS_TRUE;
    }

    /* If a field member, get the value of the field */
    if (member_descriptor->field) {
        success = jsj_GetJavaFieldValue(cx, jEnv, member_descriptor->field, java_obj, &field_val);
        if (!success) {
            jsj_ExitJava(jsj_env);
            return JS_FALSE;
        }
    }

    /* If a method member, build a wrapper around the Java method */
    if (member_descriptor->methods) {
        /* Create a function object with this JavaObject as its parent, so that
           JSFUN_BOUND_METHOD binds it as the default 'this' for the function. */
        funobj = JS_CloneFunctionObject(cx, member_descriptor->invoke_func_obj, obj);
        if (!funobj) {
            jsj_ExitJava(jsj_env);
            return JS_FALSE;
        }
        method_val = OBJECT_TO_JSVAL(funobj);
    }

#if TEST_JAVAMEMBER
    /* Always create a JavaMember object, even though it's inefficient */
    obj = jsj_CreateJavaMember(cx, method_val, field_val);
    if (!obj) {
        jsj_ExitJava(jsj_env);
        return JS_FALSE;
    }
    *vp = OBJECT_TO_JSVAL(obj);
#else   /* !TEST_JAVAMEMBER */

    if (member_descriptor->field) {
        if (!member_descriptor->methods) {
            /* Return value of Java field */
            *vp = field_val;
        } else {
            /* Handle special case of access to a property that could refer
               to either a Java field or a method that share the same name.
               In Java, such ambiguity is not possible because the compiler
               can statically determine which is being accessed. */
            obj = jsj_CreateJavaMember(cx, method_val, field_val);
            if (!obj) {
                jsj_ExitJava(jsj_env);
                return JS_FALSE;
            }
            *vp = OBJECT_TO_JSVAL(obj);
        }

    } else {
        /* Return wrapper around Java method */
        *vp = method_val;
    }

#endif  /* !TEST_JAVAMEMBER */

    jsj_ExitJava(jsj_env);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool JavaObject_resolve ( JSContext cx,
JSObject obj,
jsval  id 
)
JSBool JavaStringToId ( JSContext cx,
JNIEnv jEnv,
jstring  jstr,
jsid idp 
)

Definition at line 136 of file jsj_utils.c.

{
    const jschar *ucs2;
    JSString *jsstr;
    jsize ucs2_len;
    jsval val;
    
    ucs2 = (*jEnv)->GetStringChars(jEnv, jstr, 0);
    if (!ucs2) {
        jsj_UnexpectedJavaError(cx, jEnv, "Couldn't obtain Unicode characters"
                                "from Java string");
        return JS_FALSE;
    }
    
    ucs2_len = (*jEnv)->GetStringLength(jEnv, jstr);
    jsstr = JS_InternUCStringN(cx, ucs2, ucs2_len);
    (*jEnv)->ReleaseStringChars(jEnv, jstr, ucs2);
    if (!jsstr)
        return JS_FALSE;

    val = STRING_TO_JSVAL(jsstr);
    JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), idp);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* jsj_ClassNameOfJavaObject ( JSContext cx,
JNIEnv jEnv,
jobject  java_object 
)

Definition at line 451 of file jsj_JSObject.c.

{
    while (jsj_env->pending_js_errors)
        jsj_env->pending_js_errors = destroy_saved_js_error(jsj_env->jEnv, jsj_env->pending_js_errors);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ComputeJavaClassSignature ( JSContext cx,
JavaSignature *  signature,
jclass  java_class 
)
const char* jsj_ConvertJavaMethodSignatureToHRString ( JSContext cx,
const char *  method_name,
JavaMethodSignature method_signature 
)

Definition at line 206 of file jsj_method.c.

{
    JavaSignature **arg_signatures, *return_val_signature;
    const char *arg_sigs_cstr;
    const char *return_val_sig_cstr;
    const char *sig_cstr;

    arg_signatures = method_signature->arg_signatures;
    return_val_signature = method_signature->return_val_signature;

    /* Convert the method argument signatures to a C-string */
    arg_sigs_cstr =
            convert_java_method_arg_signatures_to_hr_string(cx, arg_signatures,
                                                            method_signature->num_args,
                                                     JS_TRUE);
    if (!arg_sigs_cstr)
        return NULL;

    /* Convert the method return value signature to a C-string */
    return_val_sig_cstr = jsj_ConvertJavaSignatureToHRString(cx, return_val_signature);
    if (!return_val_sig_cstr) {
        free((void*)arg_sigs_cstr);
        return NULL;
    }

    /* Compose method arg signatures string and return val signature string */
    sig_cstr = JS_smprintf("%s %s(%s)", return_val_sig_cstr, method_name, arg_sigs_cstr);
    free((void*)arg_sigs_cstr);
    free((void*)return_val_sig_cstr);

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 382 of file jsj_method.c.

{
    JavaSignature **arg_signatures, *return_val_signature;
    const char *arg_sigs_cstr;
    const char *return_val_sig_cstr;
    const char *sig_cstr;

    arg_signatures = method_signature->arg_signatures;
    return_val_signature = method_signature->return_val_signature;

    /* Convert the method argument signatures to a C-string */
    arg_sigs_cstr = NULL;
    if (arg_signatures) {
        arg_sigs_cstr =
            convert_java_method_arg_signatures_to_string(cx, arg_signatures,
                                                         method_signature->num_args);
        if (!arg_sigs_cstr)
            return NULL;
    }

    /* Convert the method return value signature to a C-string */
    return_val_sig_cstr = jsj_ConvertJavaSignatureToString(cx, return_val_signature);
    if (!return_val_sig_cstr) {
        free((void*)arg_sigs_cstr);
        return NULL;
    }

    /* Compose method arg signatures string and return val signature string */
    if (arg_sigs_cstr) {
        sig_cstr = JS_smprintf("(%s)%s", arg_sigs_cstr, return_val_sig_cstr);
        free((void*)arg_sigs_cstr);
    } else {
        sig_cstr = JS_smprintf("()%s", return_val_sig_cstr);
    }

    free((void*)return_val_sig_cstr);

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

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:

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:

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

JSObject* jsj_CreateJavaMember ( JSContext cx,
jsval  method_val,
jsval  field_val 
)

Definition at line 73 of file jsj_JavaMember.c.

{
    JavaMethodOrFieldValue *member_val;
    JSObject *JavaMember_obj;
    
    member_val = (JavaMethodOrFieldValue *)JS_malloc(cx, sizeof(*member_val));
    if (!member_val)
        return NULL;
    
    JavaMember_obj = JS_NewObject(cx, &JavaMember_class, 0, 0);
    if (!JavaMember_obj) {
        JS_free(cx, member_val);
        return NULL;
    }

    JS_SetPrivate(cx, JavaMember_obj, (void *)member_val);
    member_val->method_val = method_val;
    JS_AddNamedRoot(cx, &member_val->method_val, "&member_val->method_val");
    member_val->field_val = field_val;
    if (JSVAL_IS_GCTHING(field_val))
        JS_AddNamedRoot(cx, &member_val->field_val, "&member_val->field_val");

    return JavaMember_obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSObject* jsj_define_JavaClass ( JSContext cx,
JNIEnv jEnv,
JSObject obj,
const char *  unqualified_class_name,
jclass  jclazz 
)

Definition at line 613 of file jsj_JavaClass.c.

{
    JavaClassDescriptor *class_descriptor;
    JSObject *JavaClass_obj;

    class_descriptor = jsj_GetJavaClassDescriptor(cx, jEnv, java_class);
    if (!class_descriptor)
        return NULL;

    JavaClass_obj = jsj_new_JavaClass(cx, jEnv, parent_obj, class_descriptor);
    if (!JavaClass_obj)
        return NULL;

    if (!JS_DefineProperty(cx, parent_obj, simple_class_name,
                           OBJECT_TO_JSVAL(JavaClass_obj), 0, 0,
                           JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE))
        return NULL;
    return JavaClass_obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void jsj_DestroyFieldSpec ( JSContext cx,
JNIEnv jEnv,
JavaFieldSpec field 
)

Definition at line 153 of file jsj_field.c.

{
    JS_FREE_IF(cx, (char*)field->name);
    jsj_ReleaseJavaClassDescriptor(cx, jEnv, field->signature);
    JS_free(cx, field);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void jsj_DestroyMethodSpec ( JSContext cx,
JNIEnv jEnv,
JavaMethodSpec method_spec 
)

Definition at line 625 of file jsj_method.c.

{
    if (!method_spec->is_alias) {
       JS_FREE_IF(cx, (char*)method_spec->name);
       jsj_PurgeJavaMethodSignature(cx, jEnv, &method_spec->signature);
    }
    JS_free(cx, method_spec);
}

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 346 of file jsj_JavaObject.c.

{
    JSJavaThreadState *jsj_env;
    char *err_msg;

    /* 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;

    if (java_obj_reflections) {
        JSJ_HashTableEnumerateEntries(java_obj_reflections,
                                      enumerate_remove_java_obj,
                                      (void*)jsj_env);
        JSJ_HashTableDestroy(java_obj_reflections);
        java_obj_reflections = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* jsj_DupJavaStringUTF ( JSContext cx,
JNIEnv jEnv,
jstring  jstr 
)

Definition at line 120 of file jsj_utils.c.

{
    const char *str, *retval;

    str = (*jEnv)->GetStringUTFChars(jEnv, jstr, 0);
    if (!str) {
        jsj_UnexpectedJavaError(cx, jEnv, "Can't get UTF8 characters from "
                                          "Java string");
        return NULL;
    }
    retval = JS_strdup(cx, str);
    (*jEnv)->ReleaseStringUTFChars(jEnv, jstr, str);
    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSJavaThreadState* jsj_enter_js ( JNIEnv jEnv,
void java_applet_obj,
jobject  java_wrapper_obj,
JSContext **  cxp,
JSObject **  js_objp,
JSErrorReporter *  old_error_reporterp,
void **  pNSIPrincipaArray,
int  numPrincipals,
void pNSISecurityContext 
)

Definition at line 697 of file jsj_JSObject.c.

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

    cx = NULL;
    err_msg = NULL;

    /* Invoke callback, presumably used to implement concurrency constraints */
    if (JSJ_callbacks && JSJ_callbacks->enter_js_from_java) {
#ifdef OJI
        if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg, pNSIPrincipaArray, numPrincipals, pNSISecurityContext,applet_obj))
#else
        if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg))
#endif
            goto entry_failure;
    }

    /* Check the JSObject pointer in the wrapper object. */
    if (js_objp) {

#ifdef PRESERVE_JSOBJECT_IDENTITY
#if JS_BYTES_PER_LONG == 8
        js_obj = (JSObject *)((*jEnv)->GetLongField(jEnv, java_wrapper_obj, njJSObject_long_internal));
#else
        js_obj = (JSObject *)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, njJSObject_internal));
#endif
#else   /* !PRESERVE_JSOBJECT_IDENTITY */
        js_obj = jsj_UnwrapJSObjectWrapper(jEnv, java_wrapper_obj);
#endif  /* PRESERVE_JSOBJECT_IDENTITY */

        JS_ASSERT(js_obj);
        if (!js_obj)
            goto error;
        *js_objp = js_obj;
    }

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

    /* 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 && JSJ_callbacks->map_jsj_thread_to_js_context) {
#ifdef OJI
            cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
                                                             applet_obj,
                                                             jEnv, &err_msg);
#else
            cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
                                                             jEnv, &err_msg);
#endif
            if (!cx)
                goto error;
        } else {
            err_msg = JS_smprintf("Unable to find/create JavaScript execution "
                                  "context for JNI thread 0x%08x", jEnv);
            goto error;
        }
    }
    *cxp = cx;

    /*
     * Capture all JS error reports so that they can be thrown into the Java
     * caller as an instance of netscape.javascript.JSException.
     */
    *old_error_reporterp =
        JS_SetErrorReporter(cx, capture_js_error_reports_for_java);

#ifdef JSJ_THREADSAFE
    JS_BeginRequest(cx);
#endif

    return jsj_env;

error:
    /* Invoke callback, presumably used to implement concurrency constraints */
    if (JSJ_callbacks && JSJ_callbacks->exit_js)
        JSJ_callbacks->exit_js(jEnv, cx);

entry_failure:
    if (err_msg) {
        if (cx)
            JS_ReportError(cx, err_msg);
        else
            jsj_LogError(err_msg);
        free(err_msg);
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSJavaThreadState* jsj_EnterJava ( JSContext cx,
JNIEnv **  envp 
)

Definition at line 454 of file jsj_utils.c.

{
    JSJavaThreadState *jsj_env;
    char *err_msg;

    *envp = NULL;
    err_msg = NULL;

    jsj_env = the_java_jsj_env;
    if (jsj_env == NULL && JSJ_callbacks && JSJ_callbacks->map_js_context_to_jsj_thread)
        jsj_env = JSJ_callbacks->map_js_context_to_jsj_thread(cx, &err_msg);
    if (!jsj_env) {
        if (err_msg) {
            JS_ReportError(cx, err_msg);
            free(err_msg);
        }
        return NULL;
    }

    /* simultaneous calls from different JSContext are not allowed */
    if ((jsj_env->recursion_depth > 0) && (jsj_env->cx != cx))
        return NULL;

    jsj_env->recursion_depth++;

    /* bug #60018:  prevent dangling pointer to JSContext */
    if (!jsj_env->cx)
        jsj_env->cx = cx;

    if (envp)
        *envp = jsj_env->jEnv;
    return jsj_env;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_exit_js ( JSContext cx,
JSJavaThreadState jsj_env,
JSErrorReporter  old_error_reporterp 
)

Definition at line 802 of file jsj_JSObject.c.

{
    JNIEnv *jEnv;

#ifdef JSJ_THREADSAFE
    JS_EndRequest(cx);
#endif

    /* Restore the JS error reporter */
    JS_SetErrorReporter(cx, original_reporter);

    jEnv = jsj_env->jEnv;

#ifdef DEBUG
    /* Any Java exceptions should have been noticed and reported already */
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        JS_ASSERT(0);
        jsj_LogError("Unhandled Java exception detected");
        return JS_FALSE;
    }
#endif

    /*
     * Convert reported JS errors to JSExceptions, unless the errors were
     * themselves the result of Java exceptions, in which case the original
     * Java exception is simply propagated.
     */
    throw_any_pending_js_error_as_a_java_exception(jsj_env);

    /* Invoke callback, presumably used to implement concurrency constraints */
    if (JSJ_callbacks && JSJ_callbacks->exit_js)
        JSJ_callbacks->exit_js(jEnv, cx);

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 489 of file jsj_utils.c.

{
    jsj_JSIsCallingApplet = JS_FALSE;
    if (jsj_env) {
        JS_ASSERT(jsj_env->recursion_depth > 0);
        if (--jsj_env->recursion_depth == 0)
            jsj_env->cx = NULL;
    }
}

Here is the caller graph for this function:

Definition at line 841 of file jsj_JSObject.c.

{
    /* The JavaClassDescriptor for java.lang.Object */
    static JavaClassDescriptor *jlObject_descriptor = NULL;

    if (!jlObject_descriptor)
        jlObject_descriptor = jsj_GetJavaClassDescriptor(cx, jEnv, jlObject);
    return jlObject_descriptor;
}

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:

const JSErrorFormatString* JS_DLL_CALLBACK jsj_GetErrorMessage ( void userRef,
const char *  locale,
const uintN  errorNumber 
)

Definition at line 430 of file jsj_utils.c.

{
    if ((errorNumber > 0) && (errorNumber < JSJ_Err_Limit))
            return &jsj_ErrorFormatString[errorNumber];
        else
            return NULL;
}

Here is the caller graph for this function:

JSBool jsj_GetJavaArrayElement ( JSContext cx,
JNIEnv jEnv,
jarray  java_array,
jsize  index,
JavaSignature *  array_component_signature,
jsval vp 
)

Definition at line 56 of file jsj_array.c.

{
    jvalue java_value;
    JavaSignatureChar component_type;
    JSBool success;

#define GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Type,member)                   \
    (*jEnv)->Get##Type##ArrayRegion(jEnv, java_array, index, 1,              \
                                    &java_value.member);                     \
    if ((*jEnv)->ExceptionOccurred(jEnv)) {                                  \
        jsj_ReportJavaError(cx, jEnv, "Error reading element of "            \
                                      "Java primitive array");               \
        return JS_FALSE;                                                     \
    }

    component_type = array_component_signature->type;
    switch(component_type) {
    case JAVA_SIGNATURE_BYTE:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Byte,b);
        break;

    case JAVA_SIGNATURE_CHAR:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Char,c);
        break;

    case JAVA_SIGNATURE_SHORT:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Short,s);
        break;

    case JAVA_SIGNATURE_INT:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Int,i);
        break;

    case JAVA_SIGNATURE_BOOLEAN:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Boolean,z);
        break;

    case JAVA_SIGNATURE_LONG:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Long,j);
        break;
  
    case JAVA_SIGNATURE_FLOAT:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Float,f);
        break;

    case JAVA_SIGNATURE_DOUBLE:
        GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Double,d);
        break;

    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(component_type >= JAVA_SIGNATURE_ARRAY);
        java_value.l = (*jEnv)->GetObjectArrayElement(jEnv, java_array, index);
        if ((*jEnv)->ExceptionOccurred(jEnv)) {
            jsj_ReportJavaError(cx, jEnv, "Error reading Java object array");
            return JS_FALSE;
        }
        success = jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_value.l, vp);
        (*jEnv)->DeleteLocalRef(jEnv, java_value.l);
        return success;

#undef GET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY
    case JAVA_SIGNATURE_UNKNOWN:
    case JAVA_SIGNATURE_VOID:
        JS_ASSERT(0);        /* Unknown java type signature */
        return JS_FALSE;
    }

    return jsj_ConvertJavaValueToJSValue(cx, jEnv, array_component_signature, &java_value, vp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsize jsj_GetJavaArrayLength ( JSContext cx,
JNIEnv jEnv,
jarray  java_array 
)

Definition at line 439 of file jsj_utils.c.

{
    jsize array_length = (*jEnv)->GetArrayLength(jEnv, java_array);
    jthrowable java_exception = (*jEnv)->ExceptionOccurred(jEnv);
    if (java_exception) {
        jsj_UnexpectedJavaError(cx, jEnv, "Couldn't obtain array length");
        (*jEnv)->DeleteLocalRef(jEnv, java_exception);
        return -1;
    }
    return array_length;
}

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:

Definition at line 172 of file jsj_utils.c.

{
    const char *java_error_msg;
    char *error_msg = NULL;
    jthrowable exception;
    jstring java_exception_jstring;

    exception = (*jEnv)->ExceptionOccurred(jEnv);
    if (exception && jlThrowable_toString) {
        java_exception_jstring =
            (*jEnv)->CallObjectMethod(jEnv, exception, jlThrowable_toString);
        if (!java_exception_jstring)
            goto done;
        java_error_msg = (*jEnv)->GetStringUTFChars(jEnv, java_exception_jstring, NULL);
        if (java_error_msg) {
            error_msg = strdup((char*)java_error_msg);
            (*jEnv)->ReleaseStringUTFChars(jEnv, java_exception_jstring, java_error_msg);
        }
        (*jEnv)->DeleteLocalRef(jEnv, java_exception_jstring);

#ifdef DEBUG
        /* (*jEnv)->ExceptionDescribe(jEnv); */
#endif
    }
done:
    if (exception)
        (*jEnv)->DeleteLocalRef(jEnv, exception);
    return error_msg;
}    

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_GetJavaFieldValue ( JSContext cx,
JNIEnv jEnv,
JavaFieldSpec field_spec,
jobject  java_obj,
jsval vp 
)

Definition at line 259 of file jsj_field.c.

{
    JSBool is_static_field, success;
    jvalue java_value;
    JavaSignature *signature;
    JavaSignatureChar field_type;
    jfieldID fieldID = field_spec->fieldID;

    is_static_field = field_spec->modifiers & ACC_STATIC;

#define GET_JAVA_FIELD(Type,member)                                          \
    JS_BEGIN_MACRO                                                           \
    if (is_static_field)                                                     \
        java_value.member =                                                  \
            (*jEnv)->GetStatic##Type##Field(jEnv, (*jEnv)->GetObjectClass(jEnv, java_obj), fieldID);        \
    else                                                                     \
        java_value.member =                                                  \
            (*jEnv)->Get##Type##Field(jEnv, java_obj, fieldID);              \
    if ((*jEnv)->ExceptionOccurred(jEnv)) {                                  \
        jsj_UnexpectedJavaError(cx, jEnv, "Error reading Java field");           \
        return JS_FALSE;                                                     \
    }                                                                        \
    JS_END_MACRO

    signature = field_spec->signature;
    field_type = signature->type;
    switch(field_type) {
    case JAVA_SIGNATURE_BYTE:
        GET_JAVA_FIELD(Byte,b);
        break;

    case JAVA_SIGNATURE_CHAR:
        GET_JAVA_FIELD(Char,c);
        break;

    case JAVA_SIGNATURE_SHORT:
        GET_JAVA_FIELD(Short,s);
        break;

    case JAVA_SIGNATURE_INT:
        GET_JAVA_FIELD(Int,i);
        break;

    case JAVA_SIGNATURE_BOOLEAN:
        GET_JAVA_FIELD(Boolean,z);
        break;

    case JAVA_SIGNATURE_LONG:
        GET_JAVA_FIELD(Long,j);
        break;
  
    case JAVA_SIGNATURE_FLOAT:
        GET_JAVA_FIELD(Float,f);
        break;

    case JAVA_SIGNATURE_DOUBLE:
        GET_JAVA_FIELD(Double,d);
        break;
     
    case JAVA_SIGNATURE_UNKNOWN:
    case JAVA_SIGNATURE_VOID:
        JS_ASSERT(0);        /* Unknown java type signature */
        return JS_FALSE;
        
    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(field_type));
        GET_JAVA_FIELD(Object,l);
        success = jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_value.l, vp);
        (*jEnv)->DeleteLocalRef(jEnv, java_value.l);
        return success;
    }
    
#undef GET_JAVA_FIELD

    return jsj_ConvertJavaValueToJSValue(cx, jEnv, signature, &java_value, vp);
}

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 
)

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 
)

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 67 of file jsj_utils.c.

{
    JSHashNumber hash_code;
    jobject java_obj;
    JNIEnv *jEnv;

    java_obj = (jobject)key;
    jEnv = (JNIEnv*) env;
    JS_ASSERT(!(*jEnv)->ExceptionOccurred(jEnv));
    hash_code = (*jEnv)->CallStaticIntMethod(jEnv, jlSystem,
                                             jlSystem_identityHashCode, java_obj);

#ifdef DEBUG
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        (*jEnv)->ExceptionDescribe(jEnv);
        JS_ASSERT(0);
    }
#endif

    return hash_code;
}

Here is the caller graph for this function:

JSBool jsj_init_JavaArray ( JSContext cx,
JSObject global_obj 
)

Here is the caller graph for this function:

JSBool jsj_init_JavaClass ( JSContext cx,
JSObject global_obj 
)

Here is the caller graph for this function:

Definition at line 177 of file jsj_JavaMember.c.

{
    if (!JS_InitClass(cx, global_obj, 
        0, &JavaMember_class, 0, 0,
        0, 0,
        0, 0))
        return JS_FALSE;

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Here is the caller graph for this function:

JSBool jsj_init_JavaPackage ( JSContext ,
JSObject ,
JavaPackageDef predefined_packages 
)

Definition at line 533 of file jsj_JavaPackage.c.

                                                                     {

    /* Define JavaPackage class */
    if (!JS_InitClass(cx, global_obj, 0, &JavaPackage_class,
                      0, 0, 0, JavaPackage_methods, 0, 0))
        return JS_FALSE;

    /* Add top-level packages, e.g. : java, netscape, sun */
    if (!pre_define_java_packages(cx, global_obj, standard_java_packages))
        return JS_FALSE;
    if (!pre_define_java_packages(cx, global_obj, additional_predefined_packages))
        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 101 of file jsj_JSObject.c.

{
#ifdef PRESERVE_JSOBJECT_IDENTITY
    if(js_obj_reflections != NULL)
    {
      return JS_TRUE;
    }
    js_obj_reflections = JS_NewHashTable(128, NULL, JS_CompareValues,
                                         JS_CompareValues, NULL, NULL);
    if (!js_obj_reflections)
        return JS_FALSE;

#ifdef JSJ_THREADSAFE
    js_obj_reflections_monitor = PR_NewMonitor();
    if (!js_obj_reflections_monitor) {
        JS_HashTableDestroy(js_obj_reflections);
        return JS_FALSE;
    }
#endif  /* JSJ_THREADSAFE */
#endif  /* PRESERVE_JSOBJECT_IDENTITY */

    return JS_TRUE;
}

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:

JavaMethodSignature* jsj_InitJavaMethodSignature ( JSContext cx,
JNIEnv jEnv,
jobject  method,
JavaMethodSignature method_signature 
)

Definition at line 279 of file jsj_method.c.

{
    int i;
    jboolean is_constructor;
    jclass return_val_class;
    jsize num_args;
    JavaSignature *return_val_signature;
    jarray arg_classes;
    jmethodID getParameterTypes;

    memset(method_signature, 0, sizeof (JavaMethodSignature));
    
    is_constructor = (*jEnv)->IsInstanceOf(jEnv, method, jlrConstructor);

    /* Get a Java array that lists the class of each of the method's arguments */
    if  (is_constructor)
        getParameterTypes = jlrConstructor_getParameterTypes;
    else
        getParameterTypes = jlrMethod_getParameterTypes;
    arg_classes = (*jEnv)->CallObjectMethod(jEnv, method, getParameterTypes);
    if (!arg_classes) {
        jsj_UnexpectedJavaError(cx, jEnv,
                                "Can't determine argument signature of method");
        goto error;
    }

    /* Compute the number of method arguments */
    num_args = jsj_GetJavaArrayLength(cx, jEnv, arg_classes);
    if (num_args < 0)
        goto error;
    method_signature->num_args = num_args;

    /* Build a JavaSignature array corresponding to the method's arguments */
    if (num_args) {
        JavaSignature **arg_signatures;

        /* Allocate an array of JavaSignatures, one for each method argument */
        size_t arg_signatures_size = num_args * sizeof(JavaSignature *);
        arg_signatures = (JavaSignature **)JS_malloc(cx, arg_signatures_size);
        if (!arg_signatures)
            goto error;
        memset(arg_signatures, 0, arg_signatures_size);
        method_signature->arg_signatures = arg_signatures;
        
        /* Build an array of JavaSignature objects, each of which corresponds
           to the type of an individual method argument. */
        for (i = 0; i < num_args; i++) {
            JavaSignature *a;
            jclass arg_class = (*jEnv)->GetObjectArrayElement(jEnv, arg_classes, i);
            
            a = arg_signatures[i] = jsj_GetJavaClassDescriptor(cx, jEnv, arg_class);
            (*jEnv)->DeleteLocalRef(jEnv, arg_class);
            if (!a) {
                jsj_UnexpectedJavaError(cx, jEnv, "Could not determine Java class "
                                                  "signature using java.lang.reflect");
                goto error;
            }
        }
    }

    /* Get the Java class of the method's return value */
    if (is_constructor) {
        /* Constructors always have a "void" return type */
        return_val_signature = jsj_GetJavaClassDescriptor(cx, jEnv, jlVoid_TYPE);
    } else {
        return_val_class =
            (*jEnv)->CallObjectMethod(jEnv, method, jlrMethod_getReturnType);
        if (!return_val_class) {
            jsj_UnexpectedJavaError(cx, jEnv,
                                    "Can't determine return type of method "
                                    "using java.lang.reflect.Method.getReturnType()");
            goto error;
        }

        /* Build a JavaSignature object corresponding to the method's return value */
        return_val_signature = jsj_GetJavaClassDescriptor(cx, jEnv, return_val_class);
        (*jEnv)->DeleteLocalRef(jEnv, return_val_class);
    }

    if (!return_val_signature)
        goto error;
    method_signature->return_val_signature = return_val_signature;

    (*jEnv)->DeleteLocalRef(jEnv, arg_classes);
    return method_signature;

error:

    if (arg_classes)
        (*jEnv)->DeleteLocalRef(jEnv, arg_classes);
    jsj_PurgeJavaMethodSignature(cx, jEnv, method_signature);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 116 of file jsj_JavaObject.c.

{
    JS_ASSERT(!java_obj_reflections);

    java_obj_reflections =
        JSJ_NewHashTable(512, jsj_HashJavaObject, jsj_JavaObjectComparator,
                         NULL, NULL, NULL);
    if (!java_obj_reflections)
        return JS_FALSE;

#ifdef JSJ_THREADSAFE
    java_obj_reflections_monitor = (struct PRMonitor *) PR_NewMonitor();
    if (!java_obj_reflections_monitor) {
        JSJ_HashTableDestroy(java_obj_reflections);
        return JS_FALSE;
    }
#endif

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsj_JavaConstructorWrapper ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval vp 
)

Definition at line 1682 of file jsj_method.c.

{
    JavaClassDescriptor *class_descriptor;
    JavaMemberDescriptor *member_descriptor;
    JSJavaThreadState *jsj_env;
    JNIEnv *jEnv;
    JSBool result;

    obj = JSVAL_TO_OBJECT(argv[-2]);
    class_descriptor = JS_GetPrivate(cx, obj);
    JS_ASSERT(class_descriptor);
    if (!class_descriptor)
        return JS_FALSE;

    /* XXX, workaround for bug 200016, all classes in sun.plugin package should not 
       be accessible in liveconnect.
       Ideally, this checking should be done in JPI side, but it's not going to happen 
       until Sun JRE 1.5.1 */
    if (strstr(class_descriptor->name, "sun.plugin.") == class_descriptor->name)
        return JS_FALSE;
  
    /* Get the Java per-thread environment pointer for this JSContext */
    jsj_env = jsj_EnterJava(cx, &jEnv);
    if (!jEnv)
        return JS_FALSE;
    member_descriptor = jsj_LookupJavaClassConstructors(cx, jEnv, class_descriptor);
    result = java_constructor_wrapper(cx, jsj_env, member_descriptor, 
                                      class_descriptor, argc, argv, vp);
    jsj_ExitJava(jsj_env);
    return result;
}

Here is the call graph for this function:

jsj_JavaInstanceMethodWrapper ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval vp 
)

Definition at line 1776 of file jsj_method.c.

{
    JSFunction *function;
    JavaMemberDescriptor *member_descriptor;
    JavaObjectWrapper *java_wrapper;
    JavaClassDescriptor *class_descriptor;
    jsid id;
    jsval idval;
    JSJavaThreadState *jsj_env;
    JNIEnv *jEnv;
    jobject java_obj;
    JSBool result;
    
    java_wrapper = JS_GetPrivate(cx, obj);
    if (!java_wrapper)
        return JS_FALSE;
    java_obj = java_wrapper->java_obj;
    
    JS_ASSERT(JS_TypeOfValue(cx, argv[-2]) == JSTYPE_FUNCTION);
    function = JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[-2]));
    idval = STRING_TO_JSVAL(JS_InternString(cx, JS_GetFunctionName(function)));
    JS_ValueToId(cx, idval, &id);
    class_descriptor = java_wrapper->class_descriptor;
    
    /* Get the Java per-thread environment pointer for this JSContext */
    jsj_env = jsj_EnterJava(cx, &jEnv);
    if (!jEnv)
        return JS_FALSE;

    if (jaApplet && (*jEnv)->IsInstanceOf(jEnv, java_obj, jaApplet)) {
        jsj_JSIsCallingApplet = JS_TRUE;
    }

    /* Try to find an instance method with the given name first */
    member_descriptor = jsj_LookupJavaMemberDescriptorById(cx, jEnv, class_descriptor, id);
    if (member_descriptor)
        result = invoke_overloaded_java_method(cx, jsj_env, member_descriptor,
                                               JS_FALSE, java_obj, 
                                               class_descriptor, argc, argv, vp);

    /* If no instance method was found, try for a static method or constructor */
    else
       result = static_method_wrapper(cx, jsj_env, class_descriptor, id, argc, argv, 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 97 of file jsj_utils.c.

{
    jobject java_obj1, java_obj2;
    JNIEnv *jEnv;

    jEnv = (JNIEnv*)arg;
    java_obj1 = (jobject)v1;
    java_obj2 = (jobject)v2;

    if (java_obj1 == java_obj2)
        return 1;
    if (jEnv)
        return (*jEnv)->IsSameObject(jEnv, java_obj1, java_obj2);
    return 0;
}

Here is the caller graph for this function:

jsj_JavaStaticMethodWrapper ( JSContext cx,
JSObject obj,
uintN  argc,
jsval argv,
jsval vp 
)

Definition at line 1745 of file jsj_method.c.

{
    JSFunction *function;
    JavaClassDescriptor *class_descriptor;
    jsid id;
    jsval idval;
    JNIEnv *jEnv;
    JSJavaThreadState *jsj_env;
    JSBool result;
    
    class_descriptor = JS_GetPrivate(cx, obj);
    if (!class_descriptor)
        return JS_FALSE;

    /* Get the Java per-thread environment pointer for this JSContext */
    jsj_env = jsj_EnterJava(cx, &jEnv);
    if (!jEnv)
        return JS_FALSE;
    
    JS_ASSERT(JS_TypeOfValue(cx, argv[-2]) == JSTYPE_FUNCTION);
    function = JS_GetPrivate(cx, JSVAL_TO_OBJECT(argv[-2]));
    idval = STRING_TO_JSVAL(JS_InternString(cx, JS_GetFunctionName(function)));
    JS_ValueToId(cx, idval, &id);

    result = static_method_wrapper(cx, jsj_env, class_descriptor, id, argc, argv, vp);
    jsj_ExitJava(jsj_env);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void jsj_LogError ( const char *  error_msg)

Definition at line 395 of file jsj_utils.c.

{
    if (JSJ_callbacks && JSJ_callbacks->error_print)
        JSJ_callbacks->error_print(error_msg);
    else
        fputs(error_msg, stderr);
}

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 *  jClassName)

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:

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:

void jsj_PurgeJavaMethodSignature ( JSContext cx,
JNIEnv jEnv,
JavaMethodSignature signature 
)

Definition at line 249 of file jsj_method.c.

{
    int i, num_args;
    JavaSignature **arg_signatures;

    if (!method_signature)  /* Paranoia */
        return;

    /* Free the method argument signatures */
    num_args = method_signature->num_args;
    arg_signatures = method_signature->arg_signatures;
    for (i = 0; i < num_args; i++)
        jsj_ReleaseJavaClassDescriptor(cx, jEnv, arg_signatures[i]);
    if (arg_signatures)
        JS_free(cx, arg_signatures);

    /* Free the return type signature */
    if (method_signature->return_val_signature)
        jsj_ReleaseJavaClassDescriptor(cx, jEnv, method_signature->return_val_signature);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ReflectJavaFields ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
JSBool  reflect_only_static_fields 
)

Definition at line 171 of file jsj_field.c.

{
    int i;
    JSBool ok;
    jint modifiers;
    jobject java_field;
    jstring field_name_jstr;
    jarray joFieldArray;
    jsize num_fields;
    jclass java_class;

    /* Get a java array of java.lang.reflect.Field objects, by calling
       java.lang.Class.getFields(). */
    java_class = class_descriptor->java_class;
    joFieldArray = (*jEnv)->CallObjectMethod(jEnv, java_class, jlClass_getFields);
    if (!joFieldArray) {
        jsj_UnexpectedJavaError(cx, jEnv,
                                "Can't determine Java object's fields "
                                "using java.lang.Class.getFields()");
        return JS_FALSE;
    }

    /* Iterate over the class fields */
    num_fields = (*jEnv)->GetArrayLength(jEnv, joFieldArray);
    for (i = 0; i < num_fields; i++) {
       
        /* Get the i'th reflected field */
        java_field = (*jEnv)->GetObjectArrayElement(jEnv, joFieldArray, i);
        if (!java_field) {
            jsj_UnexpectedJavaError(cx, jEnv, "Can't access a Field[] array");
            return JS_FALSE;
        }

        /* Get the field modifiers, e.g. static, public, private, etc. */
        modifiers = (*jEnv)->CallIntMethod(jEnv, java_field, jlrField_getModifiers);
        if ((*jEnv)->ExceptionOccurred(jEnv)) {
            jsj_UnexpectedJavaError(cx, jEnv,
                                    "Can't access a Field's modifiers using"
                                    "java.lang.reflect.Field.getModifiers()");
            return JS_FALSE;
        }

        /* Don't allow access to private or protected Java fields. */
        if (!(modifiers & ACC_PUBLIC))
            goto no_reflect;

        /* Reflect all instance fields or all static fields, but not both */
        if (reflect_only_static_fields != ((modifiers & ACC_STATIC) != 0))
            goto no_reflect;

        /* Determine the unqualified name of the field */
        field_name_jstr = (*jEnv)->CallObjectMethod(jEnv, java_field, jlrField_getName);
        if (!field_name_jstr) {
            jsj_UnexpectedJavaError(cx, jEnv,
                                    "Can't obtain a Field's name"
                                    "java.lang.reflect.Field.getName()");
            return JS_FALSE;
        }
        
        /* Add a JavaFieldSpec object to the JavaClassDescriptor */
        ok = add_java_field_to_class_descriptor(cx, jEnv, class_descriptor, field_name_jstr,
                                                java_field, modifiers);
        if (!ok)
            return JS_FALSE;

        (*jEnv)->DeleteLocalRef(jEnv, field_name_jstr);
        field_name_jstr = NULL;

no_reflect:
        (*jEnv)->DeleteLocalRef(jEnv, java_field);
        java_field = NULL;
    }

    (*jEnv)->DeleteLocalRef(jEnv, joFieldArray);

    /* Success */
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ReflectJavaMethods ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
JSBool  reflect_only_static_methods 
)

Definition at line 515 of file jsj_method.c.

{
    jarray joMethodArray, joConstructorArray;
    jsize num_methods, num_constructors;
    int i;
    jclass java_class;
    JSBool ok, reflect_only_instance_methods;

    reflect_only_instance_methods = !reflect_only_static_methods;

    /* Get a java array of java.lang.reflect.Method objects, by calling
       java.lang.Class.getMethods(). */
    java_class = class_descriptor->java_class;
    joMethodArray = (*jEnv)->CallObjectMethod(jEnv, java_class, jlClass_getMethods);
    if (!joMethodArray) {
        jsj_UnexpectedJavaError(cx, jEnv,
                                "Can't determine Java object's methods "
                                "using java.lang.Class.getMethods()");
        return JS_FALSE;
    }

    /* Iterate over the class methods */
    num_methods = (*jEnv)->GetArrayLength(jEnv, joMethodArray);
    for (i = 0; i < num_methods; i++) {
        jstring method_name_jstr;
        
        /* Get the i'th reflected method */
        jobject java_method = (*jEnv)->GetObjectArrayElement(jEnv, joMethodArray, i);

        /* Get the method modifiers, eg static, public, private, etc. */
        jint modifiers = (*jEnv)->CallIntMethod(jEnv, java_method, jlrMethod_getModifiers);

        /* Don't allow access to private or protected Java methods. */
        if (!(modifiers & ACC_PUBLIC))
            goto dont_reflect_method;

        /* Abstract methods can't be invoked */
        if (modifiers & ACC_ABSTRACT)
            goto dont_reflect_method;

        /* Reflect all instance methods or all static methods, but not both */
        if (reflect_only_static_methods != ((modifiers & ACC_STATIC) != 0))
            goto dont_reflect_method;
        
        /* Add a JavaMethodSpec object to the JavaClassDescriptor */
        method_name_jstr = (*jEnv)->CallObjectMethod(jEnv, java_method, jlrMethod_getName);
        ok = add_java_method_to_class_descriptor(cx, jEnv, class_descriptor, method_name_jstr, java_method,
                                                 reflect_only_static_methods, JS_FALSE);
        (*jEnv)->DeleteLocalRef(jEnv, method_name_jstr);
        if (!ok) {
            (*jEnv)->DeleteLocalRef(jEnv, java_method);
            (*jEnv)->DeleteLocalRef(jEnv, joMethodArray);
            return JS_FALSE;
        }

dont_reflect_method:
        (*jEnv)->DeleteLocalRef(jEnv, java_method);
    }

    (*jEnv)->DeleteLocalRef(jEnv, joMethodArray);
    if (reflect_only_instance_methods)
        return JS_TRUE;
        
    joConstructorArray = (*jEnv)->CallObjectMethod(jEnv, java_class, jlClass_getConstructors);
    if (!joConstructorArray) {
        jsj_UnexpectedJavaError(cx, jEnv, "internal error: "
                                "Can't determine Java class's constructors "
                                "using java.lang.Class.getConstructors()");
        return JS_FALSE;
    }

    /* Iterate over the class constructors */
    num_constructors = (*jEnv)->GetArrayLength(jEnv, joConstructorArray);
    for (i = 0; i < num_constructors; i++) {
        /* Get the i'th reflected constructor */
        jobject java_constructor =
            (*jEnv)->GetObjectArrayElement(jEnv, joConstructorArray, i);

        /* Get the method modifiers, eg public, private, etc. */
        jint modifiers = (*jEnv)->CallIntMethod(jEnv, java_constructor,
                                                jlrConstructor_getModifiers);

        /* Don't allow access to private or protected Java methods. */
        if (!(modifiers & ACC_PUBLIC))
            goto dont_reflect_constructor;
        
        /* Add a JavaMethodSpec object to the JavaClassDescriptor */
        ok = add_java_method_to_class_descriptor(cx, jEnv, class_descriptor, NULL,
                                                 java_constructor,
                                                 JS_FALSE, JS_TRUE);
        if (!ok) {
            (*jEnv)->DeleteLocalRef(jEnv, joConstructorArray);
            (*jEnv)->DeleteLocalRef(jEnv, java_constructor);
            return JS_FALSE;
        }

dont_reflect_constructor:
        (*jEnv)->DeleteLocalRef(jEnv, java_constructor);
    }

    (*jEnv)->DeleteLocalRef(jEnv, joConstructorArray);
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ReflectJavaMethodsAndFields ( JSContext cx,
JavaClassDescriptor class_descriptor,
JSBool  reflect_only_statics 
)
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:

void jsj_ReportJavaError ( JSContext cx,
JNIEnv env,
const char *  format,
  ... 
)

Definition at line 360 of file jsj_utils.c.

{
    va_list ap;

    va_start(ap, format);
    vreport_java_error(cx, env, format, ap);
    va_end(ap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_ReportUncaughtJSException ( JSContext cx,
JNIEnv jEnv,
jthrowable  java_exception 
)

Definition at line 621 of file jsj_JSObject.c.

{
    JSBool success;
    JSErrorReport report;
    const char *linebuf, *filename, *message, *tokenptr;
    jint lineno, token_index;
    jstring linebuf_jstr, filename_jstr, message_jstr;

    /* Initialize everything to NULL */
    memset(&report, 0, sizeof(JSErrorReport));
    success = JS_FALSE;
    filename_jstr = linebuf_jstr = message_jstr = NULL;
    filename = message = linebuf = tokenptr = NULL;

    lineno = (*jEnv)->GetIntField(jEnv, java_exception, njJSException_lineno);
    report.lineno = lineno;

    filename_jstr = (*jEnv)->GetObjectField(jEnv, java_exception, njJSException_filename);
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "Unable to access filename field of a JSException");
        goto done;
    }
    if (filename_jstr)
        filename = (*jEnv)->GetStringUTFChars(jEnv, filename_jstr, 0);
    report.filename = filename;

    linebuf_jstr = (*jEnv)->GetObjectField(jEnv, java_exception, njJSException_source);
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "Unable to access source field of a JSException");
        goto done;
    }
    if (linebuf_jstr)
        linebuf = (*jEnv)->GetStringUTFChars(jEnv, linebuf_jstr, 0);
    report.linebuf = linebuf;

    token_index = (*jEnv)->GetIntField(jEnv, java_exception, njJSException_lineno);
    report.tokenptr = linebuf + token_index;

    message_jstr = (*jEnv)->CallObjectMethod(jEnv, java_exception, jlThrowable_getMessage);
    if ((*jEnv)->ExceptionOccurred(jEnv)) {
        jsj_UnexpectedJavaError(cx, jEnv, "Unable to access message of a JSException");
        goto done;
    }
    if (message_jstr)
        message = (*jEnv)->GetStringUTFChars(jEnv, message_jstr, 0);

    js_ReportErrorAgain(cx, message, &report);

    success = JS_TRUE;

done:

    if (filename_jstr && filename)
        (*jEnv)->ReleaseStringUTFChars(jEnv, filename_jstr, filename);
    if (linebuf_jstr && linebuf)
        (*jEnv)->ReleaseStringUTFChars(jEnv, linebuf_jstr, linebuf);
    if (message_jstr && message)
        (*jEnv)->ReleaseStringUTFChars(jEnv, message_jstr, message);
    return success;
}

Here is the call graph for this function:

JavaMemberDescriptor* jsj_ResolveExplicitMethod ( JSContext cx,
JNIEnv jEnv,
JavaClassDescriptor class_descriptor,
jsid  method_name_id,
JSBool  is_static 
)

Definition at line 656 of file jsj_method.c.

{
    JavaMethodSpec *method;
    JavaMemberDescriptor *member_descriptor;
    JavaMethodSignature *ms;
    JSString *simple_name_jsstr;
    JSFunction *fun;
    JSBool is_constructor;
    int left_paren;
    const char *sig_cstr, *method_name;
    char *arg_start;
    jsid id;
    jsval method_name_jsval;
      
    /*
     * Get the simple name of the explicit method, i.e. get "cos" from
     * "cos(double)", and use it to create a new JS string.
     */
    JS_IdToValue(cx, method_name_id, &method_name_jsval);
    method_name = JS_GetStringBytes(JSVAL_TO_STRING(method_name_jsval));
    arg_start = strchr(method_name, '('); /* Skip until '(' */
    /* If no left-paren, then this is not a case of explicit method resolution */
    if (!arg_start)
       return NULL;
    /* Left-paren must be first character for constructors */
    is_constructor = (is_static && (arg_start == method_name));
        
    left_paren = arg_start - method_name;
    simple_name_jsstr = JS_NewStringCopyN(cx, method_name, left_paren);
    if (!simple_name_jsstr)
       return NULL;

    /* Find all the methods in the same class with the same simple name */
    JS_ValueToId(cx, STRING_TO_JSVAL(simple_name_jsstr), &id);
    if (is_constructor)
        member_descriptor = jsj_LookupJavaClassConstructors(cx, jEnv, class_descriptor);
    else if (is_static)
       member_descriptor = jsj_LookupJavaStaticMemberDescriptorById(cx, jEnv, class_descriptor, id);
    else
       member_descriptor = jsj_LookupJavaMemberDescriptorById(cx, jEnv, class_descriptor, id);
    if (!member_descriptor) /* No member with matching simple name ? */
       return NULL;
    
    /*
     * Do a UTF8 comparison of method signatures with all methods of the same name,
     * so as to discover a method which exactly matches the specified argument types.
     */
    if (!strlen(arg_start + 1))
       return NULL;
    arg_start = JS_strdup(cx, arg_start + 1);
    if (!arg_start)
       return NULL;
    arg_start[strlen(arg_start) - 1] = '\0';     /* Get rid of ')' */
    sig_cstr = NULL; /* Quiet gcc warning about uninitialized variable */
    for (method = member_descriptor->methods; method; method = method->next) {
       ms = &method->signature;
       sig_cstr = convert_java_method_arg_signatures_to_hr_string(cx, ms->arg_signatures,
                                                           ms->num_args, JS_FALSE);
       if (!sig_cstr)
           return NULL;

       if (!strcmp(sig_cstr, arg_start))
           break;
       JS_free(cx, (void*)sig_cstr);
    }
    JS_free(cx, arg_start);
    if (!method)
       return NULL;
    JS_free(cx, (void*)sig_cstr);
    
    /* Don't bother doing anything if the method isn't overloaded */
    if (!member_descriptor->methods->next)
       return member_descriptor;

    /*
     * To speed up performance for future accesses, create a new member descriptor
     * with a name equal to the explicit method name, i.e. "cos(double)".
     */
    member_descriptor = JS_malloc(cx, sizeof(JavaMemberDescriptor));
    if (!member_descriptor)
        return NULL;
    memset(member_descriptor, 0, sizeof(JavaMemberDescriptor));

    member_descriptor->id = method_name_id;
    member_descriptor->name =
        JS_strdup(cx, is_constructor ? "<init>" : JS_GetStringBytes(simple_name_jsstr));
    if (!member_descriptor->name) {
        JS_free(cx, member_descriptor);
        return NULL;
    }

    member_descriptor->methods = copy_java_method_descriptor(cx, method);
    if (!member_descriptor->methods) {
       JS_free(cx, (void*)member_descriptor->name);
        JS_free(cx, member_descriptor);
        return NULL;
    }
 
    fun = JS_NewFunction(cx, jsj_JavaInstanceMethodWrapper, 0,
                      JSFUN_BOUND_METHOD, NULL, method_name);
    member_descriptor->invoke_func_obj = JS_GetFunctionObject(fun);
    JS_AddNamedRoot(cx, &member_descriptor->invoke_func_obj,
                    "&member_descriptor->invoke_func_obj");

    /* THREADSAFETY */
    /* Add the new aliased member to the list of all members for the class */
    if (is_static) {
       member_descriptor->next = class_descriptor->static_members;
       class_descriptor->static_members = member_descriptor;
    } else {
       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:

JSBool jsj_SetJavaArrayElement ( JSContext cx,
JNIEnv jEnv,
jarray  java_array,
jsize  index,
JavaSignature *  array_component_signature,
jsval  js_val 
)

Definition at line 130 of file jsj_array.c.

{
    int dummy_cost;
    jvalue java_value;
    JavaSignatureChar component_type;
    JSBool is_local_ref;

    if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, js_val, array_component_signature,
                                       &dummy_cost, &java_value, &is_local_ref))
        return JS_FALSE;

#define SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Type,member)                   \
    (*jEnv)->Set##Type##ArrayRegion(jEnv, java_array, index, 1,              \
                                    &java_value.member);                     \
    if ((*jEnv)->ExceptionOccurred(jEnv)) {                                  \
        jsj_ReportJavaError(cx, jEnv, "Error assigning to element of "       \
                                      "Java primitive array");               \
        return JS_FALSE;                                                     \
    }

    component_type = array_component_signature->type;
    switch(component_type) {
    case JAVA_SIGNATURE_BYTE:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Byte,b);
        break;

    case JAVA_SIGNATURE_CHAR:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Char,c);
        break;

    case JAVA_SIGNATURE_SHORT:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Short,s);
        break;

    case JAVA_SIGNATURE_INT:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Int,i);
        break;

    case JAVA_SIGNATURE_BOOLEAN:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Boolean,z);
        break;

    case JAVA_SIGNATURE_LONG:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Long,j);
        break;
  
    case JAVA_SIGNATURE_FLOAT:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Float,f);
        break;

    case JAVA_SIGNATURE_DOUBLE:
        SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Double,d);
        break;

    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(component_type));
        (*jEnv)->SetObjectArrayElement(jEnv, java_array, index, java_value.l);
        if (is_local_ref)                                                           \
            (*jEnv)->DeleteLocalRef(jEnv, java_value.l);
        if ((*jEnv)->ExceptionOccurred(jEnv)) {
            jsj_ReportJavaError(cx, jEnv, "Error assigning to Java object array");
            return JS_FALSE;
        }
        break;

#undef SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY
    case JAVA_SIGNATURE_UNKNOWN:
    case JAVA_SIGNATURE_VOID:
        JS_ASSERT(0);        /* Unknown java type signature */
        return JS_FALSE;
    }

    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool jsj_SetJavaFieldValue ( JSContext cx,
JNIEnv jEnv,
JavaFieldSpec field_spec,
jobject  java_obj,
jsval  js_val 
)

Definition at line 339 of file jsj_field.c.

{
    JSBool is_static_field, is_local_ref;
    int dummy_cost;
    jvalue java_value;
    JavaSignature *signature;
    JavaSignatureChar field_type;
    jfieldID fieldID = field_spec->fieldID;

    is_static_field = field_spec->modifiers & ACC_STATIC;

#define SET_JAVA_FIELD(Type,member)                                          \
    JS_BEGIN_MACRO                                                           \
    if (is_static_field) {                                                   \
        (*jEnv)->SetStatic##Type##Field(jEnv, java_obj, fieldID,             \
                                        java_value.member);                  \
    } else {                                                                 \
        (*jEnv)->Set##Type##Field(jEnv, java_obj, fieldID,java_value.member);\
    }                                                                        \
    if ((*jEnv)->ExceptionOccurred(jEnv)) {                                  \
        jsj_UnexpectedJavaError(cx, jEnv, "Error assigning to Java field");      \
        return JS_FALSE;                                                     \
    }                                                                        \
    JS_END_MACRO

    signature = field_spec->signature;
    if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, js_val, signature, &dummy_cost,
                                       &java_value, &is_local_ref))
        return JS_FALSE;

    field_type = signature->type;
    switch(field_type) {
    case JAVA_SIGNATURE_BYTE:
        SET_JAVA_FIELD(Byte,b);
        break;

    case JAVA_SIGNATURE_CHAR:
        SET_JAVA_FIELD(Char,c);
        break;

    case JAVA_SIGNATURE_SHORT:
        SET_JAVA_FIELD(Short,s);
        break;

    case JAVA_SIGNATURE_INT:
        SET_JAVA_FIELD(Int,i);
        break;

    case JAVA_SIGNATURE_BOOLEAN:
        SET_JAVA_FIELD(Boolean,z);
        break;

    case JAVA_SIGNATURE_LONG:
        SET_JAVA_FIELD(Long,j);
        break;
  
    case JAVA_SIGNATURE_FLOAT:
        SET_JAVA_FIELD(Float,f);
        break;

    case JAVA_SIGNATURE_DOUBLE:
        SET_JAVA_FIELD(Double,d);
        break;
        
    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(field_type));
        SET_JAVA_FIELD(Object,l);
        if (is_local_ref)
            (*jEnv)->DeleteLocalRef(jEnv, java_value.l);
        break;

    case JAVA_SIGNATURE_UNKNOWN:
    case JAVA_SIGNATURE_VOID:
        JS_ASSERT(0);        /* Unknown java type signature */
        return JS_FALSE;
    }

#undef SET_JAVA_FIELD
    
    return JS_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void jsj_UnexpectedJavaError ( JSContext cx,
JNIEnv env,
const char *  format,
  ... 
)

Definition at line 374 of file jsj_utils.c.

{
    va_list ap;
    const char *format2;

    va_start(ap, format);
    format2 = JS_smprintf("internal error: %s", format);
    if (format2) {
        vreport_java_error(cx, env, format2, ap);
        free((void*)format2);
    }
    va_end(ap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSObject* jsj_UnwrapJSObjectWrapper ( JNIEnv jEnv,
jobject  java_wrapper_obj 
)

Definition at line 295 of file jsj_JSObject.c.

{
    JSObjectHandle *handle;

#ifndef OJI
#if JS_BYTES_PER_LONG == 8
    handle = (JSObjectHandle*)((*jEnv)->GetLongField(jEnv, java_wrapper_obj, njJSObject_long_internal));
#else
    handle = (JSObjectHandle*)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, njJSObject_internal));
#endif
#else
    /* Unwrapping this wrapper requires knowledge of the structure of the object. This is privileged
       information that only the object implementor can know. In this case the object implementor
       is the java plugin (such as the Sun plugin class sun.plugin.javascript.navig5.JSObject. 
          Since the plugin owns this structure, we defer to it to unwrap the object. If the plugin 
          does not implement this callback, then it should be set to null. In that case we try something 
          that works with Sun's plugin assuming that it has not yet been implemented yet. This 'else' 
          case should be removed as soon as the unwrap function is supported by the Sun JPI. */

    if (JSJ_callbacks && JSJ_callbacks->unwrap_java_wrapper != NULL) {
        handle = (JSObjectHandle*)JSJ_callbacks->unwrap_java_wrapper(jEnv, java_wrapper_obj);
    }
    else {
        jclass   cid = (*jEnv)->GetObjectClass(jEnv, java_wrapper_obj);
#if JS_BYTES_PER_LONG == 8
        jfieldID fid = (*jEnv)->GetFieldID(jEnv, cid, "nativeJSObject", "J");
        handle = (JSObjectHandle*)((*jEnv)->GetLongField(jEnv, java_wrapper_obj, fid));
#else
        jfieldID fid = (*jEnv)->GetFieldID(jEnv, cid, "nativeJSObject", "I");
        handle = (JSObjectHandle*)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, fid));
#endif
    }
#endif
    
       /* JNI returns a NULL handle for a Java 'null' */
    if (!handle)
        return NULL;

    return handle->js_obj;
       
}

Here is the caller graph for this function:

JSObject* jsj_WrapJavaObject ( JSContext cx,
JNIEnv jEnv,
jobject  java_obj,
jclass  java_class 
)

Definition at line 138 of file jsj_JavaObject.c.

{
    JSJHashNumber hash_code;
    JSClass *js_class;
    JSObject *js_wrapper_obj;
    JavaObjectWrapper *java_wrapper;
    JavaClassDescriptor *class_descriptor;
    JSJHashEntry *he, **hep;

#ifdef JSJ_THREADSAFE
    int mutation_count;
#endif

    js_wrapper_obj = NULL;

    hash_code = jsj_HashJavaObject((void*)java_obj, (void*)jEnv);

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(java_obj_reflections_monitor);
#endif

    if (!installed_GC_callback) {
        /*
         * Hook into GC callback mechanism, so we can defer deleting global
         * references until it's safe.
         */
        old_GC_callback =  JS_SetGCCallback(cx, jsj_GC_callback);
        installed_GC_callback = JS_TRUE;
    }

    hep = JSJ_HashTableRawLookup(java_obj_reflections,
                                 hash_code, java_obj, (void*)jEnv);
    he = *hep;

#ifdef JSJ_THREADSAFE
    /* Track mutations to hash table */
    mutation_count = java_obj_reflections_mutation_count;

    /* We must temporarily release this monitor so as to avoid
       deadlocks with the JS GC.  See Bugsplat #354852 */
    PR_ExitMonitor(java_obj_reflections_monitor);
#endif

    if (he) {
        js_wrapper_obj = (JSObject *)he->value;
        if (js_wrapper_obj)
            return js_wrapper_obj;
    }

    /* No existing reflection found.  Construct a new one */
    class_descriptor = jsj_GetJavaClassDescriptor(cx, jEnv, java_class);
    if (!class_descriptor)
        return NULL;
    if (class_descriptor->type == JAVA_SIGNATURE_ARRAY) {
        js_class = &JavaArray_class;
    } else {
        JS_ASSERT(IS_OBJECT_TYPE(class_descriptor->type));
        js_class = &JavaObject_class;
    }

    /* Create new JS object to reflect Java object */
    js_wrapper_obj = JS_NewObject(cx, js_class, NULL, NULL);
    if (!js_wrapper_obj)
        return NULL;

    /* Create private, native portion of JavaObject */
    java_wrapper =
        (JavaObjectWrapper *)JS_malloc(cx, sizeof(JavaObjectWrapper));
    if (!java_wrapper) {
        jsj_ReleaseJavaClassDescriptor(cx, jEnv, class_descriptor);
        return NULL;
    }
    JS_SetPrivate(cx, js_wrapper_obj, java_wrapper);
    java_wrapper->class_descriptor = class_descriptor;
    java_wrapper->java_obj = NULL;

#ifdef JSJ_THREADSAFE
    PR_EnterMonitor(java_obj_reflections_monitor);

    /* We may need to do the hash table lookup again, since some other
       thread may have updated it while the lock wasn't being held. */
    if (mutation_count != java_obj_reflections_mutation_count) {
        hep = JSJ_HashTableRawLookup(java_obj_reflections,
                                     hash_code, java_obj, (void*)jEnv);
        he = *hep;
        if (he) {
            js_wrapper_obj = (JSObject *)he->value;
            if (js_wrapper_obj) {
                PR_ExitMonitor(java_obj_reflections_monitor);
                return js_wrapper_obj;
            }
        }
    }

    java_obj_reflections_mutation_count++;

#endif

    java_obj = (*jEnv)->NewGlobalRef(jEnv, java_obj);
    java_wrapper->java_obj = java_obj;
    if (!java_obj)
        goto out_of_memory;

    /* cache the hash code for all time. */
    java_wrapper->u.hash_code = hash_code;

    /* Add the JavaObject to the hash table */
    he = JSJ_HashTableRawAdd(java_obj_reflections, hep, hash_code,
                             java_obj, js_wrapper_obj, (void*)jEnv);
#ifdef JSJ_THREADSAFE
    PR_ExitMonitor(java_obj_reflections_monitor);
#endif

    if (!he) {
        (*jEnv)->DeleteGlobalRef(jEnv, java_obj);
        goto out_of_memory;
    }

    return js_wrapper_obj;

out_of_memory:
    /* No need to free js_wrapper_obj, as it will be finalized by GC. */
    JS_ReportOutOfMemory(cx);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

jobject jsj_WrapJSObject ( JSContext cx,
JNIEnv jEnv,
JSObject js_obj 
)

OJI

Definition at line 256 of file jsj_JSObject.c.

{
    jobject java_wrapper_obj;
    JSObjectHandle *handle;

    /* Create a tiny stub object to act as the GC root that points to the
       JSObject from its netscape.javascript.JSObject counterpart. */
    handle = (JSObjectHandle*)JS_malloc(cx, sizeof(JSObjectHandle));
    if (!handle)
        return NULL;
    handle->js_obj = js_obj;
    handle->rt = JS_GetRuntime(cx);

    /* Create a new Java object that wraps the JavaScript object by storing its
       address in a private integer field. */
#ifndef OJI
    java_wrapper_obj =
        (*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (lcjsobject)handle);
#else
    if (JSJ_callbacks && JSJ_callbacks->get_java_wrapper != NULL) {
        java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (lcjsobject)handle);
    } else  {
        java_wrapper_obj = NULL;
    }
#endif 
    if (!java_wrapper_obj) {
        jsj_UnexpectedJavaError(cx, jEnv, "Couldn't create new instance of "
                                          "netscape.javascript.JSObject");
        goto done;
    }
 
    JS_AddNamedRoot(cx, &handle->js_obj, "&handle->js_obj");

done:
        
    return java_wrapper_obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1009 of file jsj_JavaObject.c.

{
    JS_free(cx, map);
}

Here is the call graph for this function:

Definition at line 1015 of file jsj_JavaObject.c.

Definition at line 993 of file jsj_JavaObject.c.

{
    JSObjectMap * map;

    map = (JSObjectMap *) JS_malloc(cx, sizeof(JSObjectMap));
    if (map) {
        map->nrefs = nrefs;
        map->ops = ops;
        map->nslots = JSJ_SLOT_COUNT;
        map->freeslot = JSJ_SLOT_COUNT;
    }
    return map;
}

Here is the call graph for this function:

Definition at line 1025 of file jsj_JavaObject.c.


Variable Documentation

Definition at line 108 of file jsj.c.

Definition at line 447 of file jsj_JavaArray.c.

Definition at line 577 of file jsj_JavaClass.c.

Definition at line 160 of file jsj_JavaMember.c.

Definition at line 1071 of file jsj_JavaObject.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 131 of file jsj.c.

Definition at line 129 of file jsj.c.

Definition at line 130 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 145 of file jsj.c.

Definition at line 514 of file jsj.c.

Definition at line 58 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.