Bug 1264717 - Part 0 - Get rid of unbraced ifs in sessionstore.js. r=margaret
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 14 Apr 2016 17:58:41 +0200
changeset 331657 9a55bb9bae73342d88a57ba0720a3711992db273
parent 331656 f2187390d83f57f18c70c643a36dc80ebfe08631
child 331658 ec69a0c8c6efc95be875ec95fae73b8db363314f
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1264717
milestone48.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 1264717 - Part 0 - Get rid of unbraced ifs in sessionstore.js. r=margaret MozReview-Commit-ID: CU36X2BD3Q
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -260,22 +260,24 @@ SessionStore.prototype = {
         this.onTabInput(window, browser);
         break;
       }
     }
   },
 
   onWindowOpen: function ss_onWindowOpen(aWindow) {
     // Return if window has already been initialized
-    if (aWindow && aWindow.__SSID && this._windows[aWindow.__SSID])
+    if (aWindow && aWindow.__SSID && this._windows[aWindow.__SSID]) {
       return;
+    }
 
     // Ignore non-browser windows and windows opened while shutting down
-    if (aWindow.document.documentElement.getAttribute("windowtype") != "navigator:browser")
+    if (aWindow.document.documentElement.getAttribute("windowtype") != "navigator:browser") {
       return;
+    }
 
     // Assign it a unique identifier (timestamp) and create its data object
     aWindow.__SSID = "window" + Date.now();
     this._windows[aWindow.__SSID] = { tabs: [], selected: 0, closedTabs: [] };
 
     // Perform additional initialization when the first window is loading
     if (this._loadState == STATE_STOPPED) {
       this._loadState = STATE_RUNNING;
@@ -293,18 +295,19 @@ SessionStore.prototype = {
     browsers.addEventListener("TabClose", this, true);
     browsers.addEventListener("TabSelect", this, true);
     browsers.addEventListener("TabPreZombify", this, true);
     browsers.addEventListener("TabPostZombify", this, true);
   },
 
   onWindowClose: function ss_onWindowClose(aWindow) {
     // Ignore windows not tracked by SessionStore
-    if (!aWindow.__SSID || !this._windows[aWindow.__SSID])
+    if (!aWindow.__SSID || !this._windows[aWindow.__SSID]) {
       return;
+    }
 
     let browsers = aWindow.document.getElementById("browsers");
     browsers.removeEventListener("TabOpen", this, true);
     browsers.removeEventListener("TabClose", this, true);
     browsers.removeEventListener("TabSelect", this, true);
     browsers.removeEventListener("TabPreZombify", this, true);
     browsers.removeEventListener("TabPostZombify", this, true);
 
@@ -333,86 +336,94 @@ SessionStore.prototype = {
     // Use load to restore text data
     aBrowser.addEventListener("load", this, true);
 
     // Use a combination of events to watch for text data changes
     aBrowser.addEventListener("change", this, true);
     aBrowser.addEventListener("input", this, true);
     aBrowser.addEventListener("DOMAutoComplete", this, true);
 
-    if (!aNoNotification)
+    if (!aNoNotification) {
       this.saveStateDelayed();
+    }
     this._updateCrashReportURL(aWindow);
   },
 
   onTabRemove: function ss_onTabRemove(aWindow, aBrowser, aNoNotification) {
     // Cleanup event listeners
     aBrowser.removeEventListener("DOMTitleChanged", this, true);
     aBrowser.removeEventListener("load", this, true);
     aBrowser.removeEventListener("change", this, true);
     aBrowser.removeEventListener("input", this, true);
     aBrowser.removeEventListener("DOMAutoComplete", this, true);
 
     // If this browser is being restored, skip any session save activity
-    if (aBrowser.__SS_restore)
+    if (aBrowser.__SS_restore) {
       return;
+    }
 
     delete aBrowser.__SS_data;
 
-    if (!aNoNotification)
+    if (!aNoNotification) {
       this.saveStateDelayed();
+    }
   },
 
   onTabClose: function ss_onTabClose(aWindow, aBrowser, aTabIndex) {
-    if (this._maxTabsUndo == 0)
+    if (this._maxTabsUndo == 0) {
       return;
+    }
 
     if (aWindow.BrowserApp.tabs.length > 0) {
       // Bundle this browser's data and extra data and save in the closedTabs
       // window property
       let data = aBrowser.__SS_data || {};
       data.extData = aBrowser.__SS_extdata || {};
 
       this._windows[aWindow.__SSID].closedTabs.unshift(data);
       let length = this._windows[aWindow.__SSID].closedTabs.length;
-      if (length > this._maxTabsUndo)
+      if (length > this._maxTabsUndo) {
         this._windows[aWindow.__SSID].closedTabs.splice(this._maxTabsUndo, length - this._maxTabsUndo);
+      }
 
       this._lastClosedTabIndex = aTabIndex;
 
       if (this._notifyClosedTabs) {
         this._sendClosedTabsToJava(aWindow);
       }
 
       let evt = new Event("SSTabCloseProcessed", {"bubbles":true, "cancelable":false});
       aBrowser.dispatchEvent(evt);
     }
   },
 
   onTabLoad: function ss_onTabLoad(aWindow, aBrowser) {
     // If this browser is being restored, skip any session save activity
-    if (aBrowser.__SS_restore)
+    if (aBrowser.__SS_restore) {
       return;
+    }
 
     // Ignore a transient "about:blank"
-    if (!aBrowser.canGoBack && aBrowser.currentURI.spec == "about:blank")
+    if (!aBrowser.canGoBack && aBrowser.currentURI.spec == "about:blank") {
       return;
+    }
 
     let history = aBrowser.sessionHistory;
 
     // Serialize the tab data
     let entries = [];
     let index = history.index + 1;
     for (let i = 0; i < history.count; i++) {
       let historyEntry = history.getEntryAtIndex(i, false);
       // Don't try to restore wyciwyg URLs
       if (historyEntry.URI.schemeIs("wyciwyg")) {
         // Adjust the index to account for skipped history entries
-        if (i <= history.index)
+        if (i <= history.index) {
           index--;
+        }
         continue;
       }
       let entry = this._serializeHistoryEntry(historyEntry);
       entries.push(entry);
     }
     let data = { entries: entries, index: index };
 
     let formdata;
@@ -438,18 +449,19 @@ SessionStore.prototype = {
     let evt = new Event("SSTabDataUpdated", {"bubbles":true, "cancelable":false});
     aBrowser.dispatchEvent(evt);
     this.saveStateDelayed();
 
     this._updateCrashReportURL(aWindow);
   },
 
   onTabSelect: function ss_onTabSelect(aWindow, aBrowser) {
-    if (this._loadState != STATE_RUNNING)
+    if (this._loadState != STATE_RUNNING) {
       return;
+    }
 
     let browsers = aWindow.document.getElementById("browsers");
     let index = browsers.selectedIndex;
     this._windows[aWindow.__SSID].selected = parseInt(index) + 1; // 1-based
 
     // Restore the resurrected browser
     if (aBrowser.__SS_restore) {
       let data = aBrowser.__SS_data;
@@ -612,61 +624,65 @@ SessionStore.prototype = {
       data.windows.push(this._windows[index]);
     }
 
     return data;
   },
 
   _collectTabData: function ss__collectTabData(aWindow, aBrowser, aHistory) {
     // If this browser is being restored, skip any session save activity
-    if (aBrowser.__SS_restore)
+    if (aBrowser.__SS_restore) {
       return;
+    }
 
     aHistory = aHistory || { entries: [{ url: aBrowser.currentURI.spec, title: aBrowser.contentTitle }], index: 1 };
 
     let tabData = {};
     tabData.entries = aHistory.entries;
     tabData.index = aHistory.index;
     tabData.attributes = { image: aBrowser.mIconURL };
     tabData.desktopMode = aWindow.BrowserApp.getTabForBrowser(aBrowser).desktopMode;
     tabData.isPrivate = aBrowser.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing;
 
     aBrowser.__SS_data = tabData;
   },
 
   _collectWindowData: function ss__collectWindowData(aWindow) {
     // Ignore windows not tracked by SessionStore
-    if (!aWindow.__SSID || !this._windows[aWindow.__SSID])
+    if (!aWindow.__SSID || !this._windows[aWindow.__SSID]) {
       return;
+    }
 
     let winData = this._windows[aWindow.__SSID];
     winData.tabs = [];
 
     let browsers = aWindow.document.getElementById("browsers");
     let index = browsers.selectedIndex;
     winData.selected = parseInt(index) + 1; // 1-based
 
     let tabs = aWindow.BrowserApp.tabs;
     for (let i = 0; i < tabs.length; i++) {
       let browser = tabs[i].browser;
       if (browser.__SS_data) {
         let tabData = browser.__SS_data;
-        if (browser.__SS_extdata)
+        if (browser.__SS_extdata) {
           tabData.extData = browser.__SS_extdata;
+        }
         winData.tabs.push(tabData);
       }
     }
   },
 
   _forEachBrowserWindow: function ss_forEachBrowserWindow(aFunc) {
     let windowsEnum = Services.wm.getEnumerator("navigator:browser");
     while (windowsEnum.hasMoreElements()) {
       let window = windowsEnum.getNext();
-      if (window.__SSID && !window.closed)
+      if (window.__SSID && !window.closed) {
         aFunc.call(this, window);
+      }
     }
   },
 
   /**
    * Writes the session state to a disk file, while doing some telemetry and notification
    * bookkeeping.
    * @param aFile nsIFile used for saving the session
    * @param aData JSON session state
@@ -1154,36 +1170,40 @@ SessionStore.prototype = {
 
     // Restore the closed tabs array on the current window.
     if (state.windows[0].closedTabs) {
       this._windows[window.__SSID].closedTabs = state.windows[0].closedTabs;
     }
   },
 
   getClosedTabCount: function ss_getClosedTabCount(aWindow) {
-    if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID])
+    if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID]) {
       return 0; // not a browser window, or not otherwise tracked by SS.
+    }
 
     return this._windows[aWindow.__SSID].closedTabs.length;
   },
 
   getClosedTabs: function ss_getClosedTabs(aWindow) {
-    if (!aWindow.__SSID)
+    if (!aWindow.__SSID) {
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+    }
 
     return this._windows[aWindow.__SSID].closedTabs;
   },
 
   undoCloseTab: function ss_undoCloseTab(aWindow, aCloseTabData) {
-    if (!aWindow.__SSID)
+    if (!aWindow.__SSID) {
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+    }
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
-    if (!closedTabs)
+    if (!closedTabs) {
       return null;
+    }
 
     // If the tab data is in the closedTabs array, remove it.
     closedTabs.find(function (tabData, i) {
       if (tabData == aCloseTabData) {
         closedTabs.splice(i, 1);
         return true;
       }
     });
@@ -1205,41 +1225,44 @@ SessionStore.prototype = {
     if (this._notifyClosedTabs) {
       this._sendClosedTabsToJava(aWindow);
     }
 
     return tab.browser;
   },
 
   forgetClosedTab: function ss_forgetClosedTab(aWindow, aIndex) {
-    if (!aWindow.__SSID)
+    if (!aWindow.__SSID) {
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+    }
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
 
     // default to the most-recently closed tab
     aIndex = aIndex || 0;
-    if (!(aIndex in closedTabs))
+    if (!(aIndex in closedTabs)) {
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+    }
 
     // remove closed tab from the array
     closedTabs.splice(aIndex, 1);
 
     // Forget the last closed tab index if we're forgetting the last closed tab.
     if (aIndex == 0) {
       this._lastClosedTabIndex = -1;
     }
     if (this._notifyClosedTabs) {
       this._sendClosedTabsToJava(aWindow);
     }
   },
 
   _sendClosedTabsToJava: function ss_sendClosedTabsToJava(aWindow) {
-    if (!aWindow.__SSID)
+    if (!aWindow.__SSID) {
       throw (Components.returnCode = Cr.NS_ERROR_INVALID_ARG);
+    }
 
     let closedTabs = this._windows[aWindow.__SSID].closedTabs;
     let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(aWindow.BrowserApp.selectedBrowser);
 
     let tabs = closedTabs
       .filter(tab => tab.isPrivate == isPrivate)
       .map(function (tab) {
         // Get the url and title for the last entry in the session history.
@@ -1289,18 +1312,19 @@ SessionStore.prototype = {
       Cu.reportError("SessionStore: " + e);
       notifyMessage = "fail";
     }
 
     Services.obs.notifyObservers(null, "sessionstore-windows-restored", notifyMessage);
   }),
 
   removeWindow: function ss_removeWindow(aWindow) {
-    if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID])
+    if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID]) {
       return;
+    }
 
     delete this._windows[aWindow.__SSID];
     delete aWindow.__SSID;
 
     this.saveState();
   }
 
 };