зеркало из https://github.com/mozilla/pjs.git
bug #44187: added guards to prevent crashes when Java not available. r=jband
This commit is contained in:
Родитель
7d81913b4d
Коммит
3940913be4
|
@ -684,7 +684,8 @@ JSJ_AttachCurrentThreadToJava(JSJavaVM *jsjava_vm, const char *name, JNIEnv **ja
|
||||||
|
|
||||||
/* Try to attach a Java thread to the current native thread */
|
/* Try to attach a Java thread to the current native thread */
|
||||||
java_vm = jsjava_vm->java_vm;
|
java_vm = jsjava_vm->java_vm;
|
||||||
jEnv = JSJ_callbacks->attach_current_thread(java_vm);
|
if (JSJ_callbacks && JSJ_callbacks->attach_current_thread)
|
||||||
|
jEnv = JSJ_callbacks->attach_current_thread(java_vm);
|
||||||
if (jEnv == NULL)
|
if (jEnv == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -738,7 +739,8 @@ jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp)
|
||||||
Invoke the callback to create one on-the-fly. */
|
Invoke the callback to create one on-the-fly. */
|
||||||
|
|
||||||
/* First, figure out which Java VM is calling us */
|
/* First, figure out which Java VM is calling us */
|
||||||
java_vm = JSJ_callbacks->get_java_vm(jEnv);
|
if (JSJ_callbacks && JSJ_callbacks->get_java_vm)
|
||||||
|
java_vm = JSJ_callbacks->get_java_vm(jEnv);
|
||||||
if (java_vm == NULL)
|
if (java_vm == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||||
java_wrapper_obj =
|
java_wrapper_obj =
|
||||||
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)js_obj);
|
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)js_obj);
|
||||||
#else
|
#else
|
||||||
if (JSJ_callbacks->get_java_wrapper != NULL) {
|
if (JSJ_callbacks && JSJ_callbacks->get_java_wrapper != NULL) {
|
||||||
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)handle);
|
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)handle);
|
||||||
}
|
}
|
||||||
#endif /*! OJI */
|
#endif /*! OJI */
|
||||||
|
@ -272,7 +272,7 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||||
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)handle);
|
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)handle);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
if (JSJ_callbacks->get_java_wrapper != NULL) {
|
if (JSJ_callbacks && JSJ_callbacks->get_java_wrapper != NULL) {
|
||||||
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)handle);
|
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)handle);
|
||||||
}
|
}
|
||||||
#endif /*! OJI */
|
#endif /*! OJI */
|
||||||
|
@ -309,7 +309,7 @@ jsj_UnwrapJSObjectWrapper(JNIEnv *jEnv, jobject java_wrapper_obj)
|
||||||
that works with Sun's plugin assuming that it has not yet been implemented yet. This 'else'
|
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. */
|
case should be removed as soon as the unwrap function is supported by the Sun JPI. */
|
||||||
|
|
||||||
if (JSJ_callbacks->unwrap_java_wrapper != NULL) {
|
if (JSJ_callbacks && JSJ_callbacks->unwrap_java_wrapper != NULL) {
|
||||||
handle = (JSObjectHandle*)JSJ_callbacks->unwrap_java_wrapper(jEnv, java_wrapper_obj);
|
handle = (JSObjectHandle*)JSJ_callbacks->unwrap_java_wrapper(jEnv, java_wrapper_obj);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -700,7 +700,7 @@ jsj_enter_js(JNIEnv *jEnv, void* applet_obj, jobject java_wrapper_obj,
|
||||||
err_msg = NULL;
|
err_msg = NULL;
|
||||||
|
|
||||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||||
if (JSJ_callbacks->enter_js_from_java) {
|
if (JSJ_callbacks && JSJ_callbacks->enter_js_from_java) {
|
||||||
#ifdef OJI
|
#ifdef OJI
|
||||||
if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg, pNSIPrincipaArray, numPrincipals, pNSISecurityContext))
|
if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg, pNSIPrincipaArray, numPrincipals, pNSISecurityContext))
|
||||||
#else
|
#else
|
||||||
|
@ -739,7 +739,7 @@ jsj_enter_js(JNIEnv *jEnv, void* applet_obj, jobject java_wrapper_obj,
|
||||||
/* We called spontaneously into JS from Java, rather than from JS into
|
/* We called spontaneously into JS from Java, rather than from JS into
|
||||||
Java and back into JS. Invoke a callback to obtain/create a
|
Java and back into JS. Invoke a callback to obtain/create a
|
||||||
JSContext for us to use. */
|
JSContext for us to use. */
|
||||||
if (JSJ_callbacks->map_jsj_thread_to_js_context) {
|
if (JSJ_callbacks && JSJ_callbacks->map_jsj_thread_to_js_context) {
|
||||||
#ifdef OJI
|
#ifdef OJI
|
||||||
cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
|
cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env,
|
||||||
applet_obj,
|
applet_obj,
|
||||||
|
@ -774,7 +774,7 @@ jsj_enter_js(JNIEnv *jEnv, void* applet_obj, jobject java_wrapper_obj,
|
||||||
|
|
||||||
error:
|
error:
|
||||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||||
if (JSJ_callbacks->exit_js)
|
if (JSJ_callbacks && JSJ_callbacks->exit_js)
|
||||||
JSJ_callbacks->exit_js(jEnv);
|
JSJ_callbacks->exit_js(jEnv);
|
||||||
|
|
||||||
entry_failure:
|
entry_failure:
|
||||||
|
@ -823,7 +823,7 @@ jsj_exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JSErrorReporter original_
|
||||||
throw_any_pending_js_error_as_a_java_exception(jsj_env);
|
throw_any_pending_js_error_as_a_java_exception(jsj_env);
|
||||||
|
|
||||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||||
if (JSJ_callbacks->exit_js)
|
if (JSJ_callbacks && JSJ_callbacks->exit_js)
|
||||||
JSJ_callbacks->exit_js(jEnv);
|
JSJ_callbacks->exit_js(jEnv);
|
||||||
|
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
|
@ -1212,7 +1212,7 @@ Java_netscape_javascript_JSObject_eval(JNIEnv *jEnv,
|
||||||
|
|
||||||
/* Set up security stuff */
|
/* Set up security stuff */
|
||||||
principals = NULL;
|
principals = NULL;
|
||||||
if (JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
if (JSJ_callbacks && JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
||||||
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx, NULL, 0, NULL);
|
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx, NULL, 0, NULL);
|
||||||
codebase = principals ? principals->codebase : NULL;
|
codebase = principals ? principals->codebase : NULL;
|
||||||
|
|
||||||
|
@ -1281,7 +1281,7 @@ Java_netscape_javascript_JSObject_getWindow(JNIEnv *jEnv,
|
||||||
{
|
{
|
||||||
char *err_msg;
|
char *err_msg;
|
||||||
JSContext *cx = NULL;
|
JSContext *cx = NULL;
|
||||||
JSObject *js_obj;
|
JSObject *js_obj = NULL;
|
||||||
jsval js_val;
|
jsval js_val;
|
||||||
int dummy_cost;
|
int dummy_cost;
|
||||||
JSBool dummy_bool;
|
JSBool dummy_bool;
|
||||||
|
@ -1295,7 +1295,8 @@ Java_netscape_javascript_JSObject_getWindow(JNIEnv *jEnv,
|
||||||
|
|
||||||
err_msg = NULL;
|
err_msg = NULL;
|
||||||
java_obj = NULL;
|
java_obj = NULL;
|
||||||
js_obj = JSJ_callbacks->map_java_object_to_js_object(jEnv, java_applet_obj, &err_msg);
|
if (JSJ_callbacks && JSJ_callbacks->map_java_object_to_js_object)
|
||||||
|
js_obj = JSJ_callbacks->map_java_object_to_js_object(jEnv, java_applet_obj, &err_msg);
|
||||||
if (!js_obj) {
|
if (!js_obj) {
|
||||||
if (err_msg) {
|
if (err_msg) {
|
||||||
JS_ReportError(cx, err_msg);
|
JS_ReportError(cx, err_msg);
|
||||||
|
|
|
@ -452,8 +452,8 @@ jsj_EnterJava(JSContext *cx, JNIEnv **envp)
|
||||||
err_msg = NULL;
|
err_msg = NULL;
|
||||||
|
|
||||||
jsj_env = the_java_jsj_env;
|
jsj_env = the_java_jsj_env;
|
||||||
if (jsj_env == NULL)
|
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);
|
jsj_env = JSJ_callbacks->map_js_context_to_jsj_thread(cx, &err_msg);
|
||||||
if (!jsj_env) {
|
if (!jsj_env) {
|
||||||
if (err_msg) {
|
if (err_msg) {
|
||||||
JS_ReportError(cx, err_msg);
|
JS_ReportError(cx, err_msg);
|
||||||
|
|
|
@ -453,7 +453,7 @@ nsCLiveconnect::Eval(JNIEnv *jEnv, jsobject obj, const jchar *script, jsize leng
|
||||||
|
|
||||||
/* Set up security stuff */
|
/* Set up security stuff */
|
||||||
principals = NULL;
|
principals = NULL;
|
||||||
if (JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
if (JSJ_callbacks && JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
||||||
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx, principalsArray, numPrincipals, pNSISecurityContext);
|
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx, principalsArray, numPrincipals, pNSISecurityContext);
|
||||||
codebase = principals ? (const char *)principals->codebase : NULL;
|
codebase = principals ? (const char *)principals->codebase : NULL;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче