Bug 1326581 - Rewrite PointerlockFsWarning.Timeout to use ES6-class. r?jaws
MozReview-Commit-ID: ISK3gO2vo1r
--- 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)