From fcf43d972e1d49ab63d267f7a5f543a27b29f845 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 19 May 2017 10:12:55 -0400 Subject: [PATCH] tentatively fix issue reported in #2612 re. FFox 24.8.1 --- src/js/cosmetic-filtering.js | 18 +++----- src/js/messaging.js | 22 +++------- src/js/redirect-engine.js | 11 ++--- src/js/static-net-filtering.js | 80 +++++++++++----------------------- src/js/storage.js | 15 +++---- src/js/traffic.js | 8 +--- src/js/url-net-filtering.js | 30 +++++-------- src/js/utils.js | 20 +++------ 8 files changed, 66 insertions(+), 138 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 1abe92293..b23f01b6c 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -1629,19 +1629,13 @@ FilterContainer.prototype._reEscapeScriptArg = /[\\'"]/g; FilterContainer.prototype.toSelfie = function() { var selfieFromMap = function(map) { var selfie = [], - entry, bucket, ff, f, - iterator = map.entries(); - for (;;) { - entry = iterator.next(); - if ( entry.done ) { - break; - } - selfie.push('k\t' + entry.value[0]); - bucket = entry.value[1]; + bucket, ff, f; + // Note: destructuring assignment not supported before Chromium 49. + for ( var entry of map ) { + selfie.push('k\t' + entry[0]); + bucket = entry[1]; selfie.push(bucket.fid + '\t' + bucket.toSelfie()); - if ( bucket.fid !== '[]' ) { - continue; - } + if ( bucket.fid !== '[]' ) { continue; } ff = bucket.filters; for ( var j = 0, nj = ff.length; j < nj; j++ ) { f = ff[j]; diff --git a/src/js/messaging.js b/src/js/messaging.js index 8587b2902..bd353e4e7 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -208,17 +208,11 @@ var getHostnameDict = function(hostnameToCountMap) { domainEntry, domainFromHostname = µb.URI.domainFromHostname, domain, blockCount, allowCount, - iter = hostnameToCountMap.entries(), - entry, hostname, counts; - for (;;) { - entry = iter.next(); - if ( entry.done ) { - break; - } - hostname = entry.value[0]; - if ( r[hostname] !== undefined ) { - continue; - } + hostname, counts; + // Note: destructuring assignment not supported before Chromium 49. + for ( var entry of hostnameToCountMap ) { + hostname = entry[0]; + if ( r[hostname] !== undefined ) { continue; } domain = domainFromHostname(hostname) || hostname; counts = hostnameToCountMap.get(domain) || 0; blockCount = counts & 0xFFFF; @@ -234,14 +228,12 @@ var getHostnameDict = function(hostnameToCountMap) { } else { domainEntry = r[domain]; } - counts = entry.value[1]; + counts = entry[1]; blockCount = counts & 0xFFFF; allowCount = counts >>> 16 & 0xFFFF; domainEntry.totalBlockCount += blockCount; domainEntry.totalAllowCount += allowCount; - if ( hostname === domain ) { - continue; - } + if ( hostname === domain ) { continue; } r[hostname] = { domain: domain, blockCount: blockCount, diff --git a/src/js/redirect-engine.js b/src/js/redirect-engine.js index dfae64ffd..c7e0edff8 100644 --- a/src/js/redirect-engine.js +++ b/src/js/redirect-engine.js @@ -322,13 +322,10 @@ RedirectEngine.prototype.toSelfie = function() { // convert it to a serializable format. The serialized format must be // suitable to be used as an argument to the Map() constructor. var rules = [], - iter = this.rules.entries(), - item, rule, entries, i, entry; - for (;;) { - item = iter.next(); - if ( item.done ) { break; } - rule = [ item.value[0], [] ]; - entries = item.value[1]; + rule, entries, i, entry; + for ( var item of this.rules ) { + rule = [ item[0], [] ]; + entries = item[1]; i = entries.length; while ( i-- ) { entry = entries[i]; diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 4a9d86342..7ce32bae5 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -1875,39 +1875,26 @@ FilterContainer.prototype.freeze = function() { FilterContainer.prototype.toSelfie = function() { var categoryToSelfie = function(map) { - var selfie = [], - iterator = map.entries(), - entry; - for (;;) { - entry = iterator.next(); - if ( entry.done === true ) { break; } - selfie.push('k2\t' + exportInt(entry.value[0])); // token hash - selfie.push(entry.value[1].compile()); + var selfie = []; + for ( var entry of map ) { + selfie.push('k2\t' + exportInt(entry[0])); // token hash + selfie.push(entry[1].compile()); } return selfie.join('\n'); }; var categoriesToSelfie = function(map) { - var selfie = [], - iterator = map.entries(), - entry; - for (;;) { - entry = iterator.next(); - if ( entry.done === true ) { break; } - selfie.push('k1\t' + exportInt(entry.value[0])); // category bits - selfie.push(categoryToSelfie(entry.value[1])); + var selfie = []; + for ( var entry of map ) { + selfie.push('k1\t' + exportInt(entry[0])); // category bits + selfie.push(categoryToSelfie(entry[1])); } return selfie.join('\n'); }; var dataFiltersToSelfie = function(dataFilters) { - var selfie = [], - iter = dataFilters.entries(), - entry; - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - entry = entry.value[1]; + var selfie = []; + for ( var entry of dataFilters.values() ) { do { selfie.push(entry.compile()); entry = entry.next; @@ -2344,56 +2331,39 @@ FilterContainer.prototype.matchAndFetchData = function(dataType, requestURL, out if ( toAddImportant.size === 0 && toAdd.size === 0 ) { return; } // Remove entries overriden by other filters. - var iter = toAddImportant.entries(), - k; - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - k = entry.value[0]; - toAdd.delete(k); - toRemove.delete(k); + var key; + for ( key of toAddImportant.keys() ) { + toAdd.delete(key); + toRemove.delete(key); } - iter = toRemove.entries(); - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - k = entry.value[0]; - if ( k === '' ) { + for ( key of toRemove.keys() ) { + if ( key === '' ) { toAdd.clear(); break; } - toAdd.delete(k); + toAdd.delete(key); } var logData; - iter = toAddImportant.entries(); - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - out.push(entry.value[0]); + for ( entry of toAddImportant ) { + out.push(entry[0]); if ( outlog === undefined ) { continue; } - logData = entry.value[1].logData(); + logData = entry[1].logData(); logData.source = 'static'; logData.result = 1; outlog.push(logData); } - iter = toAdd.entries(); - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - out.push(entry.value[0]); + for ( entry of toAdd ) { + out.push(entry[0]); if ( outlog === undefined ) { continue; } - logData = entry.value[1].logData(); + logData = entry[1].logData(); logData.source = 'static'; logData.result = 1; outlog.push(logData); } if ( outlog !== undefined ) { - iter = toRemove.entries(); - for (;;) { - entry = iter.next(); - if ( entry.done === true ) { break; } - logData = entry.value[1].logData(); + for ( entry of toRemove.values()) { + logData = entry.logData(); logData.source = 'static'; logData.result = 2; outlog.push(logData); diff --git a/src/js/storage.js b/src/js/storage.js index 5eab982b8..e9260129f 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -333,15 +333,12 @@ return url; }; var importedSet = new Set(this.listKeysFromCustomFilterLists(externalLists)), - toImportSet = new Set(this.listKeysFromCustomFilterLists(details.toImport)), - iter = toImportSet.values(); - for (;;) { - var entry = iter.next(); - if ( entry.done ) { break; } - if ( importedSet.has(entry.value) ) { continue; } - assetKey = assetKeyFromURL(entry.value); - if ( assetKey === entry.value ) { - importedSet.add(entry.value); + toImportSet = new Set(this.listKeysFromCustomFilterLists(details.toImport)); + for ( var urlKey of toImportSet ) { + if ( importedSet.has(urlKey) ) { continue; } + assetKey = assetKeyFromURL(urlKey); + if ( assetKey === urlKey ) { + importedSet.add(urlKey); } selectedListKeySet.add(assetKey); } diff --git a/src/js/traffic.js b/src/js/traffic.js index 5ecff9140..1665b8d93 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -48,12 +48,8 @@ if ( µBlock.hiddenSettings.suspendTabsUntilReady ) { var suspendedTabs = new Set(); µBlock.onStartCompletedQueue.push(function(callback) { onBeforeReady = null; - var iter = suspendedTabs.values(), - entry; - for (;;) { - entry = iter.next(); - if ( entry.done ) { break; } - vAPI.tabs.reload(entry.value); + for ( var tabId of suspendedTabs ) { + vAPI.tabs.reload(tabId); } callback(); }); diff --git a/src/js/url-net-filtering.js b/src/js/url-net-filtering.js index cd531f9d0..b317c9200 100644 --- a/src/js/url-net-filtering.js +++ b/src/js/url-net-filtering.js @@ -142,23 +142,16 @@ URLNetFiltering.prototype.reset = function() { URLNetFiltering.prototype.assign = function(other) { var thisRules = this.rules, - otherRules = other.rules, - iter, item; + otherRules = other.rules; // Remove rules not in other - iter = thisRules.entries(); - for (;;) { - item = iter.next(); - if ( item.done ) { break; } - if ( otherRules.has(item.value) === false ) { - thisRules.delete(item.value); + for ( var key of thisRules.keys() ) { + if ( otherRules.has(key) === false ) { + thisRules.delete(key); } } // Add/change rules in other - iter = otherRules.entries(); - for (;;) { - item = iter.next(); - if ( item.done ) { break; } - thisRules.set(item.value[0], item.value[1].slice()); + for ( var entry of otherRules ) { + thisRules.set(entry[0], entry[1].slice()); } }; @@ -310,17 +303,14 @@ URLNetFiltering.prototype.copyRules = function(other, context, urls, type) { URLNetFiltering.prototype.toString = function() { var out = [], - iter = this.rules.entries(), - item, key, pos, hn, type, entries, i, entry; - for (;;) { - item = iter.next(); - if ( item.done ) { break; } - key = item.value[0]; + key, pos, hn, type, entries, i, entry; + for ( var item of this.rules ) { + key = item[0]; pos = key.indexOf(' '); hn = key.slice(0, pos); pos = key.lastIndexOf(' '); type = key.slice(pos + 1); - entries = item.value[1]; + entries = item[1]; for ( i = 0; i < entries.length; i++ ) { entry = entries[i]; out.push( diff --git a/src/js/utils.js b/src/js/utils.js index 1a0a3ab41..8b73c39ca 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -276,13 +276,9 @@ µBlock.mapToArray = typeof Array.from === 'function' ? Array.from : function(map) { - var out = [], - entries = map.entries(), - entry; - for (;;) { - entry = entries.next(); - if ( entry.done ) { break; } - out.push([ entry.value[0], entry.value[1] ]); + var out = []; + for ( var entry of map ) { + out.push(entry); } return out; }; @@ -294,13 +290,9 @@ µBlock.setToArray = typeof Array.from === 'function' ? Array.from : function(dict) { - var out = [], - entries = dict.values(), - entry; - for (;;) { - entry = entries.next(); - if ( entry.done ) { break; } - out.push(entry.value); + var out = []; + for ( var value of dict ) { + out.push(value); } return out; };