| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-present eyeo GmbH | 3  * Copyright (C) 2006-present eyeo GmbH | 
| 4  * | 4  * | 
| 5  * Adblock Plus is free software: you can redistribute it and/or modify | 5  * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6  * it under the terms of the GNU General Public License version 3 as | 6  * it under the terms of the GNU General Public License version 3 as | 
| 7  * published by the Free Software Foundation. | 7  * published by the Free Software Foundation. | 
| 8  * | 8  * | 
| 9  * Adblock Plus is distributed in the hope that it will be useful, | 9  * Adblock Plus is distributed in the hope that it will be useful, | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 46    * Removes a listener for the specified event name. | 46    * Removes a listener for the specified event name. | 
| 47    * | 47    * | 
| 48    * @param {string}   name | 48    * @param {string}   name | 
| 49    * @param {function} listener | 49    * @param {function} listener | 
| 50    */ | 50    */ | 
| 51   off(name, listener) | 51   off(name, listener) | 
| 52   { | 52   { | 
| 53     let listeners = this._listeners.get(name); | 53     let listeners = this._listeners.get(name); | 
| 54     if (listeners) | 54     if (listeners) | 
| 55     { | 55     { | 
| 56       let idx = listeners.indexOf(listener); | 56       if (listeners.length > 1) | 
| 57       if (idx != -1) | 57       { | 
| 58         listeners.splice(idx, 1); | 58         let idx = listeners.indexOf(listener); | 
|  | 59         if (idx != -1) | 
|  | 60           listeners.splice(idx, 1); | 
|  | 61       } | 
|  | 62       else if (listeners[0] === listener) | 
|  | 63       { | 
|  | 64         // We must use strict equality above for compatibility with | 
|  | 65         // Array.prototype.indexOf | 
|  | 66         this._listeners.delete(name); | 
|  | 67       } | 
| 59     } | 68     } | 
| 60   } | 69   } | 
| 61 | 70 | 
| 62   /** | 71   /** | 
| 63    * Adds a one time listener and returns a promise that | 72    * Adds a one time listener and returns a promise that | 
| 64    * is resolved the next time the specified event is emitted. | 73    * is resolved the next time the specified event is emitted. | 
| 65    * | 74    * | 
| 66    * @param {string} name | 75    * @param {string} name | 
| 67    * @returns {Promise} | 76    * @returns {Promise} | 
| 68    */ | 77    */ | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 81   } | 90   } | 
| 82 | 91 | 
| 83   /** | 92   /** | 
| 84    * Returns a copy of the array of listeners for the specified event. | 93    * Returns a copy of the array of listeners for the specified event. | 
| 85    * | 94    * | 
| 86    * @param {string} name | 95    * @param {string} name | 
| 87    * @returns {Array.<function>} | 96    * @returns {Array.<function>} | 
| 88    */ | 97    */ | 
| 89   listeners(name) | 98   listeners(name) | 
| 90   { | 99   { | 
| 91     let listeners = this._listeners.get(name); | 100     let listeners = this._listeners.size > 0 ? this._listeners.get(name) : null; | 
| 92     return listeners ? listeners.slice() : []; | 101     return listeners ? listeners.slice() : []; | 
| 93   } | 102   } | 
| 94 | 103 | 
| 95   /** | 104   /** | 
|  | 105    * Checks whether there are any listeners for the specified event. | 
|  | 106    * | 
|  | 107    * @param {string} [name] The name of the event. If omitted, checks whether | 
|  | 108    *   there are any listeners for any event. | 
|  | 109    * @returns {boolean} | 
|  | 110    */ | 
|  | 111   hasListeners(name) | 
|  | 112   { | 
|  | 113     return this._listeners.size > 0 && | 
|  | 114            (typeof name == "undefined" || this._listeners.has(name)); | 
|  | 115   } | 
|  | 116 | 
|  | 117   /** | 
| 96    * Calls all previously added listeners for the given event name. | 118    * Calls all previously added listeners for the given event name. | 
| 97    * | 119    * | 
| 98    * @param {string} name | 120    * @param {string} name | 
| 99    * @param {...*}   [args] | 121    * @param {...*}   [args] | 
| 100    */ | 122    */ | 
| 101   emit(name, ...args) | 123   emit(name, ...args) | 
| 102   { | 124   { | 
| 103     let listeners = this.listeners(name); | 125     let listeners = this._listeners.size > 0 ? this._listeners.get(name) : null; | 
| 104     for (let listener of listeners) | 126     if (listeners) | 
| 105       listener(...args); | 127     { | 
|  | 128       for (let listener of listeners.slice()) | 
|  | 129         listener(...args); | 
|  | 130     } | 
| 106   } | 131   } | 
| 107 } | 132 } | 
| 108 | 133 | 
| 109 exports.EventEmitter = EventEmitter; | 134 exports.EventEmitter = EventEmitter; | 
| OLD | NEW | 
|---|