| Index: lib/requestNotifier.js |
| =================================================================== |
| --- a/lib/requestNotifier.js |
| +++ b/lib/requestNotifier.js |
| @@ -22,49 +22,56 @@ |
| Cu.import("resource://gre/modules/Services.jsm"); |
| let {Utils} = require("utils"); |
| let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideException} = require("filterClasses"); |
| let nodeData = new WeakMap(); |
| let windowStats = new WeakMap(); |
| let windowSelection = new WeakMap(); |
| +let requestNotifierMaxId = 0; |
| let requestEntryMaxId = 0; |
| /** |
| - * List of notifiers in use - these notifiers need to receive notifications on |
| - * new requests. |
| - * @type RequestNotifier[] |
| + * Active RequestNotifier instances by their ID |
| + * @type Map |
| */ |
| -let activeNotifiers = []; |
| +let notifiers = new Map(); |
| /** |
| * Creates a notifier object for a particular window. After creation the window |
| * will first be scanned for previously saved requests. Once that scan is |
| * complete only new requests for this window will be reported. |
| * @param {Window} wnd window to attach the notifier to |
| * @param {Function} listener listener to be called whenever a new request is found |
| * @param {Object} [listenerObj] "this" pointer to be used when calling the listener |
| */ |
| function RequestNotifier(wnd, listener, listenerObj) |
| { |
| this.window = wnd; |
| this.listener = listener; |
| this.listenerObj = listenerObj || null; |
| - activeNotifiers.push(this); |
| + this.id = ++requestNotifierMaxId; |
| + notifiers.set(this.id, this); |
| if (wnd) |
| this.startScan(wnd); |
| else |
| this.scanComplete = true; |
| } |
| exports.RequestNotifier = RequestNotifier; |
| RequestNotifier.prototype = |
| { |
| /** |
| + * The unique ID of this notifier. |
| + * @type Integer |
| + */ |
| + id: null, |
| + |
| + /** |
| * The window this notifier is associated with. |
| * @type Window |
| */ |
| window: null, |
| /** |
| * The listener to be called when a new request is found. |
| * @type Function |
| @@ -88,19 +95,17 @@ RequestNotifier.prototype = |
| * will no longer be called after that. |
| */ |
| shutdown: function() |
| { |
| delete this.window; |
| delete this.listener; |
| delete this.listenerObj; |
| - for (let i = activeNotifiers.length - 1; i >= 0; i--) |
| - if (activeNotifiers[i] == this) |
| - activeNotifiers.splice(i, 1); |
| + notifiers.delete(this.id); |
| }, |
| /** |
| * Notifies listener about a new request. |
| * @param {Window} wnd |
| * @param {Node} node |
| * @param {RequestEntry} entry |
| */ |
| @@ -280,17 +285,17 @@ function RequestEntry(node, topWnd, cont |
| if (filter.text in stats.filters) |
| stats.filters[filter.text]++; |
| else |
| stats.filters[filter.text] = 1; |
| } |
| // Notify listeners |
| - for (let notifier of activeNotifiers) |
| + for (let notifier of notifiers.values()) |
| if (!notifier.window || notifier.window == topWnd) |
| notifier.notifyListener(topWnd, node, this); |
| } |
| RequestEntry.prototype = |
| { |
| /** |
| * id of request (used to determine last entry attached to a node) |
| * @type integer |