Bug 521264 - Don't use file.exists() when not necessary - browser/base part; r=dietrich
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Tue, 30 Aug 2011 22:45:31 +0100
changeset 77546 734bf8fbdb814bfeba0c29cc83a250b02eae50ad
parent 77545 72974e2ef258a29a36a866f2ab44ba2b7c02592e
child 77547 31b7b26ff4f9b1012a5b86fc9e323b1c1100190e
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs521264
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 521264 - Don't use file.exists() when not necessary - browser/base part; r=dietrich
browser/base/content/browser.js
browser/base/content/safeMode.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2208,18 +2208,22 @@ var gLastOpenDirectory = {
         if (!this._lastDir.exists())
           this._lastDir = null;
       }
       catch(e) {}
     }
     return this._lastDir;
   },
   set path(val) {
-    if (!val || !val.exists() || !val.isDirectory())
+    try {
+      if (!val || !val.isDirectory())
+        return;
+    } catch(e) {
       return;
+    }
     this._lastDir = val.clone();
 
     // Don't save the last open directory pref inside the Private Browsing mode
     if (!gPrivateBrowsingUI.privateBrowsingEnabled)
       gPrefService.setComplexValue("browser.open.lastDir", Ci.nsILocalFile,
                                    this._lastDir);
   },
   reset: function() {
@@ -2234,18 +2238,21 @@ function BrowserOpenFileWindow()
     const nsIFilePicker = Components.interfaces.nsIFilePicker;
     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
     fp.init(window, gNavigatorBundle.getString("openFile"), nsIFilePicker.modeOpen);
     fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText | nsIFilePicker.filterImages |
                      nsIFilePicker.filterXML | nsIFilePicker.filterHTML);
     fp.displayDirectory = gLastOpenDirectory.path;
 
     if (fp.show() == nsIFilePicker.returnOK) {
-      if (fp.file && fp.file.exists())
-        gLastOpenDirectory.path = fp.file.parent.QueryInterface(Ci.nsILocalFile);
+      try {
+        if (fp.file)
+          gLastOpenDirectory.path = fp.file.parent.QueryInterface(Ci.nsILocalFile);
+      } catch(e) {
+      }
       openTopWin(fp.fileURL.spec);
     }
   } catch (ex) {
   }
 }
 
 function BrowserCloseTabOrWindow() {
 #ifdef XP_MACOSX
--- a/browser/base/content/safeMode.js
+++ b/browser/base/content/safeMode.js
@@ -70,18 +70,21 @@ function restoreDefaultBookmarks() {
 }
 
 function deleteLocalstore() {
   const nsIDirectoryServiceContractID = "@mozilla.org/file/directory_service;1";
   const nsIProperties = Components.interfaces.nsIProperties;
   var directoryService =  Components.classes[nsIDirectoryServiceContractID]
                                     .getService(nsIProperties);
   var localstoreFile = directoryService.get("LStoreS", Components.interfaces.nsIFile);
-  if (localstoreFile.exists())
+  try {
     localstoreFile.remove(false);
+  } catch(e) {
+    Components.utils.reportError(e);
+  }
 }
 
 function disableAddons() {
   AddonManager.getAllAddons(function(aAddons) {
     aAddons.forEach(function(aAddon) {
       if (aAddon.type == "theme") {
         // Setting userDisabled to false on the default theme activates it,
         // disables all other themes and deactivates the applied persona, if