if (JSJ_callbacks->exit_js)
if (JSJ_callbacks && JSJ_callbacks->exit_js)
jsj_enter_js(JNIEnv *jEnv, void* applet_obj, jobject java_wrapper_obj,             JSContext **cxp, JSObject **js_objp, JSErrorReporter *old_error_reporterp,             void **pNSIPrincipaArray, int numPrincipals, void *pNSISecurityContext){    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->enter_js_from_java) {#ifdef OJI        if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg, pNSIPrincipaArray, numPrincipals, pNSISecurityContext))#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->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;        }        jsj_env->cx = cx;    }    *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->exit_js)        JSJ_callbacks->exit_js(jEnv);entry_failure:    if (err_msg) {        if (cx)            JS_ReportError(cx, err_msg);        else            jsj_LogError(err_msg);        free(err_msg);    }    return NULL;}