Bug 1356231 - Fix eslint r=Mossop
MozReview-Commit-ID: 4lOgBL7qZJ4
--- a/toolkit/modules/EventEmitter.jsm
+++ b/toolkit/modules/EventEmitter.jsm
@@ -1,15 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
"use strict";
-(function (factory) {
+// module, require are exposed when loaded as a CommonJS module
+// isWorker is exposed when loaded as a DevTools module
+/* globals module, isWorker */
+
+(function(factory) {
// This file can be loaded in several different ways. It can be
// require()d, either from the main thread or from a worker thread;
// or it can be imported via Cu.import. These different forms
// explain some of the hairiness of this code.
//
// It's important for the devtools-as-html project that a require()
// on the main thread not use any chrome privileged APIs. Instead,
// the body of the main function can only require() (not Cu.import)
@@ -34,62 +38,62 @@
// Cu.import, because it is never run in the devtools-in-content
// mode.
this.isWorker = false;
const Cu = Components.utils;
let console = Cu.import("resource://gre/modules/Console.jsm", {}).console;
// Bug 1259045: This module is loaded early in firefox startup as a JSM,
// but it doesn't depends on any real module. We can save a few cycles
// and bytes by not loading Loader.jsm.
- let require = function (module) {
+ let require = function(module) {
switch (module) {
case "devtools/shared/defer":
return Cu.import("resource://gre/modules/Promise.jsm", {}).Promise.defer;
case "Services":
return Cu.import("resource://gre/modules/Services.jsm", {}).Services;
case "devtools/shared/platform/stack": {
let obj = {};
Cu.import("resource://devtools/shared/platform/chrome/stack.js", obj);
return obj;
}
}
return null;
};
factory.call(this, require, this, { exports: this }, console);
this.EXPORTED_SYMBOLS = ["EventEmitter"];
}
-}).call(this, function (require, exports, module, console) {
+}).call(this, function(require, exports, module, console) {
// ⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠
// After this point the code may not use Cu.import, and should only
// require() modules that are "clean-for-content".
- let EventEmitter = this.EventEmitter = function () {};
+ let EventEmitter = this.EventEmitter = function() {};
module.exports = EventEmitter;
// See comment in JSM module boilerplate when adding a new dependency.
const Services = require("Services");
const defer = require("devtools/shared/defer");
let loggingEnabled = true;
if (!isWorker) {
loggingEnabled = Services.prefs.getBoolPref("devtools.dump.emit");
Services.prefs.addObserver("devtools.dump.emit", {
observe: () => {
loggingEnabled = Services.prefs.getBoolPref("devtools.dump.emit");
}
- }, false);
+ });
}
/**
* Decorate an object with event emitter functionality.
*
* @param Object objectToDecorate
* Bind all public methods of EventEmitter to
* the objectToDecorate object.
*/
- EventEmitter.decorate = function (objectToDecorate) {
+ EventEmitter.decorate = function(objectToDecorate) {
let emitter = new EventEmitter();
objectToDecorate.on = emitter.on.bind(emitter);
objectToDecorate.off = emitter.off.bind(emitter);
objectToDecorate.once = emitter.once.bind(emitter);
objectToDecorate.emit = emitter.emit.bind(emitter);
};
function describeNthCaller(n) {
@@ -144,17 +148,17 @@
* that this is needed) then use listener
*/
once(event, listener) {
let deferred = defer();
let handler = (_, first, ...rest) => {
this.off(event, handler);
if (listener) {
- listener.apply(null, [event, first, ...rest]);
+ listener(event, first, ...rest);
}
deferred.resolve(first);
};
handler._originalListener = listener;
this.on(event, handler);
return deferred.promise;