Bug 1330422 - Use arrow functions instead of capturing "this" in the session store. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 12 Jan 2017 21:36:01 +0100
changeset 464682 c20c73a9bfcda6a70ce4c757e9f2e276cb138045
parent 464678 cf9efdba5e2401f1bde0654579bb63a30b958b72
child 464683 8aa5d4a1254763f19de120fe5381c698871e5d91
push id42398
push usermozilla@buttercookie.de
push dateSat, 21 Jan 2017 21:16:15 +0000
reviewerssebastian
bugs1330422
milestone53.0a1
Bug 1330422 - Use arrow functions instead of capturing "this" in the session store. r?sebastian MozReview-Commit-ID: AlLHJipN6kL
mobile/android/components/SessionStore.js
--- 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;