Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/common.js

Issue 29711592: Issue 6424 - Use internal symbol in ext namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Support internal methods Created Feb. 28, 2018, 4:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+
{
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) =>
+ [...eventTarget[internal].listeners].map(
+ listener => listener(...args)
+ );
+
/* Message passing */
- ext.onMessage = new ext._EventTarget();
+ ext.onMessage = new ext[internal].EventTarget();
}
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld