Index: ext/common.js |
=================================================================== |
--- a/ext/common.js |
+++ b/ext/common.js |
@@ -10,42 +10,46 @@ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
+/* global defineNamespace */ |
+ |
"use strict"; |
+const internal = Symbol(); |
Manish Jethani
2018/02/28 15:23:27
The symbol is defined in ext/common.js since it is
|
+ |
{ |
window.ext = {}; |
- let EventTarget = ext._EventTarget = function() |
+ defineNamespace(ext, internal); |
+ |
+ let EventTarget = ext[internal].EventTarget = function() |
{ |
- this._listeners = new Set(); |
+ defineNamespace(this, internal); |
+ |
+ this[internal].listeners = new Set(); |
}; |
EventTarget.prototype = { |
addListener(listener) |
{ |
- this._listeners.add(listener); |
+ this[internal].listeners.add(listener); |
}, |
removeListener(listener) |
{ |
- this._listeners.delete(listener); |
- }, |
- _dispatch(...args) |
- { |
- let results = []; |
- |
- for (let listener of this._listeners) |
- results.push(listener(...args)); |
- |
- return results; |
+ this[internal].listeners.delete(listener); |
} |
}; |
+ ext[internal].dispatchEvent = (eventTarget, ...args) => |
Manish Jethani
2018/02/28 15:23:27
EventTarget.prototype._dispatch is now ext[interna
|
+ [...eventTarget[internal].listeners].map( |
+ listener => listener(...args) |
+ ); |
+ |
/* Message passing */ |
- ext.onMessage = new ext._EventTarget(); |
+ ext.onMessage = new ext[internal].EventTarget(); |
} |