Back to index

lightning-sunbird  0.9+nobinonly
jsj_private.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * This Original Code has been modified by IBM Corporation. Modifications made
00039  * by IBM described herein are Copyright (c) International Business Machines
00040  * Corporation, 2000.
00041  * Modifications to Mozilla code or documentation identified per MPL Section 3.3
00042  *
00043  * Date             Modified by     Description of modification
00044  * 04/20/2000       IBM Corp.      OS/2 VisualAge build.
00045  *
00046  * ***** END LICENSE BLOCK ***** */
00047 
00048 /*
00049  * This file is part of the Java-vendor-neutral implementation of LiveConnect
00050  *
00051  * Declarations of private (internal) functions/data/types for
00052  * JavaScript <==> Java communication.
00053  *
00054  */
00055  
00056 
00057 #ifndef _JSJAVA_PVT_H
00058 #define _JSJAVA_PVT_H
00059 
00060 #include "jstypes.h"
00061 
00062 #   include "jsprf.h"
00063 #   include "jsutil.h"
00064 #   include "jshash.h"
00065 
00066 #include "jsj_hash.h"        /* Hash tables */
00067 #include "jni.h"             /* Java Native Interface */
00068 #include "jsapi.h"           /* JavaScript engine API */
00069 #include "jsjava.h"          /* LiveConnect public API */
00070 
00071 /*
00072  * OJI provides its own reentrancy-inhibiting monitors in the enter_js()
00073  * and exit_js() callbacks, so it does not need redundant thread-safety code.
00074  */
00075 #if defined(OJI) && !defined(JSJ_INHIBIT_THREADSAFE)
00076 #    define JSJ_INHIBIT_THREADSAFE
00077 #endif
00078 
00079 /* If JS is thread-safe, so is LiveConnect, unless overridden */
00080 #ifndef JSJ_THREADSAFE
00081 #    if defined(JS_THREADSAFE) && !defined(JSJ_INHIBIT_THREADSAFE)
00082 #        define JSJ_THREADSAFE
00083 #    endif
00084 #endif
00085 
00086 /*
00087  * This file doesn't include prtypes.h, which defines PR_BEGIN_EXTERN_C,
00088  * and I certainly don't want to pull it in to such a high level include
00089  * file, so I'll just do what prtypes.h does. edburns
00090  */
00091 #ifdef __cplusplus
00092 extern "C" {
00093 #endif
00094 
00095 /*************************** Type Declarations ******************************/
00096 
00097 /* Forward type declarations */
00098 typedef struct JavaMemberDescriptor JavaMemberDescriptor;
00099 typedef struct JavaMethodSpec JavaMethodSpec;
00100 typedef struct JavaClassDescriptor JavaClassDescriptor;
00101 typedef struct JavaClassDescriptor JavaSignature;
00102 typedef struct CapturedJSError CapturedJSError;
00103 
00104 /*
00105  * This enum uses a method similar to the JDK to specify
00106  * Java type signatures, but the classification of Java
00107  * object types is more fine-grained.
00108  */
00109 typedef enum {
00110     JAVA_SIGNATURE_UNKNOWN,
00111     JAVA_SIGNATURE_VOID,
00112 
00113     /* Primitive types */
00114     JAVA_SIGNATURE_BOOLEAN,
00115     JAVA_SIGNATURE_CHAR,
00116     JAVA_SIGNATURE_BYTE,
00117     JAVA_SIGNATURE_SHORT,
00118     JAVA_SIGNATURE_INT,
00119     JAVA_SIGNATURE_LONG,
00120     JAVA_SIGNATURE_FLOAT,
00121     JAVA_SIGNATURE_DOUBLE,
00122 
00123     /* Reference types */
00124     JAVA_SIGNATURE_ARRAY,              /* Any array class */
00125     JAVA_SIGNATURE_OBJECT,             /* non-array object, but not one of the
00126                                           more specific types below */
00127     JAVA_SIGNATURE_JAVA_LANG_BOOLEAN,  /* java.lang.Boolean */
00128     JAVA_SIGNATURE_JAVA_LANG_CLASS,    /* java.lang.Class */
00129     JAVA_SIGNATURE_JAVA_LANG_DOUBLE,   /* java.lang.Double */
00130     JAVA_SIGNATURE_NETSCAPE_JAVASCRIPT_JSOBJECT,  /* netscape.javascript.JSObject */
00131     JAVA_SIGNATURE_JAVA_LANG_OBJECT,   /* java.lang.Object */
00132     JAVA_SIGNATURE_JAVA_LANG_STRING,   /* java.lang.String */
00133 
00134     JAVA_SIGNATURE_LIMIT
00135 } JavaSignatureChar;
00136 
00137 #define IS_REFERENCE_TYPE(sig) ((int)(sig) >= (int)JAVA_SIGNATURE_ARRAY)
00138 #define IS_OBJECT_TYPE(sig)    ((int)(sig) >= (int)JAVA_SIGNATURE_OBJECT)
00139 #define IS_PRIMITIVE_TYPE(sig)                                               \
00140     (((int)(sig) >= (int)JAVA_SIGNATURE_BOOLEAN) && !IS_REFERENCE_TYPE(sig))                                    \
00141 
00142 /* This is used for checking whether an exception is wrapped or not. */
00143 #define JSTYPE_EMPTY -1
00144 
00145 /* The signature of a Java method consists of the signatures of all its
00146    arguments and its return type signature. */
00147 typedef struct JavaMethodSignature {
00148     jsize                   num_args;               /* Length of arg_signatures array */
00149     JavaSignature **        arg_signatures;         /* Array of argument signatures */
00150     JavaSignature *         return_val_signature;   /* Return type signature */
00151 } JavaMethodSignature;
00152 
00153 /* A descriptor for the reflection of a single Java field */
00154 typedef struct JavaFieldSpec {
00155     jfieldID                fieldID;    /* JVM opaque access handle for field */
00156     JavaSignature *         signature;  /* Java type of field */
00157     int                     modifiers;  /* Bitfield indicating field qualifiers */
00158     const char *            name;       /* UTF8; TODO - Should support Unicode field names */
00159 } JavaFieldSpec;
00160 
00161 /* A descriptor for the reflection of a single Java method.
00162    Each overloaded method has a separate corresponding JavaMethodSpec. */
00163 struct JavaMethodSpec {
00164     jmethodID               methodID;   /* JVM opaque access handle for method */
00165     JavaMethodSignature     signature;
00166     const char *            name;       /* UTF8; TODO - Should support Unicode method names */
00167     JavaMethodSpec *        next;       /* next method in chain of overloaded methods */
00168     JSBool               is_alias; /* An aliased name for a Java method ? */
00169 };
00170 
00171 /*
00172  * A descriptor for the reflection of a single member of a Java object.
00173  * This can represent one or more Java methods and/or a single field.
00174  * (When there is more than one method attached to a single JavaMemberDescriptor
00175  * they are overloaded methods sharing the same simple name.)  This same
00176  * descriptor type is used for both static or instance members.
00177  */
00178 struct JavaMemberDescriptor {
00179     const char *            name;       /* simple name of field and/or method */
00180     jsid                    id;         /* hashed name for quick JS property lookup */
00181     JavaFieldSpec *         field;      /* field with the given name, if any */
00182     JavaMethodSpec *        methods;    /* Overloaded methods which share the same name, if any */
00183     JavaMemberDescriptor *  next;       /* next descriptor in same defining class */
00184     JSObject *              invoke_func_obj; /* If non-null, JSFunction obj to invoke method */
00185 };
00186 
00187 /* Status of Class member reflection.  See JavaClassDescriptor. */
00188 typedef enum {
00189     REFLECT_NO,
00190     REFLECT_IN_PROGRESS,
00191     REFLECT_COMPLETE
00192 } ReflectStatus;
00193 
00194 /* This is the native portion of a reflected Java class */
00195 struct JavaClassDescriptor {
00196     const char *            name;       /* Name of class, e.g. "java.lang.Byte" */
00197     JavaSignatureChar       type;       /* class category: primitive type, object, array */
00198     jclass                  java_class; /* Opaque JVM handle to corresponding java.lang.Class */
00199     int                     num_instance_members;
00200     int                     num_static_members;
00201     volatile ReflectStatus  instance_members_reflected;
00202     JavaMemberDescriptor *  instance_members;
00203     volatile ReflectStatus  static_members_reflected;
00204     JavaMemberDescriptor *  static_members;
00205     JavaMemberDescriptor *  constructors;
00206     int                     modifiers;  /* Class declaration qualifiers,
00207                                            e.g. abstract, private */
00208     int                     ref_count;  /* # of references to this struct */
00209     JavaSignature *         array_component_signature; /* Only non-NULL for array classes */
00210 };
00211 
00212 typedef struct JavaObjectWrapper JavaObjectWrapper;
00213 
00214 /* This is the native portion of a reflected Java object */
00215 struct JavaObjectWrapper {
00216     jobject                 java_obj;           /* Opaque JVM ref to Java object */
00217     JavaClassDescriptor *   class_descriptor;   /* Java class info */
00218     union {
00219         JSJHashNumber       hash_code;          /* Cached hash code */
00220         JavaObjectWrapper * next;               /* Link to next wrapper after finalization */
00221     } u;
00222 };
00223 
00224 /* These are definitions of the Java class/method/field modifier bits.
00225    These really shouldn't be hard-coded here.  Rather,
00226    they should be read from java.lang.reflect.Modifier */
00227 #define ACC_PUBLIC          0x0001      /* visible to everyone */
00228 #define ACC_STATIC          0x0008      /* instance variable is static */
00229 #define ACC_FINAL           0x0010      /* no further subclassing,overriding */
00230 #define ACC_INTERFACE       0x0200      /* class is an interface */
00231 #define ACC_ABSTRACT     0x0400      /* no definition provided */
00232 
00233 /* A JSJavaVM structure must be created for each Java VM that is accessed
00234    via LiveConnect */
00235 struct JSJavaVM {
00236 /* TODO -  all LiveConnect global variables should be migrated into this
00237            structure in order to allow more than one LiveConnect-enabled
00238            Java VM to exist within the same process. */
00239     void *              init_args;              /* args to initialize VM with */
00240     SystemJavaVM *      java_vm;
00241     JNIEnv *            main_thread_env;        /* Main-thread Java environment */
00242     JSPackedBool        jsj_created_java_vm;
00243     JSPackedBool        jsj_inited_java_vm;
00244     int                 num_attached_threads;
00245     JSJavaVM *          next;                   /* next VM among all created VMs */
00246 };
00247 
00248 /* Per-thread state that encapsulates the connection to the Java VM */
00249 struct JSJavaThreadState {
00250     const char *        name;           /* Thread name, for debugging */
00251     JSJavaVM *          jsjava_vm;      /* All per-JVM state */
00252     JNIEnv *            jEnv;           /* Per-thread opaque handle to Java VM */
00253     CapturedJSError *   pending_js_errors; /* JS errors to be thrown as Java exceptions */
00254     JSContext *         cx;             /* current JS context for thread */
00255     int                     recursion_depth;/* # transitions into Java from JS */
00256     JSJavaThreadState * next;           /* next thread state among all created threads */
00257 };
00258 
00259 struct JavaToJSSavedState {
00260        JSErrorReporter error_reporter;
00261        JSJavaThreadState* java_jsj_env;
00262 };
00263 typedef struct JavaToJSSavedState JavaToJSSavedState;
00264 
00265 
00266 /* This object provides is the "anchor" by which netscape.javscript.JSObject
00267    objects hold a reference to native JSObjects. */
00268 struct JSObjectHandle {
00269     JSObject *js_obj;
00270     JSRuntime *rt;
00271 };
00272 typedef struct JSObjectHandle JSObjectHandle;
00273 
00274 
00275 /******************************** Globals ***********************************/
00276 
00277 extern JSJCallbacks *JSJ_callbacks;
00278 
00279 /* JavaScript classes that reflect Java objects */
00280 extern JSClass JavaObject_class;
00281 extern JSClass JavaArray_class;
00282 extern JSClass JavaClass_class;
00283 extern JSClass JavaMember_class;
00284 
00285 /*
00286  * Opaque JVM handles to Java classes, methods and objects required for
00287  * Java reflection.  These are computed and cached during initialization.
00288  * TODO: These should be moved inside the JSJavaVM struct
00289  */
00290 extern jclass jlObject;                        /* java.lang.Object */
00291 extern jclass jlrConstructor;                  /* java.lang.reflect.Constructor */
00292 extern jclass jlrArray;                        /* java.lang.reflect.Array */
00293 extern jclass jlThrowable;                     /* java.lang.Throwable */
00294 extern jclass jlSystem;                        /* java.lang.System */
00295 extern jclass jlClass;                         /* java.lang.Class */
00296 extern jclass jlBoolean;                       /* java.lang.Boolean */
00297 extern jclass jlDouble;                        /* java.lang.Double */
00298 extern jclass jlString;                        /* java.lang.String */
00299 extern jclass jaApplet;                        /* java.applet.Applet */
00300 extern jclass njJSObject;                      /* netscape.javascript.JSObject */
00301 extern jclass njJSException;                   /* netscape.javascript.JSException */
00302 extern jclass njJSUtil;                        /* netscape.javascript.JSUtil */
00303 
00304 extern jmethodID jlClass_getMethods;           /* java.lang.Class.getMethods() */
00305 extern jmethodID jlClass_getConstructors;      /* java.lang.Class.getConstructors() */
00306 extern jmethodID jlClass_getFields;            /* java.lang.Class.getFields() */
00307 extern jmethodID jlClass_getName;              /* java.lang.Class.getName() */
00308 extern jmethodID jlClass_getComponentType;     /* java.lang.Class.getComponentType() */
00309 extern jmethodID jlClass_getModifiers;         /* java.lang.Class.getModifiers() */
00310 extern jmethodID jlClass_isArray;              /* java.lang.Class.isArray() */
00311 
00312 extern jmethodID jlrMethod_getName;            /* java.lang.reflect.Method.getName() */
00313 extern jmethodID jlrMethod_getParameterTypes;  /* java.lang.reflect.Method.getParameterTypes() */
00314 extern jmethodID jlrMethod_getReturnType;      /* java.lang.reflect.Method.getReturnType() */
00315 extern jmethodID jlrMethod_getModifiers;       /* java.lang.reflect.Method.getModifiers() */
00316 
00317 extern jmethodID jlrConstructor_getParameterTypes; /* java.lang.reflect.Constructor.getParameterTypes() */
00318 extern jmethodID jlrConstructor_getModifiers;  /* java.lang.reflect.Constructor.getModifiers() */
00319 
00320 extern jmethodID jlrField_getName;             /* java.lang.reflect.Field.getName() */
00321 extern jmethodID jlrField_getType;             /* java.lang.reflect.Field.getType() */
00322 extern jmethodID jlrField_getModifiers;        /* java.lang.reflect.Field.getModifiers() */
00323 
00324 extern jmethodID jlrArray_newInstance;         /* java.lang.reflect.Array.newInstance() */
00325 
00326 extern jmethodID jlThrowable_getMessage;       /* java.lang.Throwable.getMessage() */
00327 extern jmethodID jlThrowable_toString;         /* java.lang.Throwable.toString() */
00328 
00329 extern jmethodID jlBoolean_Boolean;            /* java.lang.Boolean constructor */
00330 extern jmethodID jlBoolean_booleanValue;       /* java.lang.Boolean.booleanValue() */
00331 extern jmethodID jlDouble_Double;              /* java.lang.Double constructor */
00332 extern jmethodID jlDouble_doubleValue;         /* java.lang.Double.doubleValue() */
00333 
00334 extern jmethodID jlSystem_identityHashCode;    /* java.lang.System.identityHashCode() */
00335 
00336 extern jobject jlVoid_TYPE;                    /* java.lang.Void.TYPE value */
00337 
00338 extern jmethodID njJSException_JSException;    /* netscape.javascipt.JSException constructor */
00339 extern jmethodID njJSException_JSException_wrap;/*netscape.javascipt.JSException alternate constructor */
00340 extern jmethodID njJSObject_JSObject;          /* netscape.javascript.JSObject constructor */
00341 extern jmethodID njJSUtil_getStackTrace;       /* netscape.javascript.JSUtil.getStackTrace() */
00342 extern jfieldID njJSObject_internal;           /* netscape.javascript.JSObject.internal */
00343 extern jfieldID njJSObject_long_internal;      /* netscape.javascript.JSObject.long_internal */
00344 extern jfieldID njJSException_lineno;          /* netscape.javascript.JSException.lineno */
00345 extern jfieldID njJSException_tokenIndex;      /* netscape.javascript.JSException.tokenIndex */
00346 extern jfieldID njJSException_source;          /* netscape.javascript.JSException.source */
00347 extern jfieldID njJSException_filename;        /* netscape.javascript.JSException.filename */
00348 extern jfieldID njJSException_wrappedExceptionType;        /* netscape.javascript.JSException.wrappedExceptionType */
00349 extern jfieldID njJSException_wrappedException;        /* netscape.javascript.JSException.wrappedException */
00350 
00351 /* 
00352  * XXX, bug 146458, 
00353  * whether we are doing a liveconnect call from javascript to java applet 
00354  */
00355 extern JSBool jsj_JSIsCallingApplet;
00356 
00357 /**************** Java <==> JS conversions and Java types *******************/
00358 extern JSBool
00359 jsj_ComputeJavaClassSignature(JSContext *cx,
00360                               JavaSignature *signature,
00361                               jclass java_class);
00362 
00363 extern const char *
00364 jsj_ConvertJavaSignatureToString(JSContext *cx, JavaSignature *signature);
00365 extern const char *
00366 jsj_ConvertJavaSignatureToHRString(JSContext *cx,
00367                                    JavaSignature *signature);
00368 extern JavaMethodSignature *
00369 jsj_InitJavaMethodSignature(JSContext *cx, JNIEnv *jEnv, jobject method,
00370                             JavaMethodSignature *method_signature);
00371 
00372 extern const char *
00373 jsj_ConvertJavaMethodSignatureToString(JSContext *cx,
00374                                        JavaMethodSignature *method_signature);
00375 extern const char *
00376 jsj_ConvertJavaMethodSignatureToHRString(JSContext *cx,
00377                                          const char *method_name,
00378                                          JavaMethodSignature *method_signature);
00379 extern void
00380 jsj_PurgeJavaMethodSignature(JSContext *cx, JNIEnv *jEnv, JavaMethodSignature *signature);
00381 
00382 extern JSBool
00383 jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature,
00384                            int *cost, jvalue *java_value, JSBool *is_local_refp);
00385 extern JSBool
00386 jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature,
00387                             int *cost, jobject *java_value, JSBool *is_local_refp);
00388 extern jstring
00389 jsj_ConvertJSStringToJavaString(JSContext *cx, JNIEnv *jEnv, JSString *js_str);
00390 
00391 extern JSBool
00392 jsj_ConvertJavaValueToJSValue(JSContext *cx, JNIEnv *jEnv, JavaSignature *signature,
00393                               jvalue *java_value, jsval *vp);
00394 extern JSBool
00395 jsj_ConvertJavaObjectToJSValue(JSContext *cx, JNIEnv *jEnv,
00396                                jobject java_obj, jsval *vp);
00397 
00398 extern JSString *
00399 jsj_ConvertJavaStringToJSString(JSContext *cx, JNIEnv *jEnv, jstring java_str);
00400 
00401 extern JSBool
00402 jsj_ConvertJavaObjectToJSString(JSContext *cx, JNIEnv *jEnv,
00403                                 JavaClassDescriptor *class_descriptor,
00404                                 jobject java_obj, jsval *vp);
00405 extern JSBool
00406 jsj_ConvertJavaObjectToJSNumber(JSContext *cx, JNIEnv *jEnv,
00407                                 JavaClassDescriptor *class_descriptor,
00408                                 jobject java_obj, jsval *vp);
00409 extern JSBool
00410 jsj_ConvertJavaObjectToJSBoolean(JSContext *cx, JNIEnv *jEnv,
00411                                  JavaClassDescriptor *class_descriptor,
00412                                  jobject java_obj, jsval *vp);
00413 extern JSJavaThreadState *
00414 jsj_enter_js(JNIEnv *jEnv, void* java_applet_obj, jobject java_wrapper_obj,
00415          JSContext **cxp, JSObject **js_objp, JSErrorReporter *old_error_reporterp, 
00416          void **pNSIPrincipaArray, int numPrincipals, void *pNSISecurityContext);
00417 
00418 extern JSBool
00419 jsj_exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JSErrorReporter old_error_reporterp);
00420 
00421 extern JavaClassDescriptor *
00422 jsj_get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv);
00423 
00424 extern JSBool
00425 jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj);
00426 
00427 extern JSBool
00428 jsj_init_js_obj_reflections_table(void);
00429 
00430 /************************ Java package reflection **************************/
00431 extern JSBool
00432 jsj_init_JavaPackage(JSContext *, JSObject *,
00433                      JavaPackageDef *predefined_packages);
00434 
00435 /************************* Java class reflection ***************************/
00436 extern JSBool
00437 jsj_init_JavaClass(JSContext *cx, JSObject *global_obj);
00438 
00439 extern void
00440 jsj_DiscardJavaClassReflections(JNIEnv *jEnv);
00441 
00442 extern const char *
00443 jsj_GetJavaClassName(JSContext *cx, JNIEnv *jEnv, jclass java_class);
00444 
00445 extern JavaClassDescriptor *
00446 jsj_GetJavaClassDescriptor(JSContext *cx, JNIEnv *jEnv, jclass java_class);
00447 
00448 extern void
00449 jsj_ReleaseJavaClassDescriptor(JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class_descriptor);
00450 
00451 extern JSObject *
00452 jsj_define_JavaClass(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
00453                      const char *unqualified_class_name,
00454                      jclass jclazz);
00455 
00456 extern JavaMemberDescriptor *
00457 jsj_GetJavaMemberDescriptor(JSContext *cx,
00458                             JNIEnv *jEnv,
00459                             JavaClassDescriptor *class_descriptor,
00460                             jstring member_name);
00461 
00462 extern JavaMemberDescriptor *
00463 jsj_LookupJavaMemberDescriptorById(JSContext *cx, JNIEnv *jEnv,
00464                                    JavaClassDescriptor *class_descriptor,
00465                                    jsid id);
00466 
00467 extern JavaMemberDescriptor *
00468 jsj_LookupJavaStaticMemberDescriptorById(JSContext *cx, JNIEnv *jEnv,
00469                                          JavaClassDescriptor *class_descriptor,
00470                                          jsid id);
00471 
00472 extern JavaMemberDescriptor *
00473 jsj_GetJavaStaticMemberDescriptor(JSContext *cx, JNIEnv *jEnv,
00474                                   JavaClassDescriptor *class_descriptor,
00475                                   jstring member_name);
00476 
00477 extern JavaMemberDescriptor *
00478 jsj_GetJavaClassConstructors(JSContext *cx,
00479                              JavaClassDescriptor *class_descriptor);
00480 
00481 extern JavaMemberDescriptor *
00482 jsj_LookupJavaClassConstructors(JSContext *cx, JNIEnv *jEnv,
00483                                 JavaClassDescriptor *class_descriptor);
00484 
00485 extern JavaMemberDescriptor *
00486 jsj_GetClassInstanceMembers(JSContext *cx, JNIEnv *jEnv,
00487                             JavaClassDescriptor *class_descriptor);
00488 
00489 extern JavaMemberDescriptor *
00490 jsj_GetClassStaticMembers(JSContext *cx, JNIEnv *jEnv,
00491                           JavaClassDescriptor *class_descriptor);
00492 
00493 extern JSBool
00494 jsj_InitJavaClassReflectionsTable(void);
00495 
00496 /************************* Java field reflection ***************************/
00497 
00498 extern JSBool
00499 jsj_GetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
00500                       jobject java_obj, jsval *vp);
00501 extern JSBool
00502 jsj_SetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
00503                       jobject java_obj, jsval js_val);
00504 extern JSBool 
00505 jsj_ReflectJavaFields(JSContext *cx, JNIEnv *jEnv,
00506                       JavaClassDescriptor *class_descriptor,
00507                       JSBool reflect_only_static_fields);
00508 extern void
00509 jsj_DestroyFieldSpec(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field);
00510 
00511 /************************* Java method reflection ***************************/
00512 JS_EXTERN_API(JSBool)
00513 jsj_JavaInstanceMethodWrapper(JSContext *cx, JSObject *obj,
00514                               uintN argc, jsval *argv, jsval *vp);
00515 JS_EXTERN_API(JSBool)
00516 jsj_JavaStaticMethodWrapper(JSContext *cx, JSObject *obj,
00517                             uintN argc, jsval *argv, jsval *vp);
00518 JS_EXTERN_API(JSBool)
00519 jsj_JavaConstructorWrapper(JSContext *cx, JSObject *obj,
00520                            uintN argc, jsval *argv, jsval *vp);
00521 extern JSBool 
00522 jsj_ReflectJavaMethods(JSContext *cx, JNIEnv *jEnv,
00523                        JavaClassDescriptor *class_descriptor,
00524                        JSBool reflect_only_static_methods);
00525 
00526 extern JavaMemberDescriptor *
00527 jsj_ResolveExplicitMethod(JSContext *cx, JNIEnv *jEnv,
00528                        JavaClassDescriptor *class_descriptor, 
00529                        jsid method_name_id,
00530                        JSBool is_static);
00531 extern void
00532 jsj_DestroyMethodSpec(JSContext *cx, JNIEnv *jEnv, JavaMethodSpec *method_spec);
00533 
00534 /************************* Java member reflection ***************************/
00535 extern JSBool
00536 jsj_init_JavaMember(JSContext *, JSObject *);
00537 
00538 extern JSBool
00539 jsj_ReflectJavaMethodsAndFields(JSContext *cx, JavaClassDescriptor *class_descriptor,
00540                                 JSBool reflect_only_statics);
00541 
00542 extern JSObject *
00543 jsj_CreateJavaMember(JSContext *cx, jsval method_val, jsval field_val);
00544 
00545 /************************* Java object reflection **************************/
00546 extern JSBool
00547 jsj_init_JavaObject(JSContext *, JSObject *);
00548 
00549 extern JSBool
00550 jsj_InitJavaObjReflectionsTable(void);
00551 
00552 extern JSObject *
00553 jsj_WrapJavaObject(JSContext *cx, JNIEnv *jEnv, jobject java_obj, jclass java_class);
00554 
00555 extern void
00556 jsj_DiscardJavaObjReflections(JNIEnv *jEnv);
00557 
00558 extern JSBool JS_DLL_CALLBACK
00559 JavaObject_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
00560 
00561 JS_EXTERN_API(void)
00562 JavaObject_finalize(JSContext *cx, JSObject *obj);
00563 
00564 extern JSBool
00565 JavaObject_resolve(JSContext *cx, JSObject *obj, jsval id);
00566 
00567 extern JSBool
00568 JavaObject_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
00569 
00570 JS_EXTERN_API(JSBool)
00571 JavaObject_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
00572 
00573 /************************* Java array reflection ***************************/
00574 extern JSBool
00575 jsj_init_JavaArray(JSContext *cx, JSObject *global_obj);
00576 
00577 extern JSBool
00578 jsj_GetJavaArrayElement(JSContext *cx, JNIEnv *jEnv, jarray java_array,
00579                         jsize index, JavaSignature *array_component_signature,
00580                         jsval *vp);
00581    
00582 extern JSBool     
00583 jsj_SetJavaArrayElement(JSContext *cx, JNIEnv *jEnv, jarray java_array,
00584                         jsize index, JavaSignature *array_component_signature,
00585                         jsval js_val);
00586 
00587 /********************* JavaScript object reflection ************************/                        
00588 extern jobject
00589 jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj);
00590 
00591 extern JSObject *
00592 jsj_UnwrapJSObjectWrapper(JNIEnv *jEnv, jobject java_wrapper_obj);
00593 
00594 extern void
00595 jsj_ClearPendingJSErrors(JSJavaThreadState *jsj_env);
00596 
00597 extern JSBool
00598 jsj_ReportUncaughtJSException(JSContext *cx, JNIEnv *jEnv, jthrowable java_exception);
00599 
00600 /**************************** Utilities ************************************/
00601 extern void
00602 jsj_ReportJavaError(JSContext *cx, JNIEnv *env, const char *format, ...);
00603 
00604 extern void
00605 jsj_UnexpectedJavaError(JSContext *cx, JNIEnv *env, const char *format, ...);
00606 
00607 extern const char *
00608 jsj_GetJavaErrorMessage(JNIEnv *env);
00609 
00610 extern void
00611 jsj_LogError(const char *error_msg);
00612 
00613 extern const JSErrorFormatString * JS_DLL_CALLBACK
00614 jsj_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
00615 
00616 JSJHashNumber JS_DLL_CALLBACK
00617 jsj_HashJavaObject(const void *key, void* env);
00618 
00619 intN JS_DLL_CALLBACK
00620 jsj_JavaObjectComparator(const void *v1, const void *v2, void *arg);
00621 
00622 extern JSJavaThreadState *
00623 jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp);
00624 
00625 extern void
00626 jsj_MakeJNIClassname(char *jClassName);
00627 
00628 extern const char *
00629 jsj_ClassNameOfJavaObject(JSContext *cx, JNIEnv *jEnv, jobject java_object);
00630 
00631 extern jsize
00632 jsj_GetJavaArrayLength(JSContext *cx, JNIEnv *jEnv, jarray java_array);
00633 
00634 extern JSBool
00635 JavaStringToId(JSContext *cx, JNIEnv *jEnv, jstring jstr, jsid *idp);
00636 
00637 extern const char *
00638 jsj_DupJavaStringUTF(JSContext *cx, JNIEnv *jEnv, jstring jstr);
00639 
00640 extern JSJavaThreadState *
00641 jsj_EnterJava(JSContext *cx, JNIEnv **envp);
00642 
00643 extern void
00644 jsj_ExitJava(JSJavaThreadState *jsj_env);
00645 
00646 extern JSObjectMap * JS_DLL_CALLBACK
00647 jsj_wrapper_newObjectMap(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops,
00648                          JSClass *clasp, JSObject *obj);
00649 
00650 extern void JS_DLL_CALLBACK
00651 jsj_wrapper_destroyObjectMap(JSContext *cx, JSObjectMap *map);
00652 
00653 extern jsval JS_DLL_CALLBACK
00654 jsj_wrapper_getRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot);
00655 
00656 extern JSBool JS_DLL_CALLBACK
00657 jsj_wrapper_setRequiredSlot(JSContext *cx, JSObject *obj, uint32 slot, jsval v);
00658 
00659 #ifdef DEBUG
00660 #define DEBUG_LOG(args) printf args
00661 #endif
00662 
00663 #define JS_FREE_IF(cx, x)                                                   \
00664     JS_BEGIN_MACRO                                                          \
00665         if (x)                                                              \
00666             JS_free(cx, x);                                                 \
00667     JS_END_MACRO
00668 
00669 
00670 enum JSJErrNum {
00671 #define MSG_DEF(name, number, format, count) \
00672     name = number,
00673 #include "jsj.msg"
00674 #undef MSG_DEF
00675     JSJ_Err_Limit
00676 #undef MSGDEF
00677 };
00678 
00679 #ifdef __cplusplus
00680 } 
00681 /* end extern "C" */
00682 #endif
00683 
00684 #endif   /* _JSJAVA_PVT_H */