From 4f5955815ae3d0217d55fcd3014efdd205d02090 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Sat, 8 Apr 2017 14:18:23 +0200 Subject: [PATCH] Bug 1351808 - Part 1 - Replace some magic numbers in session store. r=sebastian MozReview-Commit-ID: BzqieZVi7h4 --HG-- extra : rebase_source : 019d80844d65d075314ab57197793decca0853c5 --- mobile/android/components/SessionStore.js | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mobile/android/components/SessionStore.js b/mobile/android/components/SessionStore.js index 838be60612fe..240e7aee09f7 100644 --- a/mobile/android/components/SessionStore.js +++ b/mobile/android/components/SessionStore.js @@ -40,6 +40,9 @@ function log(a) { // Session Store // ----------------------------------------------------------------------- +const INVALID_TAB_ID = -1; +const INVALID_TAB_INDEX = -1; + const STATE_STOPPED = 0; const STATE_RUNNING = 1; const STATE_QUITTING = -1; @@ -82,7 +85,7 @@ SessionStore.prototype = { // The index where the most recently closed tab was in the tabs array // when it was closed. - _lastClosedTabIndex: -1, + _lastClosedTabIndex: INVALID_TAB_INDEX, // Whether or not to send notifications for changes to the closed tabs. _notifyClosedTabs: false, @@ -90,7 +93,7 @@ SessionStore.prototype = { // If we're simultaneously closing both a tab and Firefox, we don't want // to bother reloading the newly selected tab if it is zombified. // The Java UI will tell us which tab to watch out for. - _keepAsZombieTabId: -1, + _keepAsZombieTabId: INVALID_TAB_ID, init: function ss_init() { loggingEnabled = Services.prefs.getBoolPref("browser.sessionstore.debug_logging"); @@ -157,7 +160,7 @@ SessionStore.prototype = { win.closedTabs = []; } - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; }, onEvent: function ss_onEvent(event, data, callback) { @@ -418,7 +421,7 @@ SessionStore.prototype = { for (let window of Object.values(this._windows)) { window.closedTabs = window.closedTabs.filter(tab => !tab.isPrivate); } - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; break; } }, @@ -682,7 +685,7 @@ SessionStore.prototype = { onTabClose: function ss_onTabClose(aWindow, aBrowser, aTabIndex) { let data = aBrowser.__SS_data || {}; if (this._maxTabsUndo == 0 || this._sessionDataIsEmpty(data)) { - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; return; } @@ -809,7 +812,7 @@ SessionStore.prototype = { log("keeping as zombie tab " + tabId); } // The tab id passed through Tab:KeepZombified is valid for one TabSelect only. - this._keepAsZombieTabId = -1; + this._keepAsZombieTabId = INVALID_TAB_ID; log("onTabSelect() ran for tab " + tabId); this.saveStateDelayed(); @@ -844,7 +847,7 @@ SessionStore.prototype = { // The long press that initiated the move canceled any close undo option that may have been // present. - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; this.saveStateDelayed(); }, @@ -1411,7 +1414,7 @@ SessionStore.prototype = { } let parentId = tabData.parentId; - if (parentId > -1) { + if (parentId > INVALID_TAB_ID) { tab.parentId = parentId; } @@ -1491,7 +1494,7 @@ SessionStore.prototype = { tab.browser.__SS_extdata = aCloseTabData.extData; this._restoreTab(aCloseTabData, tab.browser); - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; if (this._notifyClosedTabs) { this._sendClosedTabsToJava(aWindow); @@ -1518,7 +1521,7 @@ SessionStore.prototype = { // Forget the last closed tab index if we're forgetting the last closed tab. if (aIndex == 0) { - this._lastClosedTabIndex = -1; + this._lastClosedTabIndex = INVALID_TAB_INDEX; } if (this._notifyClosedTabs) { this._sendClosedTabsToJava(aWindow); @@ -1526,7 +1529,7 @@ SessionStore.prototype = { }, get canUndoLastCloseTab() { - return this._lastClosedTabIndex > -1; + return this._lastClosedTabIndex > INVALID_TAB_INDEX; }, _sendClosedTabsToJava: function ss_sendClosedTabsToJava(aWindow) {