Bug 775588 - Do not define a special directory if it doesn't exist. r=khuey
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Wed, 22 Aug 2012 16:58:09 -0400
changeset 105105 a9fefd087abca7b6685beb8796e13f1935708f07
parent 105104 1a822acf8faa09193f5544d74f9feb4a0ddde483
child 105106 dba7f413d26b56cf6d0060f508c0a4556c10a24c
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerskhuey
bugs775588
milestone17.0a1
Bug 775588 - Do not define a special directory if it doesn't exist. r=khuey
dom/system/OSFileConstants.cpp
--- a/dom/system/OSFileConstants.cpp
+++ b/dom/system/OSFileConstants.cpp
@@ -69,26 +69,34 @@ typedef struct {
  * System directories.
  */
 Paths* gPaths = NULL;
 
 }
 
 /**
  * Return the path to one of the special directories.
+ *
+ * @param aKey The key to the special directory (e.g. "TmpD", "ProfD", ...)
+ * @param aOutPath The path to the special directory. In case of error,
+ * the string is set to void.
  */
 nsresult GetPathToSpecialDir(const char *aKey, nsString& aOutPath)
 {
   nsCOMPtr<nsIFile> file;
   nsresult rv = NS_GetSpecialDirectory(aKey, getter_AddRefs(file));
   if (NS_FAILED(rv) || !file) {
     return rv;
   }
 
-  return file->GetPath(aOutPath);
+  rv = file->GetPath(aOutPath);
+  if (NS_FAILED(rv)) {
+    aOutPath.SetIsVoid(true);
+  }
+  return rv;
 }
 
 /**
  * Perform the part of initialization that can only be
  * executed on the main thread.
  */
 nsresult InitOSFileConstants()
 {
@@ -114,25 +122,21 @@ nsresult InitOSFileConstants()
     return rv;
   }
 
   rv = libDir->GetPath(paths->libDir);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
-  rv = GetPathToSpecialDir(NS_OS_TEMP_DIR, paths->tmpDir);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
+  // For other directories, ignore errors (they may be undefined on
+  // some platforms or in non-Firefox embeddings of Gecko).
 
-  rv = GetPathToSpecialDir(NS_APP_USER_PROFILE_50_DIR, paths->profileDir);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
+  GetPathToSpecialDir(NS_OS_TEMP_DIR, paths->tmpDir);
+  GetPathToSpecialDir(NS_APP_USER_PROFILE_50_DIR, paths->profileDir);
 
   gPaths = paths.forget();
   return NS_OK;
 }
 
 /**
  * Perform the cleaning up that can only be executed on the main thread.
  */
@@ -522,20 +526,25 @@ JSObject *GetOrCreateObjectProperty(JSCo
       JSMSG_UNEXPECTED_TYPE, aProperty, "not an object");
     return NULL;
   }
   return JS_DefineObject(cx, aObject, aProperty, NULL, NULL, JSPROP_ENUMERATE);
 }
 
 /**
  * Set a property of an object from a nsString.
+ *
+ * If the nsString is void (i.e. IsVoid is true), do nothing.
  */
 bool SetStringProperty(JSContext *cx, JSObject *aObject, const char *aProperty,
                        const nsString aValue)
 {
+  if (aValue.IsVoid()) {
+    return true;
+  }
   JSString* strValue = JS_NewUCStringCopyZ(cx, aValue.get());
   jsval valValue = STRING_TO_JSVAL(strValue);
   return JS_SetProperty(cx, aObject, aProperty, &valValue);
 }
 
 /**
  * Define OS-specific constants.
  *