nsresult rv; nsCOMPtr<nsILocalFile> directory; if (aMozBinDirectory) {  void* xpcomObj = GetMatchingXPCOMObject(env, aMozBinDirectory); NS_ASSERTION(xpcomObj != nsnull, "Failed to get matching XPCOM object"); if (xpcomObj == nsnull) { ThrowXPCOMException(env, 0); return; }  NS_ASSERTION(!IsXPTCStub(xpcomObj), "Expected JavaXPCOMInstance, but got nsJavaXPTCStub"); directory = do_QueryInterface(((JavaXPCOMInstance*) xpcomObj)->GetInstance()); }   nsIDirectoryServiceProvider* provider = nsnull;   rv = NS_InitEmbedding(directory, provider); if (NS_FAILED(rv)) ThrowXPCOMException(env, rv);  gEmbeddingInitialized = PR_TRUE;
FreeJavaGlobals(env); ThrowXPCOMException(env, NS_FAILED(rv) ? rv : NS_ERROR_FAILURE);
GECKO_NATIVE(initEmbedding) (JNIEnv* env, jclass, jobject aMozBinDirectory,                             jobject aAppFileLocProvider){  if (!InitializeJavaGlobals(env)) {    FreeJavaGlobals(env);    ThrowXPCOMException(env, 0);    return;  }  nsresult rv;  nsCOMPtr<nsILocalFile> directory;  if (aMozBinDirectory)  {    // Find corresponding XPCOM object    void* xpcomObj = GetMatchingXPCOMObject(env, aMozBinDirectory);    NS_ASSERTION(xpcomObj != nsnull, "Failed to get matching XPCOM object");    if (xpcomObj == nsnull) {      ThrowXPCOMException(env, 0);      return;    }    NS_ASSERTION(!IsXPTCStub(xpcomObj), "Expected JavaXPCOMInstance, but got nsJavaXPTCStub");    directory = do_QueryInterface(((JavaXPCOMInstance*) xpcomObj)->GetInstance());  }  /* XXX How do we handle AppFileLocProvider, if we can't create any of the   * Java<->XPCOM mappings before NS_InitEmbedding has been called?   */  nsIDirectoryServiceProvider* provider = nsnull;/*  if (aAppFileLocProvider)  {    JavaXPCOMInstance* inst = (JavaXPCOMInstance*) aMozBinDirectory;    provider = (nsIDirectoryServiceProvider*) inst->GetInstance();  } */  rv = NS_InitEmbedding(directory, provider);  if (NS_FAILED(rv))    ThrowXPCOMException(env, rv);  gEmbeddingInitialized = PR_TRUE;}