/* * Initialize the provided JSContext by setting up the JS classes necessary for * reflection and by defining JavaPackage objects for the default Java packages * as properties of global_obj. If java_vm is NULL, a new Java VM is * created, using the provided classpath in addition to any default classpath. * The classpath argument is ignored, however, if java_vm is non-NULL. */ JSBool JSJ_SimpleInit(JSContext *cx, JSObject *global_obj, SystemJavaVM *java_vm, const char *classpath) { JNIEnv *jEnv; JSJ_Init(&jsj_default_callbacks); JS_ASSERT(!the_jsj_vm); the_jsj_vm = JSJ_ConnectToJavaVM(java_vm, (void*)classpath); if (!the_jsj_vm) return JS_FALSE; if (!JSJ_InitJSContext(cx, global_obj, NULL)) goto error; the_cx = cx; the_global_js_obj = global_obj; the_jsj_thread = JSJ_AttachCurrentThreadToJava(the_jsj_vm, "main thread", &jEnv); if (!the_jsj_thread) goto error; JSJ_SetDefaultJSContextForJavaThread(cx, the_jsj_thread); return JS_TRUE; error: JSJ_SimpleShutdown(); return JS_FALSE; }
static void sajsj_InitLocked() { JRIEnv *env; /* if jsj has already been initialized, we don't do this * standalone jsj setup, and none of the stuff in this * file gets used */ if (!JSJ_Init(&sajsjCallbacks)) return; jsjiTask = JS_Init(8L * 1024L * 1024L); jsmon = PR_NewMonitor(); globalContext = JS_NewContext(jsjiTask, 8192); PR_ASSERT(globalContext); globalObject = NULL; JS_AddRoot(globalContext, &globalObject); globalObject = JS_NewObject(globalContext, &sajsj_global_class, NULL, NULL); if (!globalObject) { PR_ASSERT(globalObject); goto trash_cx; } if (!JS_InitStandardClasses(globalContext, globalObject)) goto trash_cx; if (!JSJ_InitContext(globalContext, globalObject)) goto trash_cx; env = JRI_GetCurrentEnv(); PR_ASSERT(env); return; trash_cx: JS_DestroyContext(globalContext); globalContext = NULL; /* FIXME error codes? */ return; }
void JVM_InitLCGlue(void) { JSJ_Init(&jsj_callbacks); }