Bug 1330422 - Use arrow functions instead of capturing "this" in the session store. r?sebastian
MozReview-Commit-ID: AlLHJipN6kL
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -167,17 +167,16 @@ SessionStore.prototype = {
for (let [ssid, win] of Object.entries(this._windows)) {
win.closedTabs = [];
}
this._lastClosedTabIndex = -1;
},
observe: function ss_observe(aSubject, aTopic, aData) {
- let self = this;
let observerService = Services.obs;
switch (aTopic) {
case "app-startup":
observerService.addObserver(this, "final-ui-startup", true);
observerService.addObserver(this, "domwindowopened", true);
observerService.addObserver(this, "domwindowclosed", true);
observerService.addObserver(this, "browser:purge-session-history", true);
observerService.addObserver(this, "browser:purge-session-tabs", true);
@@ -196,31 +195,31 @@ SessionStore.prototype = {
observerService.addObserver(this, "Tabs:OpenMultiple", true);
break;
case "final-ui-startup":
observerService.removeObserver(this, "final-ui-startup");
this.init();
break;
case "domwindowopened": {
let window = aSubject;
- window.addEventListener("load", function() {
- self.onWindowOpen(window);
+ window.addEventListener("load", () => {
+ this.onWindowOpen(window);
window.removeEventListener("load", arguments.callee);
});
break;
}
case "domwindowclosed": // catch closed windows
this.onWindowClose(aSubject);
break;
case "quit-application-requested":
log("quit-application-requested");
// Get a current snapshot of all windows
if (this._pendingWrite) {
- this._forEachBrowserWindow(function(aWindow) {
- self._collectWindowData(aWindow);
+ this._forEachBrowserWindow((aWindow) => {
+ this._collectWindowData(aWindow);
});
}
break;
case "quit-application-proceeding":
log("quit-application-proceeding");
// Freeze the data at what we've got (ignoring closing windows)
this._loadState = STATE_QUITTING;
break;
@@ -1006,19 +1005,18 @@ SessionStore.prototype = {
type: "PrivateBrowsing:Data",
session: (privateData.windows.length > 0 && privateData.windows[0].tabs.length > 0) ? JSON.stringify(privateData) : null
});
this._lastSaveTime = Date.now();
},
_getCurrentState: function ss_getCurrentState() {
- let self = this;
- this._forEachBrowserWindow(function(aWindow) {
- self._collectWindowData(aWindow);
+ this._forEachBrowserWindow((aWindow) => {
+ this._collectWindowData(aWindow);
});
let data = { windows: [] };
for (let index in this._windows) {
data.windows.push(this._windows[index]);
}
return data;