rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile3));
rv = defaultPrefDir->Clone(getter_AddRefs(aFile));
extern "C" JSBool pref_InitInitialObjects()// Initialize default preference JavaScript buffers from// appropriate TEXT resources//----------------------------------------------------------------------------------------{  nsresult rv;  PRBool exists;  nsCOMPtr<nsIFile> aFile;  nsCOMPtr <nsIFileSpec> defaultPrefDir;          rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile));  if (NS_FAILED(rv))    return JS_FALSE;  rv = nsIFileToFileSpec(aFile, getter_AddRefs(defaultPrefDir));  if (NS_FAILED(rv))    return JS_FALSE;  static const char* specialFiles[] = {        "initpref.js"#ifdef NS_DEBUG      , "debug-developer.js"#endif#ifdef XP_MAC      , "macprefs.js"#elif defined(XP_WIN)      , "winpref.js"#elif defined(XP_UNIX)      , "unix.js"#if defined(VMS)      , "openvms.js"#endif#if defined(MOZ_WIDGET_PHOTON)	  , "photon.js"#endif		 #elif defined(XP_OS2)      , "os2pref.js"#endif  };  int k=0;  nsIFileSpec **defaultPrefFiles = (nsIFileSpec **)nsMemory::Alloc(INITIAL_MAX_DEFAULT_PREF_FILES * sizeof(nsIFileSpec *));  int maxDefaultPrefFiles = INITIAL_MAX_DEFAULT_PREF_FILES;  int numFiles = 0;  // Parse all the random files that happen to be in the components directory.  nsCOMPtr<nsIDirectoryIterator> dirIterator;  rv = nsComponentManager::CreateInstance(        (const char*)NS_DIRECTORYITERATOR_CONTRACTID,        (nsISupports*)nsnull,        (const nsID&)NS_GET_IID(nsIDirectoryIterator),        getter_AddRefs(dirIterator));  NS_ASSERTION(NS_SUCCEEDED(rv), "ERROR: Could not make a directory iterator.");  if (!dirIterator || NS_FAILED(dirIterator->Init(defaultPrefDir, PR_TRUE)))    return JS_FALSE;  // Get any old child of the components directory. Warning: aliases get resolved, so  // SetLeafName will not work here.  nsCOMPtr<nsIFile> aFile2;  rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile2));  if (NS_FAILED(rv))    	return JS_TRUE;  rv = aFile2->Append((char *)specialFiles[0]);  if (NS_FAILED(rv))    return JS_TRUE;  if (NS_FAILED(aFile2->Exists(&exists)))  {    return JS_FALSE;  }  if (exists)  {    rv = openPrefFile(aFile2, PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE);    NS_ASSERTION(NS_SUCCEEDED(rv), "initpref.js not parsed successfully");  }  // Keep this child#ifdef DEBUG_prefs  printf("Parsing default JS files.\n");#endif /* DEBUG_prefs */  for (; Exists(dirIterator); dirIterator->Next())  {    nsCOMPtr<nsIFileSpec> child;    PRBool shouldParse = PR_TRUE;    if NS_FAILED(dirIterator->GetCurrentSpec(getter_AddRefs(child)))      continue;    char* leafName;    rv = child->GetLeafName(&leafName);    if (NS_SUCCEEDED(rv))    {      // Skip non-js files      if (PL_strstr(leafName, ".js") + PL_strlen(".js") != leafName + PL_strlen(leafName))        shouldParse = PR_FALSE;      // Skip files in the special list.      if (shouldParse)      {        for (int j = 0; j < (int) (sizeof(specialFiles) / sizeof(char*)); j++)          if (PL_strcmp(leafName, specialFiles[j]) == 0)            shouldParse = PR_FALSE;      }      if (shouldParse)      {#ifdef DEBUG_prefs        printf("Adding %s to the list to be sorted\n", leafName);#endif /* DEBUG_prefs */        rv = NS_NewFileSpec(&(defaultPrefFiles[numFiles]));        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create a file spec");        if (NS_SUCCEEDED(rv) && defaultPrefFiles[numFiles]) {          rv = defaultPrefFiles[numFiles]->FromFileSpec(child);          NS_ASSERTION(NS_SUCCEEDED(rv),"failed to set the spec");          if (NS_SUCCEEDED(rv)) {            numFiles++;          }          if (numFiles == maxDefaultPrefFiles) {            // double the size of the array            maxDefaultPrefFiles *= 2;            defaultPrefFiles = (nsIFileSpec **)nsMemory::Realloc(defaultPrefFiles, maxDefaultPrefFiles * sizeof(nsIFileSpec *));          }        }      }      if (leafName) nsCRT::free((char*)leafName);    }  }#ifdef DEBUG_prefs  printf("Sort defaultPrefFiles.  we need them sorted so all-ns.js will override all.js (where override == parsed later)\n");#endif /* DEBUG_prefs */  NS_QuickSort((void *)defaultPrefFiles, numFiles,sizeof(nsIFileSpec *), inplaceSortCallback, nsnull);  for (k=0;k<numFiles;k++) {    char* currentLeafName = nsnull;    if (defaultPrefFiles[k]) {      rv = defaultPrefFiles[k]->GetLeafName(&currentLeafName);#ifdef DEBUG_prefs      printf("Parsing %s\n", currentLeafName);#endif /* DEBUG_prefs */      if (currentLeafName) nsCRT::free((char*)currentLeafName);      if (NS_SUCCEEDED(rv)) {        rv = openPrefFileSpec(defaultPrefFiles[k], PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE);        NS_ASSERTION(NS_SUCCEEDED(rv), "Config file not parsed successfully");      }    }  }  for (k=0;k<numFiles;k++) {    NS_IF_RELEASE(defaultPrefFiles[k]);  }  nsMemory::Free(defaultPrefFiles);  defaultPrefFiles = nsnull;#ifdef DEBUG_prefs  printf("Parsing platform-specific JS files.\n");#endif /* DEBUG_prefs */  nsCOMPtr<nsIFile> aFile3;  // Finally, parse any other special files (platform-specific ones).  for (k = 1; k < (int) (sizeof(specialFiles) / sizeof(char*)); k++) {    // we must get the directory every time so we can append the child    // because SetLeafName will not work here.    rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile3));    if (NS_SUCCEEDED(rv)) {      rv = aFile3->Append((char*)specialFiles[k]);      if (NS_SUCCEEDED(rv)) {#ifdef DEBUG_prefs        printf("Parsing %s\n", specialFiles[k]);#endif /* DEBUG_prefs */        if (NS_SUCCEEDED(aFile3->Exists(&exists)) && exists) {          rv = openPrefFile(aFile3, PR_FALSE, PR_FALSE, PR_FALSE, PR_FALSE);          NS_ASSERTION(NS_SUCCEEDED(rv), "<platform>.js was not parsed successfully");        }      }    }  }  JS_MaybeGC(gMochaContext);  return JS_TRUE;}