Bug 1326581 - Rewrite PointerlockFsWarning.Timeout to use ES6-class. r?jaws draft
authorJalen Adams <leftysolara@gmail.com>
Thu, 05 Jan 2017 19:30:54 -0500
changeset 456607 9fff6d1919732269d9e0e1b110fa29e7ed266a35
parent 456417 b548da4e16f067e5b69349376e37b2db97983cf7
child 541285 b3089620f913d595fca55f14e28140f3840263b1
push id40564
push userbmo:leftysolara@gmail.com
push dateFri, 06 Jan 2017 00:34:48 +0000
reviewersjaws
bugs1326581
milestone53.0a1
Bug 1326581 - Rewrite PointerlockFsWarning.Timeout to use ES6-class. r?jaws MozReview-Commit-ID: ISK3gO2vo1r
browser/base/content/browser-fullScreenAndPointerLock.js
browser/base/content/browser.js
--- a/browser/base/content/browser-fullScreenAndPointerLock.js
+++ b/browser/base/content/browser-fullScreenAndPointerLock.js
@@ -3,56 +3,45 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var PointerlockFsWarning = {
 
   _element: null,
   _origin: null,
 
-  init() {
-    this.Timeout.prototype = {
-      start() {
-        this.cancel();
-        this._id = setTimeout(() => this._handle(), this._delay);
-      },
-      cancel() {
-        if (this._id) {
-          clearTimeout(this._id);
-          this._id = 0;
-        }
-      },
-      _handle() {
-        this._id = 0;
-        this._func();
-      },
-      get delay() {
-        return this._delay;
-      }
-    };
-  },
-
-  /* eslint-disable object-shorthand */
-  /* The object-shorthand rule must be disabled for this constructor
-   * because the ES6 method syntax causes "this.Timeout is not a
-   * constructor" exception. Further, using the {ignoreConstructors: true}
-   * option causes "TypeError: Cannot read property 'charAt' of undefined"
-   * in eslint.
-   */
   /**
    * Timeout object for managing timeout request. If it is started when
    * the previous call hasn't finished, it would automatically cancelled
    * the previous one.
    */
-  Timeout: function(func, delay) {
-    this._id = 0;
-    this._func = func;
-    this._delay = delay;
+  Timeout: class {
+    constructor(func, delay) {
+      this._id = 0;
+      this._func = func;
+      this._delay = delay;
+    }
+    start() {
+      this.cancel();
+      this._id = setTimeout(() => this._handle(), this._delay);
+    }
+    cancel() {
+      if (this._id) {
+        clearTimeout(this._id);
+        this._id = 0;
+      }
+    }
+    _handle() {
+      this._id = 0;
+      this._func();
+    }
+    get delay() {
+      return this._delay;
+    }
   },
-  /* eslint-enable object-shorthand */
 
   showPointerLock(aOrigin) {
     if (!document.fullscreen) {
       let timeout = gPrefService.getIntPref("pointer-lock-api.warning.timeout");
       this.show(aOrigin, "pointerlock-warning", timeout, 0);
     }
   },
 
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1346,17 +1346,16 @@ var gBrowserInit = {
       placesContext.addEventListener("popuphiding", updateEditUIVisibility, false);
     }
 
     LightWeightThemeWebInstaller.init();
 
     if (Win7Features)
       Win7Features.onOpenWindow();
 
-    PointerlockFsWarning.init();
     FullScreen.init();
     PointerLock.init();
 
     // initialize the sync UI
     gSyncUI.init();
     gFxAccounts.init();
 
     if (AppConstants.MOZ_DATA_REPORTING)