mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-02 00:42:45 +01:00
code review: use Map instead of Object
This commit is contained in:
parent
2d5e3f38f3
commit
26e9bb7c19
@ -533,7 +533,7 @@ var reInvalidHostname = /[^a-z0-9.\-\[\]:]/,
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µBlock.scriptlets = (function() {
|
µBlock.scriptlets = (function() {
|
||||||
var pendingEntries = Object.create(null);
|
var pendingEntries = new Map();
|
||||||
|
|
||||||
var Entry = function(tabId, scriptlet, callback) {
|
var Entry = function(tabId, scriptlet, callback) {
|
||||||
this.tabId = tabId;
|
this.tabId = tabId;
|
||||||
@ -545,8 +545,9 @@ var reInvalidHostname = /[^a-z0-9.\-\[\]:]/,
|
|||||||
Entry.prototype.service = function(response) {
|
Entry.prototype.service = function(response) {
|
||||||
if ( this.timer !== null ) {
|
if ( this.timer !== null ) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
|
this.timer = null;
|
||||||
}
|
}
|
||||||
delete pendingEntries[makeKey(this.tabId, this.scriptlet)];
|
pendingEntries.delete(makeKey(this.tabId, this.scriptlet));
|
||||||
this.callback(response);
|
this.callback(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -556,10 +557,8 @@ var reInvalidHostname = /[^a-z0-9.\-\[\]:]/,
|
|||||||
|
|
||||||
var report = function(tabId, scriptlet, response) {
|
var report = function(tabId, scriptlet, response) {
|
||||||
var key = makeKey(tabId, scriptlet);
|
var key = makeKey(tabId, scriptlet);
|
||||||
var entry = pendingEntries[key];
|
var entry = pendingEntries.get(key);
|
||||||
if ( entry === undefined ) {
|
if ( entry === undefined ) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
entry.service(response);
|
entry.service(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -569,14 +568,19 @@ var reInvalidHostname = /[^a-z0-9.\-\[\]:]/,
|
|||||||
callback();
|
callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var key = makeKey(tabId, scriptlet);
|
var key = makeKey(tabId, scriptlet),
|
||||||
if ( pendingEntries[key] !== undefined ) {
|
entry = pendingEntries.get(key);
|
||||||
callback();
|
if ( entry !== undefined ) {
|
||||||
|
if ( callback !== entry.callback ) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pendingEntries[key] = new Entry(tabId, scriptlet, callback);
|
pendingEntries.set(key, new Entry(tabId, scriptlet, callback));
|
||||||
}
|
}
|
||||||
vAPI.tabs.injectScript(tabId, { file: 'js/scriptlets/' + scriptlet + '.js' });
|
vAPI.tabs.injectScript(tabId, {
|
||||||
|
file: 'js/scriptlets/' + scriptlet + '.js'
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: think about a callback mechanism.
|
// TODO: think about a callback mechanism.
|
||||||
|
Loading…
Reference in New Issue
Block a user