| LEFT | RIGHT |
| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 defineNamespace(ext, internal); | 27 defineNamespace(ext, internal); |
| 28 | 28 |
| 29 let EventTarget = ext[internal].EventTarget = function() | 29 let EventTarget = ext[internal].EventTarget = function() |
| 30 { | 30 { |
| 31 defineNamespace(this, internal); | 31 defineNamespace(this, internal); |
| 32 | 32 |
| 33 this[internal].listeners = new Set(); | 33 this[internal].listeners = new Set(); |
| 34 }; | 34 }; |
| 35 EventTarget.prototype = { | 35 EventTarget.prototype = { |
| 36 [internal]: { |
| 37 dispatch(...args) |
| 38 { |
| 39 return [...this[internal].listeners].map(listener => listener(...args)); |
| 40 } |
| 41 }, |
| 36 addListener(listener) | 42 addListener(listener) |
| 37 { | 43 { |
| 38 this[internal].listeners.add(listener); | 44 this[internal].listeners.add(listener); |
| 39 }, | 45 }, |
| 40 removeListener(listener) | 46 removeListener(listener) |
| 41 { | 47 { |
| 42 this[internal].listeners.delete(listener); | 48 this[internal].listeners.delete(listener); |
| 43 } | 49 } |
| 44 }; | 50 }; |
| 45 | 51 |
| 46 ext[internal].dispatchEvent = (eventTarget, ...args) => | |
| 47 [...eventTarget[internal].listeners].map( | |
| 48 listener => listener(...args) | |
| 49 ); | |
| 50 | |
| 51 | 52 |
| 52 /* Message passing */ | 53 /* Message passing */ |
| 53 | 54 |
| 54 ext.onMessage = new ext[internal].EventTarget(); | 55 ext.onMessage = new ext[internal].EventTarget(); |
| 55 } | 56 } |
| LEFT | RIGHT |