nsCOMPtr<nsIScriptContext> scriptContext = (nsIScriptContext*)JS_GetContextPrivate(pJSCX);
nsCOMPtr<nsIScriptContext> scriptContext = NS_REINTERPRET_CAST(nsIScriptContext*, JS_GetContextPrivate(pJSCX));
enter_js_from_java_impl(JNIEnv *jEnv, char **errp,                        void **pNSIPrincipaArray, int numPrincipals,                         void *pNSISecurityContext,                        void *java_applet_obj){	JVMContext* context = GetJVMContext();    // Get and Save the current applet object in the vm context.    // There is not a 1:1 coorespondence between jvmcontexts and    // jscontexts, but there is a 1:1 correspondence between    // jvmcontexts and applet objects. So syncronize the two    // here and use the applet object to get the jscontext when    // needed.    if (java_applet_obj) {        context->java_applet_obj = java_applet_obj;    }    else if (context->java_applet_obj) {        java_applet_obj=context->java_applet_obj;    }    JSContext *pJSCX    = map_jsj_thread_to_js_context_impl(nsnull,java_applet_obj,jEnv,errp);    nsCOMPtr<nsIPrincipal> principal;    if (pNSISecurityContext != nsnull) {        if (pJSCX) {            nsCOMPtr<nsIScriptContext> scriptContext = (nsIScriptContext*)JS_GetContextPrivate(pJSCX);            if (scriptContext) {                nsCOMPtr<nsIScriptGlobalObject> global(dont_AddRef(scriptContext->GetGlobalObject()));                NS_ASSERTION(global, "script context has no global object");                if (global) {                    nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);                    if (globalData) {                        if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal))))                            return NS_ERROR_FAILURE;                    }                }            }        }        // What if !pJSCX?         nsCOMPtr<nsISecurityContext> jscontext = new nsCSecurityContext(principal);        nsISecurityContext* jvcontext = NS_STATIC_CAST(nsISecurityContext*,pNSISecurityContext);                                        // Should be NS_DYNAMIC_CAST, but no such define exists.                                        // So for the sake of portability, we'll live                                         // dangerously and use brute force.        if (!jscontext || !jvcontext) {            return PR_FALSE;        }        // Check that the origin + certificate are the same.        // If not, then return false.        const int buflen = 512;        char jsorigin[buflen];        char jvorigin[buflen];        *jsorigin = nsnull;        *jvorigin = nsnull;                jscontext->GetOrigin(jsorigin,buflen);        jvcontext->GetOrigin(jvorigin,buflen);        if (nsCRT::strcasecmp(jsorigin,jvorigin)) {            return PR_FALSE;        }#if 0 // ISSUE: Needs security review. We don't compare certificates.       // because currently there is no basis for making a postive comparision.      // If one or the other context is signed, the comparision will fail.        char jscertid[buflen];        char jvcertid[buflen];        *jscertid = nsnull;        *jvcertid = nsnull;        jscontext->GetCertificateID(jscertid,buflen);        jvcontext->GetCertificateID(jvcertid,buflen);        if (nsCRT::strcasecmp(jscertid,jvcertid)) {            return PR_FALSE;        }#endif    }	return PR_TRUE;}