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: Switch to internal methods everywhere Created March 1, 2018, 11:58 a.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
« ext/background.js ('K') | « 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,47 @@
* 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 = {
+ [internal]: {
+ dispatch(...args)
+ {
+ return [...this[internal].listeners].map(listener => listener(...args));
+ }
+ },
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);
}
};
/* Message passing */
- ext.onMessage = new ext._EventTarget();
+ ext.onMessage = new ext[internal].EventTarget();
}
« ext/background.js ('K') | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld