From 6763ec6040d7da6f99fa25c0f10aba912eaf75ba Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Wed, 19 Oct 2005 18:55:44 +0000 Subject: [PATCH] fixes bug 312946 "javascript:Packages.prototype crashes browser if Java plugin is not found" r=brendan --- js/src/liveconnect/jsj.c | 6 ++++-- modules/oji/src/lcglue.cpp | 14 +++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/js/src/liveconnect/jsj.c b/js/src/liveconnect/jsj.c index 6de19a027ab5..889654f35847 100644 --- a/js/src/liveconnect/jsj.c +++ b/js/src/liveconnect/jsj.c @@ -471,8 +471,10 @@ jsj_ConnectToJavaVM(JSJavaVM *jsjava_vm) JS_ASSERT(JSJ_callbacks->create_java_vm); JS_ASSERT(JSJ_callbacks->destroy_java_vm); - ok = JSJ_callbacks->create_java_vm(&jsjava_vm->java_vm, &jsjava_vm->main_thread_env, jsjava_vm->init_args); - if (!ok || jsjava_vm->java_vm == NULL) { + ok = JSJ_callbacks->create_java_vm(&jsjava_vm->java_vm, + &jsjava_vm->main_thread_env, + jsjava_vm->init_args); + if (!ok) { jsj_LogError("Failed to create Java VM\n"); return JS_FALSE; } diff --git a/modules/oji/src/lcglue.cpp b/modules/oji/src/lcglue.cpp index 1b97dae416c5..3a2d4716a532 100644 --- a/modules/oji/src/lcglue.cpp +++ b/modules/oji/src/lcglue.cpp @@ -337,12 +337,16 @@ JS_STATIC_DLL_CALLBACK(PRBool) create_java_vm_impl(SystemJavaVM* *jvm, JNIEnv* *initialEnv, void* initargs) { // const char* classpath = (const char*)initargs; - nsresult rv; - nsCOMPtr managerService = do_GetService(kJVMManagerCID, &rv); - if (NS_FAILED(rv)) return PR_FALSE; - *jvm = NS_REINTERPRET_CAST(SystemJavaVM*, managerService.get()); // unused in the browse + nsCOMPtr serv = do_GetService(kJVMManagerCID); + if (!serv) + return PR_FALSE; *initialEnv = JVM_GetJNIEnv(); - return (*jvm != NULL && *initialEnv != NULL); + if (!*initialEnv) + return PR_FALSE; + // serv will be released when this function returns, but that's OK because + // the XPCOM service manager will keep it alive. + *jvm = NS_REINTERPRET_CAST(SystemJavaVM*, serv.get()); + return PR_TRUE; } JS_STATIC_DLL_CALLBACK(PRBool)